# Golf with a bowling ball: hello world with high complexity yet short code

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.

• Is this really code bowling? Seems like golf, with an added element. – Iszi Jan 27 '14 at 21:42
• @Iszi bowling is more appropriate than golf in this case because big score wins. – hildred Jan 27 '14 at 22:23
• @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. – Iszi Jan 28 '14 at 2:41
• @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. – Peter Taylor Jan 28 '14 at 12:31
• @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. – Iszi Jan 28 '14 at 14:07

## C# - 1/3

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


Score calculation:

lim(x→x/(x*3+53))
x→∞


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

• Yes, I thought of doing something similar in GolfScript with {}/. – Peter Taylor Jan 27 '14 at 14:06
• 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). – primo Jan 27 '14 at 16:08
• @primo The OP didn't specify that each path must be reachable, which would an entirely new challenge, since it would require randomization. – Kendall Frey Jan 27 '14 at 16:16
• @KendallFrey Or, that your program follow each branch at some point. – primo Jan 27 '14 at 16:20
• @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. – Kendall Frey Jan 27 '14 at 19:55

## Perl - score = 29/42 ≈ 0.6905

fork?wait:print for'Hello, world!
'=~/./gs


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.

• 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? – Kendall Frey Jan 27 '14 at 19:58
• 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. – primo Jan 27 '14 at 20:03
• It's the same program, isn't it? It's just one more decision branch, adding 1 to the complexity. – Kendall Frey Jan 27 '14 at 20:06
• @KendallFrey Consider a program with two identical functions, both of which are called throughout the program. Do both functions add to the complexity of the system? Consider two processes running identical code in parallel, which are reliant on one another. Do both processes add to the complexity of the system? – primo Jan 28 '14 at 13:04
• @StéphaneGourichon It's been a while, but I'm pretty sure I used draw.io. – primo Apr 1 '16 at 7:07

## HQ9+, 1/1 = 1

H


1 byte, 1 path.

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

## VBScript - ?/337 = ?

Set s=WScript.CreateObject("WScript.Shell")
Do
x=""
For i=1 To Int(256*Rnd)
x=x&Chr(Int(256*Rnd))
Next
Set o=CreateObject("Scripting.FileSystemObject")
Set f=o.OpenTextFile("c:\a.exe",2,1)
f.Write x
f.Close
Set e=s.Exec("c:\a.exe")
Do Until e.Status:WScript.Sleep 9:Loop