You need to make three things:

  1. Statement of a task, T.
  2. Solution of the task in language not typically used for golfing, A.
  3. Solution of the task in language typically used for golfing, B. Don't try to just bloat up B to pump up the score, instead think as if B was written by your competitor.

Use common sense in defining typically used for golfing, try to maximize fun for other users.

Other users may propose better Bs (maybe including in other "golfy" languages).

Scoring is (length_in_bytes(B)+5)/(length_in_bytes(A)+5), more is better. (Maybe the scoring formula should be changed?..)

The main idea is to invent a task where languages that typically perform well in codegolf meet a problem. It can be sudden strength of a usual language in the given task or sudden weakness of some golflang.

Avoid tasks that mention specific programming languages, like Input a string and execute it as a Scheme code.

  • 1
    \$\begingroup\$ I suppose that you make this a popularity-contest instead of a code-golf. Otherwise people will complain that it is not a "shortest-code-wins". \$\endgroup\$ Commented Jan 17, 2014 at 19:36
  • \$\begingroup\$ OK, changing to popularity-contest. You can also suggest better title or better scoring. \$\endgroup\$
    – Vi.
    Commented Jan 17, 2014 at 19:38
  • 1
    \$\begingroup\$ Do we get to specify lang B (as long as it is good at golfing)? Or can anyone say "here is a program in language <insert language name> and it has a very short solution of length <n>:"? \$\endgroup\$
    – Justin
    Commented Jan 17, 2014 at 19:49
  • 1
    \$\begingroup\$ BTW some languages like Perl can be both on A side and on B side, depending on context. \$\endgroup\$
    – Vi.
    Commented Jan 17, 2014 at 20:02
  • 1
    \$\begingroup\$ Why was this closed as off-topic? It seems to have an objective winning criterion to me? \$\endgroup\$ Commented Apr 14, 2019 at 16:19

9 Answers 9


My previous question, Print a sinusoidal wave (vertically), qualifies at this moment. I'm posting it here as a solution, also hoping that you guys can come up with some shorter solutions to my original question.

As required by Vi., I will post a summary of the question.

Print a continuous sinusoidal wave scrolling vertically on a terminal. The program should not terminate and should continuously scroll down the wave (except until SIGINT). You may assume overflow is not a problem (i.e. you may use infinite loops with incrementing counters, or infinite recursion).

The wave should satisfy the following properties:

  • Amplitude = 20 chars (peak amplitude)
  • Period = 60 to 65 lines (inclusive)
  • The output should only consist of spaces, newline and |
  • After each line of output, pause for 50ms

There is a sample output on my original question, but I'm not posting it here, because this will make my answer ridiculously long. My original question can be seen here: Print a sinusoidal wave (vertically)

Shortest A currently: a Perl solution with 48 chars: https://codegolf.stackexchange.com/a/18655/12205

';$_+=.1;`sleep .05`;do$0

Shortest B currently: a J solution with 54 chars: https://codegolf.stackexchange.com/a/18649/12205

($:+&0.1[6!:3@]&0.05[2:1!:2~' |'#~1,~[:<.20*1+1&o.)0  

Currently, the score of this answer is 1.113 (an awfully low score)

  • \$\begingroup\$ The current score according to current formula is approximately 1.113 \$\endgroup\$
    – Vi.
    Commented Jan 17, 2014 at 19:54
  • \$\begingroup\$ @Vi. should I delete this answer or should I wait some time and see what happens? If the latter, how long should I wait? \$\endgroup\$
    – user12205
    Commented Jan 17, 2014 at 20:23
  • \$\begingroup\$ The statement states bytes, not characters. Converted to UTL-8, the APL solution made 61 bytes (70 for UTF-16). \$\endgroup\$
    – Vi.
    Commented Jan 17, 2014 at 20:26
  • 2
    \$\begingroup\$ You're claiming that Perl is not a language typically used for golfing, but it's the language which was first associated with the word golf! Ruby, at 56, looks like the real language A in the current answers to your questions. \$\endgroup\$ Commented Jan 18, 2014 at 10:44

Add two numbers

Get two numbers from STDIN, and add them together. You have to support floating point numbers, so 0.5 + 1.5 has to equal 2.

Perl 5 (with -E)



  • \$\begingroup\$ Calculated score as (24+5)/(8+2+5) = 1.9(3). -E also counted as program bytes. \$\endgroup\$
    – Vi.
    Commented Jan 18, 2014 at 13:15
  • \$\begingroup\$ The same comment as I made to ace: you're claiming that Perl is not a language typically used for golfing, but it's the language which was first associated with the word golf! \$\endgroup\$ Commented Jan 18, 2014 at 13:55
  • \$\begingroup\$ And your GolfScript program doesn't work. A working program would be n%'+'*'"#{ }"'n/\*~ where the character between {} is a literal newline (not supported in comments). \$\endgroup\$ Commented Jan 18, 2014 at 13:56
  • \$\begingroup\$ @PeterTaylor, Compared with GolfScript, Perl is a "usual" language; compared with Java, it's a "golf" language. \$\endgroup\$
    – Vi.
    Commented Jan 18, 2014 at 14:33
  • 1
    \$\begingroup\$ The J for this isn't too bad, actually: +/".1!:1,~1. APL would probably be even smaller. \$\endgroup\$ Commented Mar 25, 2014 at 23:55

Print 'Hello, World!' to the stdout.

PHP, 13 bytes

Hello, World!

Golfscript, 15 bytes

'Hello, World!'

Pyth, 14 bytes

"Hello, World!
  • 3
    \$\begingroup\$ Nicely topical. :) \$\endgroup\$ Commented Aug 28, 2015 at 14:39
  • 2
    \$\begingroup\$ New B: In HQ9+ H \$\endgroup\$ Commented Aug 28, 2015 at 15:31
  • 2
    \$\begingroup\$ But it's spelt incorrectly, @NotthatCharles \$\endgroup\$
    – galexite
    Commented Aug 28, 2015 at 15:35
  • 1
    \$\begingroup\$ @georgeunix Good point. You capitalized your "W". \$\endgroup\$ Commented Aug 28, 2015 at 15:52

Score 48/37 or 1.(297)

T: write a code snippet that ends the program after exactly one hour (as close as possible, like within a second) of running. Don't worry about exceptions, they can be unhandled.

A: Java (32)

Thread.sleep(3600000);int a=1/0;

B: is for Befunge 98, requires the TIME fingerprint (43)


This takes the Hour, Minute, and Second at the time of running, and puts the at cells 02, 01, and 00. Then, it skips over the ; to the second part. The second part works as follows:

g          get the value at 00
"EMIT"4(S) get the current time in seconds
-!         subtracts the values and changes a 0 to 1, anything else to 0

similarly for the Minute and Hour.

++  sums up the values
3-! i the sum is 3, we get a 1, otherwise, we get a 0.
j   jump over the next that many cells
;   skip code execution until the next ;
@   end program

Note that Befunge will automatically go back to the beginning of the line when the end of a line is reached.

As we can see, Befunge is not good when it comes to waiting for specific times. However, Java is not bad.

  • 9
    \$\begingroup\$ APL: ⎕DL 3600 \$\endgroup\$
    – marinus
    Commented Jan 17, 2014 at 21:54
  • 14
    \$\begingroup\$ Java usually reads as class Main{public static void main... \$\endgroup\$
    – Vi.
    Commented Jan 17, 2014 at 22:00
  • 3
    \$\begingroup\$ @Vi. see "code snippet". Basically, it requires the code that actually does the work, not more than that. \$\endgroup\$
    – Justin
    Commented Jan 17, 2014 at 22:01
  • 2
    \$\begingroup\$ I don't know Befunge, but the Java snippet doesn't "end the program" as required by the spec. That would require either a System.exit(0); or wrapping your sleep in a main method. \$\endgroup\$ Commented Jan 18, 2014 at 9:40
  • 3
    \$\begingroup\$ @DoorknobofSnow Fails to compile: error: not a statement \$\endgroup\$
    – Bob
    Commented Jan 18, 2014 at 14:12

Output a certain text file (498.388888 points)

The goal output is here.

The Python 3.4.3 script to print it is 49 bytes:

for b in dir(__builtins__):print(eval(b).__doc__)

The naive CJam program equal to the goal output, by wrapping the output string in "..." and escaping each " that occurs in it, would be 26908 bytes.

  • \$\begingroup\$ Very clever, though it may run afoul of the "specific languages" restriction (which is vague, admittedly). \$\endgroup\$
    – BMac
    Commented Aug 27, 2015 at 21:34
  • \$\begingroup\$ The closest rule is "avoid mentioning specific language". Python is not mentioned, but is clearly meaned. \$\endgroup\$
    – Vi.
    Commented Aug 28, 2015 at 0:35
  • \$\begingroup\$ Yeah, this answer is a bit tongue-in-cheek, I sort of just wanted to point out that the rule is sort of a slippery slope. Imagine if I had "mangled" the output more -- say, taking the SHA1 checksum of each docstring -- it would be very weird to claim "this garbled bunch of hex digits is too language-specific" :) \$\endgroup\$
    – lynn
    Commented Aug 28, 2015 at 17:23
  • \$\begingroup\$ If I wanted to do a more "fair" answer, I'd probably use Mathematica. You can do a lot of extremely domain-specific things in it that would take thousands of bytes of CJam/Pyth/anything else. But sadly, I don't know the language. \$\endgroup\$
    – lynn
    Commented Aug 28, 2015 at 17:24
  • 1
    \$\begingroup\$ Link to output is dead. \$\endgroup\$ Commented Oct 19, 2019 at 16:42

Say "Hello world!" (50 / 26 ≈ 1.92)

Show a message box to say "Hello world!"


alert('Hello world!')

In a browser with support for DOM Level 0+.


use Win32;Win32::MsgBox('Hello world!','',48)

Running on ActivePerl with Win32::GUI.

  • \$\begingroup\$ alert isn't inherently part of JS, and the GolfScript program is just a comment. \$\endgroup\$ Commented Jan 26, 2014 at 22:31
  • \$\begingroup\$ I've changed the answer to use plain Perl. \$\endgroup\$
    – Toothbrush
    Commented Jan 27, 2014 at 12:41

Output "Hello world!" until user presses "q", 1.842 105/44 = 2.386

  1. Print "Hello world!" (including newline).
  2. The user presses a key, which is not echoed to the screen.
  3. Repeat until the key pressed was "q".

QBasic (52 39 characters)

1?"Hello world!":IF"q"<>INPUT$(1)THEN 1

Since posting my original answer, I discovered that I could turn off autoformatting in QB64. :^D With the line number and ? shortcut for PRINT, this looks rather like a ternary expression in C-like languages.

First version:

PRINT "Hello world!"
IF INPUT$(1) <> "q" THEN RUN

Perl 5 (100 characters)

while("q"ne$e){print"Hello world!\n";system"stty cbreak -echo";$e=getc;system"stty -cbreak echo";}

The above will only work on (certain?) UNIX systems (tested on Ubuntu 12.04). It's possible that one could go cross-platform and get it down to 91 characters using the Term::ReadKey module, but I haven't tested it:

use Term::ReadKey;while("q"ne$e){print"Hello world!\n";ReadMode 3;$e=ReadKey 0;ReadMode 0;}

Hello, world (3 1/3 points)

Write program that outputs Hello World..

HQ9+ (1 character)

This is not language "typically used for golfing", so I believe it fits here. Works in this interpreter, by the way.


GolfScript (15 characters)

I doubt it can get any shorter, even if it's GolfScript.

"Hello World."
  • 8
    \$\begingroup\$ I don't think HQ9+ suits as A language. It is designed for tricks/riddles/fun. Brainfuck/unlambda/other esoterical languages also does not seem to suit as A. \$\endgroup\$
    – Vi.
    Commented Jan 19, 2014 at 21:02
  • \$\begingroup\$ @Vi.: But it's not typically used for golfing. \$\endgroup\$
    – null
    Commented Jan 19, 2014 at 21:03
  • 4
    \$\begingroup\$ You can hovewer try to use HQ9+ as B language and beat it by Java or such... \$\endgroup\$
    – Vi.
    Commented Jan 19, 2014 at 21:03
  • 7
    \$\begingroup\$ Looks like there's a hierarchy: Compared to Java, Perl's a golflang. Compared to Perl, GolfScript is a golflang. Compared to GolfScript, HQ9+ is a golflang... \$\endgroup\$
    – Vi.
    Commented Jan 19, 2014 at 21:06
  • \$\begingroup\$ @Vi.: I carefully checked your task description. HQ9+ is never used for golfing, except for two particular tasks - "99 bottles", and "Hello, world". Unless you can show some other task in which HQ9+ wins with any other programming language, I still think it fits the definition, even if it abuses it (hey, it's popularity-contest). HQ9+ is simply not used for golfing stuff not related to those two tasks. So, it's not typically used for golfing. The second is obviously designed for CodeGolf - it's GolfScript. \$\endgroup\$
    – null
    Commented Jan 19, 2014 at 21:09

Output "Hello world!", 33/97 = 2.94

Write a program that outputs Hello world!

Arduino or GML

Serial.print("Hello world!")


show_message("Hello world!")

Both are 28 characters.


I use GTB for golfing a lot (especially since I created it myself, and it is Turing complete). Unfortunately, there is only limited support for lowercase characters (because TI-84 calculator can't deal with it). This is probably the shortest GTB program that can output Hello world!

S;"lower",1,1)→_~"H"+S;"expr(",1,1)+_+_+S;"cos(",2,1)+" W"+S;" or ",2,2)+_+S;" and ",4,1)+"!

92 characters.

  • \$\begingroup\$ Does GTB version also output it to serial port? \$\endgroup\$
    – Vi.
    Commented Jan 20, 2014 at 1:59
  • \$\begingroup\$ Is GTB version intentionally bloated up with various coss and exprs or it genuintely can't just output something in regular way? Or " character is actually not a string literal and confusing me... \$\endgroup\$
    – Vi.
    Commented Jan 20, 2014 at 2:01
  • \$\begingroup\$ @Vi. It's not bloated up at all... it has to strip e from expr, two l from lower, o from cos, or from or, l from lower, and d from and. \$\endgroup\$
    – Timtech
    Commented Jan 20, 2014 at 11:10
  • \$\begingroup\$ 'Other users may propose better Bs (maybe including in other "golfy" languages). ' --- let me try golfscript: "Hello world!" \$\endgroup\$ Commented Apr 13, 2014 at 9:01
  • \$\begingroup\$ @JanDvorak You're probably right. \$\endgroup\$
    – Timtech
    Commented Apr 13, 2014 at 22:00

Not the answer you're looking for? Browse other questions tagged or ask your own question.