Golf

Created 22nd October, 2009 05:59 (UTC), last edited 22nd October, 2009 06:29 (UTC)

One of the things we like to do once we have working code is to refactor it to remove redundancy. Of course, as with any engineering discipline things go wrong when taken to an extreme, and Code Golf is at “remove it all” end of that extreme.

Here is an example Code Golf puzzle taken from the eponymous web site. You start with a grid of numbers:

01344631552116888787
32408240439608824186
30162418045465963848
32009990247589410401
11803183089337962764
09812841482368558672
64611455333940185759
49345081851222548076
18455026819525144675
22523750374016715217

Each row has a sum as does each column. Given the numbers sent in via stdin, what is the shortest program that will find the row or column with the greatest sum and print out that sum. I.e., something like:

solution_program < numbers.txt

Should print “615” (which is the sum of column 8).

Shortest has a very simple definition here, the least number of characters in the program, counting white space, new lines and everything else.

So, who is up for some golf? How short can you make your program?