More code golf: "grid" computing
By joe
- 2 minutes read - 264 wordsI told you I was an addict. Problem statement is here.
And you want to do it in the minimum number of characters (e.g. golf strokes) in your programming language. They give an example matrix, and their result (which is correct). So … what can you do for this? I used two languages: Octave/Matlab and Perl. The former is more of a ‘modeling’ language with formal programming bits atop it, and the latter is a classical programming language, quite notorious for its ability to be terse. Here’s the simplest Octave/Matlab I could come up with to do this:
octave:11> g=gc1
g =
1 34 46 31 55 21 16 88 87 87
32 40 82 40 43 96 8 82 41 86
30 16 24 18 4 54 65 96 38 48
32 0 99 90 24 75 89 41 4 1
11 80 31 83 8 93 37 96 27 64
9 81 28 41 48 23 68 55 86 72
64 61 14 55 33 39 40 18 57 59
49 34 50 81 85 12 22 54 80 76
18 45 50 26 81 95 25 14 46 75
22 52 37 50 37 40 16 71 52 17
octave:12> max(norm(g,'inf'),norm(transpose(g),'inf'))
ans = 615
That one line is 43 characters. Took me about 30 seconds to do that. I wish the Perl were that good, but I couldn’t figure out how to do a particular print the last element of list I sort in a single statement. Must be having a brain block. Will post this code when I get home.