Older blog entries for rmathew (starting at number 72)

SRM-236
Yet another miserable performance from yours truly. The first problem was to find out the task finally left from a set of tasks after the n-th task (assuming the list is circular) is removed and the process repeatedly applied till there is only one left. I took too much time on this one, all because of a rather silly off-by-one error. The second problem was to find the n-th smallest Hamming number given a set of factors. If X1,..,Xn are the given factors, a Hamming number is X1^P1 * ... * Xn^Pn, where Pi >= 0. For example, for 2 and 3, the Hamming numbers are 1,2,3,4,6,8,9,.... My brute-force solution was too slow and timed out for large values. I could not finish this one before the deadline and thus could not attempt the third problem.

Naturally, my rating fell yet again, but the good thing is that I'm back in Division 2 where I should at least get easier problems.

Java Web Start (JDK 1.4.2_07) on Linux (Again)
I found a neater way of working around the bug in Sun's javaws in JDK 1.4.2_07 on a Linux system running kernel 2.6.x and glibc 2.3.3+ that I referred to in my previous blog entry - I wrote a wrapper for waitid() that tolerates the bogus options passed by javawsbin and calls the real waitid() with saner options. With this code, I am finally able to run javaws without problems. Note that this bug seems to have been fixed by Sun in JDK 1.5.0_02.
/* Quick and dirty pre-loaded DSO to make buggy javawsbin
   in JDK 1.4.2_07 work on Linux with kernel 2.6.x and
   glibc 2.3.4.

Compilation: gcc -O2 -fPIC -g0 -shared -o mywait.so mywait.c

Usage (Bash): LD_PRELOAD=/path/to/mywait.so /path/to/javaws <Launcher URL> */ #include <dlfcn.h> #include <sys/wait.h>

int (*real_waitid)( idtype_t, id_t, siginfo_t *, int);

int waitid( idtype_t idtype, id_t id, siginfo_t *infop, int options) { int retVal = -1;

void *handle = dlopen( "/lib/libc.so.6", RTLD_LAZY); real_waitid = dlsym( handle, "waitid");

options = (options == 0) ? WEXITED : options; retVal = (*real_waitid)( idtype, id, infop, options);

dlclose( handle);

return retVal; } /* End pseudo-waitid() */

Java Web Start on Linux
Due to a bug in Sun's Java Web Start executable in JDK 1.4.2_07 for Linux, I am not able to use it as-is on a system with glibc 2.3.4 and kernel 2.6.11. As should be obvious, if they had made it truly Free, I could have easily fixed the problem and moved on with my life. Since it is not, I have to either use an alternative like OpenJNLP or somehow work around this bug.

On a system where this bug does not manifest itself, I used "ps --columns 2000 -e -o "%a" | grep javaws" to grab the command line that is used by this executable to spawn the Java VM. I tried modifying this command line for my system (adjusting paths) and running it but it failed trying to download the JVM from Sun's site. After a bit of snooping around, I found out that it was looking for a file named "deployment.properties" in "$HOME/.java/.deployment" that is populated by the wrapper executable with the information on the JRE being used. So I just copied this file over from the system where stuff works and adjusted the paths. It finally worked as expected, albeit without the splash screen (which I do not regret losing at all).

Acrobat Reader
If you remove the utterly useless plug-ins from the Acrobat Reader installation folder, it starts up much faster.

PDF Viewer Under Linux
Mark: Honeymoon? Congratulations!

As for Evince, my PC only has KDE and therefore I don't think I can use it. In any case, I like the way Adobe Acrobat Reader cleanly renders PDFs and I especially like the navigation and zoom controls. The last I checked, both XPDF and KPDF were rather lacking in this area.

JDK API Documentation
One of the minor irritants I face while programming in Java under Linux is that there is no ready equivalent of the JDK API documentation in WinHelp format that comes in so handy while looking up a method or class. The normal HTML format JavaDocs is rather painful for such tasks.

One of the options is to use either xCHM or GnoCHM with the same CHM file that I use under Windows. However the former needs wxWidgets and the latter needs GNOME, neither of which I want to install on my PC. Besides this, I do not want to support a closed-format document format that people are struggling to understand.

It seems that there is a Java-based solution called JHelpViewer to help out with this situation and my limited testing with it indicates that it is decent and does the job to a fair extent. However, I do not like the overhead of keeping a JVM instance running on my PC just to view JavaDocs. I think a better option would be to use something like Gtk2 instead.

Does no one else find it weird that Sun does not itself ship the JDK API documentation in the JavaHelp format?

Adobe Acrobat Reader 7.0 for Linux
Acrobat Reader 7.0 is available for Linux, but for some reason the main download page still shows 5.0 as the last supported version for Linux. This version takes up around 93MB (!) of disc space, but feels and shows documents much better than any of the other PDF viewers for Linux that I have had a look at.
"The Five Boxing Wizards Jump Quickly"
This is much better than "the quick brown fox jumps over a lazy dog", which was the only other pangram I had known before seeing this blog entry by X guru Keith Packard. Talking of X, XFree86 released their server version 4.5.0 almost a week ago and I haven't seen references to it on any of the main nerds news sites yet. From the same blog entry by Keith, I came to know that a font designed 530 years ago still looks quite decent.
SRM-235
This morning I took part in my second TopCoder Single Round Match (SRM) - "SRM-235". Because of my rating from the previous match, I got to compete in Division 1 this time, which translated to tougher problems and competitors. Alas, I did pathetically in this match with my final score being zero!

Once again, the two problems that I had a chance to try out were not that difficult, but sloppy coding and muddled thinking made sure that my submissions would fail. The 300-point problem was to find out the minimum positive or negative steps needed by a stepping motor to reach any of the given target positions from a given current position. On this problem, integer overflow and underflow proved to be my undoing.

The 400-point problem was to find out the centre of gravity of a perforated rectangular sheet with rectangular holes. Here my solution just did not come close enough to the official solutions and I kept tweaking the multiplications and casts in my solution to match the results. After some time I even converted my solution over to fixed-point instead of floating-point, but it was still a bit off the mark. Such fiddling around ensured that I could not submit the solution in time, let alone attempt the 900-point problem.

My rating has dropped after this match, but still not enough to get me out of the darn Division 1. I look forward to being mauled once again in the next SRM on April 2.

GCJ on Slashdot
GCJ was discussed on Slashdot recently and this time around there were so many positive comments! This comment in particular made my day - it was referring to PR 20312. As Tom remarked earlier, the number of bugs that have been filed against GCJ have increased dramatically in the recent months, indicating that more and more people are trying it out and are hopeful enough about it to bother to report bugs.
SRM-234
This morning I took part in my first TopCoder Single Round Match (SRM) - "SRM-234". I liked the experience and would like to take part in more of these, time permitting.

The 250-point problem was a simple "find the length of the longest contiguous string of either As or Bs in the input". The 500-point problem was to find the sequence of unit fractions ("1/n") in descending order that add together to yield the given fraction "x/y". The 1000-point problem was to find the derivations needed to get to the input string given the productions of a simple non-left-recursive grammar.

The problems (as I have also noticed in the practice rooms) were not difficult per se, but had to be solved "correctly enough" within the given 75-minutes - much less if you also want to get a good score and ranking. It does not really matter if your code or design is elegant as long as it manages to pass all system tests as well as the challenges that other coders might throw at it. The permissible input is also severely restrained so that you do not usually have to worry about validating it.

One thing I noticed is that there were not many Indians among the toppers, while there were quite a few people from Poland. This is quite weird as I have met quite a few good Indian coders. Perhaps the lack of awareness, the lack of an enthusiasm for such competitions, the lack of decent net connections, the weird timings of the matches when converted to IST, etc. play a role. If you are an Indian coder reading this, please do consider taking part in these matches and letting your friends know about it.

C++ is Evil
As if sane people needed a proof showing how extraordinarily convoluted the language is - what kind of a language meant for sane coders needs indefinite lookahead and semantic disambiguation in a compiler so that it can parse source code written in that language?

63 older entries...

New Advogato Features

New HTML Parser: The long-awaited libxml2 based HTML parser code is live. It needs further work but already handles most markup better than the original parser.

Keep up with the latest Advogato features by reading the Advogato status blog.

If you're a C programmer with some spare time, take a look at the mod_virgule project page and help us with one of the tasks on the ToDo list!