In this challenge, you must write a Hello World program that is both short and complex. We measure complexity by Cyclomatic McCabe complexity, and length by the number of bytes (not characters).

Score = complexity / bytes

For example, if the cyclomatic complexity is 5 and you use 100 bytes, your score is 5/100=0.05. If the cyclomatic complexity is 25 and you use 200 bytes, your score is 25/200=0.125.

The program shall take no input. The program must output exactly the ASCII-encoded string:

Hello, world!

in this exact case. This string may or may not be followed by a single newline (LF, ASCII 10). No other text shall be output.

  • \$\begingroup\$ Is this really code bowling? Seems like golf, with an added element. \$\endgroup\$
    – Iszi
    Commented Jan 27, 2014 at 21:42
  • \$\begingroup\$ @Iszi bowling is more appropriate than golf in this case because big score wins. \$\endgroup\$
    – hildred
    Commented Jan 27, 2014 at 22:23
  • \$\begingroup\$ @hildred Highest score wins, but the code has to be fairly short to keep a score high. Though the scoring may not be golf-like, the nature of the challenge most closely matches code golf. \$\endgroup\$
    – Iszi
    Commented Jan 28, 2014 at 2:41
  • 1
    \$\begingroup\$ @Iszi, I'm not sure whether it's really bowling, but it's certainly not golf because the scoring depends on a factor other than the length of the code. \$\endgroup\$ Commented Jan 28, 2014 at 12:31
  • \$\begingroup\$ @PeterTaylor I understand there's a factor other than length of code, but length of code is a strong enough factor in this that I think it really does fit. I'm pretty sure we've had other modified code golf challenges like this before, and I can't think of another tag that fits well enough - unless you just want to genericize it to code bowling. \$\endgroup\$
    – Iszi
    Commented Jan 28, 2014 at 14:07

4 Answers 4


C# - 1/3

string x = null;
Console.WriteLine(x??x??x??...??x??"Hello, world!");

Score calculation:


If you feel the need to wrap this all in a class with a Main method... it doesn't change the score.

  • \$\begingroup\$ Yes, I thought of doing something similar in GolfScript with {}/. \$\endgroup\$ Commented Jan 27, 2014 at 14:06
  • \$\begingroup\$ Since x is always initialized to null, the score here should probably be one (every time the program is executed, one path - and exactly the same path - is taken). \$\endgroup\$
    – primo
    Commented Jan 27, 2014 at 16:08
  • 2
    \$\begingroup\$ @primo The OP didn't specify that each path must be reachable, which would an entirely new challenge, since it would require randomization. \$\endgroup\$ Commented Jan 27, 2014 at 16:16
  • \$\begingroup\$ @KendallFrey Or, that your program follow each branch at some point. \$\endgroup\$
    – primo
    Commented Jan 27, 2014 at 16:20
  • 2
    \$\begingroup\$ @gerrit That's a good question. In the strictest theoretical sense, a program that does not take input takes only one possible path, so it's not possible to take multiple paths without input. Therefore the complexity will always be 1 unless you account for paths that are not taken. At least, this is my extrapolation. \$\endgroup\$ Commented Jan 27, 2014 at 19:55

Perl - score = 29/42 ≈ 0.6905

fork?wait:print for'Hello, world!

This will spawn a total of 16384 processes (don't worry though, no more than 15 are ever active at a time), each with a cyclomatic complexity of 3:

E - N + 2P = 8 - 7 + (2·1) = 3

Each time a branch is encountered, both paths are taken; once by the parent, and once by the newly spawned child.

My contention is that because the parent process never stops executing (that is, control is not passed, but rather split in two directions), the child process can not be considered to be running in the same control flow as the parent, but rather in its own. The total complexity diagram would therefore be more accurately depicted as the following:

The nodes from all paths which can never be reached have been removed.

E = 100; N = 73; P = 1 ⇒ CC = 29

Perl - score = 6000000/38 ≈ 157894.74

print eval'0?1:'x6e6."'Hello, world!'"

If you don't like the previous solution, consider this one: 6000000 nested branches, with a code length of 38. It could be argued - in fact I would even argue - that the complexity of this code is exactly 1, as the true condition of each branch can never be met, and therefore should be excluded from the complexity analysis.

In general, I think solutions of this type trivialize the challenge.

  • \$\begingroup\$ As a non-Perl hacker, I'm pretty confused by this. Can you explain how it works, and why it has a complexity of more than 4, which I would have calculated it as? \$\endgroup\$ Commented Jan 27, 2014 at 19:58
  • \$\begingroup\$ The false branch spawns an entirely new process, essentially creating a whole new code tree. If one were to draw each of these trees on a single canvas, there would be 16384 of them. \$\endgroup\$
    – primo
    Commented Jan 27, 2014 at 20:03
  • 2
    \$\begingroup\$ It's the same program, isn't it? It's just one more decision branch, adding 1 to the complexity. \$\endgroup\$ Commented Jan 27, 2014 at 20:06
  • 1
    \$\begingroup\$ @StéphaneGourichon It's been a while, but I'm pretty sure I used draw.io. \$\endgroup\$
    – primo
    Commented Apr 1, 2016 at 7:07
  • 1
    \$\begingroup\$ @Akangka perl will immediately declare that it is out of memory. 6e6 is the largest possible value representable in three chars that executes on a 32-bit system. \$\endgroup\$
    – primo
    Commented Jun 6, 2020 at 9:51

HQ9+, 1/1 = 1


1 byte, 1 path.

  • \$\begingroup\$ Doesn't output exactly Hello, world!. \$\endgroup\$ Commented Jan 27, 2014 at 21:24
  • 1
    \$\begingroup\$ Yeah it does... try the official interpreter. \$\endgroup\$
    – Timtech
    Commented Jan 27, 2014 at 21:26
  • \$\begingroup\$ I didn't know there was an official one. The one I tried didn't. \$\endgroup\$ Commented Jan 27, 2014 at 21:27
  • \$\begingroup\$ Ingenious. A bit like cheating though… \$\endgroup\$
    – Tobia
    Commented Jan 27, 2014 at 22:04

VBScript - ?/337 = ?

Set s=WScript.CreateObject("WScript.Shell")
For i=1 To Int(256*Rnd)
Set o=CreateObject("Scripting.FileSystemObject")
Set f=o.OpenTextFile("c:\a.exe",2,1)
f.Write x
Set e=s.Exec("c:\a.exe")
Do Until e.Status:WScript.Sleep 9:Loop
Loop While t<>"Hello, world!"
Wscript.Echo t

Not sure exactly how to score this, as it's what I call "Bogo, world!". It generates random bytes and then shells them as executables until one of them successfully outputs "Hello, world!". The complexity for any given run is impossible to determine - eventually it will exit, but the number of code branches that it generates are outside of my abilities to determine statistically.

My original thought was to do something similar with randomly emitted assemblies in C#, but VBScript has a much lower byte count given the error trapping .NET would require...

BTW - have a Task Manager open if you run this (the Exec method doesn't have a way to suppress the command window, and I need the return value so I can't use Run).


Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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