October 2, 2010 at 06:07 (esoteric language, tutorial)

Background: I introduced SPOJ in a previous post.

If you haven’t heard, LOLCODE is a powerful programming language used mainly by cats. It is deplorable that such a beautiful and natural language has not received wider support thus far. To help remedy the situation, I decided to code a solution to TEST using LOLPython, which is derived from LOLCODE and is just as elegant. Of course the program cannot be submitted because neither LOLCODE nor LOLPython is currently supported by SPOJ. But we must have faith that one day such blatant discrimination against cats and their programming languages will end, and we must prepare for that glorious day!

I can haz code?


Save a kitten – ask for LOLCODE support in your local programming competition (and syntax highlighter) today!

Permalink Leave a Comment

Java Custom addSlashes()

October 1, 2010 at 06:56 (java, javascript, tutorial, web dev)

Java regexes can get pretty clunky due to the dual use of the backslash character, as is commonly known. Although there’s not a lot to it, below is some code to add slashes for these characters: backslash, line feed, carriage return, null, single quote. It is used in a web application to format JSON strings on the server before passing to the client, where the objects are then processed by JavaScript/Ext JS. Maybe someone will find it useful!

public class StringUtil {
    public static String addSlashes(String s) {
        s = s.replaceAll("\\\\", "\\\\\\\\");
        s = s.replaceAll("\\n", "\\\\n");
        s = s.replaceAll("\\r", "\\\\r");
        s = s.replaceAll("\\00", "\\\\0");
        s = s.replaceAll("'", "\\\\'");
        return s;

Incidentally, there are other places where the following JavaScript replacement is necessary:

s = s.replace(/"/g, '"');

Permalink Leave a Comment

SPOJ, ideone, and TEST

September 14, 2010 at 05:53 (computer language, tutorial)

Background: I introduced SPOJ in a previous post.

ideone is an excellent tool that allows you to write and execute code in many languages, all online. It’s basically a pastebin with added functionality, making it an online mini-IDE. It is based on the SPOJ engine but supports some languages that SPOJ does not.

I’m mainly writing this post to report a useful discovery regarding ideone and the first SPOJ problem, TEST. If you happen to know a language like JavaScript and would like to submit a solution to TEST but can’t figure out how I/O is supposed to work, there is an easy solution through ideone. Simply go there, set the language to say JavaScript (rhino) and use the link to insert sample that appears above the textarea. A basic solution to TEST in the given language will magically appear, complete with sample input. This seems to work for just about any language on the list (even Whitespace!), and could come in handy when there is no corresponding thread in the SPOJ forums.

Permalink Leave a Comment

How To: SPOJ TEST Using JAR File

September 12, 2010 at 07:39 (java, tutorial)

Background: Sphere Online Judge (SPOJ) is an online judge system accepting a wide variety of programming languages. It’s a great way to test your skills as a programmer, and can be quite addictive if you like a good challenge.

While browsing the SPOJ forums, I did not find a thread detailing how to successfully submit a JAR for the first problem, TEST. So, here’s a quick guide. I’m using Windows, but there should be little difference with other operating systems since everything is done through the command line. I will assume you already have the JDK installed and paths set up such that if you type java, javac, or jar from the command line the appropriate programs will be executed.

Read the rest of this entry »

Permalink 3 Comments

MediaWiki – Multi-Line <pre></pre> within List

July 14, 2010 at 21:03 (mediawiki, tutorial)

Background: MediaWiki is open source software used to create wikis; it was developed for and is currently used by Wikipedia. I am using version 1.15.4.

I’ve spent a lot of time searching without success for a way to insert a multi-line pre-formatted block of text within an ordered or unordered list in MediaWiki using wiki markup * and # syntax. Today I finally figured out this can be done using either &#10; (Line Feed) or &#13; (Carriage Return). I haven’t tested across platforms or browsers, but here is an example:

Read the rest of this entry »

Permalink 3 Comments

Continued Fractions of Square Roots – Steps

July 4, 2010 at 19:31 (algorithm, java, math.NT, tutorial)

Everyone knows what continued fractions are, right? Continued fractions have interesting properties and can be used to obtain best rational approximations for real numbers, among other things. Here is an example of a finite continued fraction:

8.309 = 8+\cfrac{1}{3+\cfrac{1}{4+\cfrac{1}{4+\cfrac{1}{3+\cfrac{1}{2+\cfrac{1}{2}}}}}}

Read the rest of this entry »

Permalink Leave a Comment