Matlab 'solution' JordiB 22nd October, 2009 09:36 (UTC)

Crap, the site ate the square brackets (and some more again). Here's a repost using <> instead of square brackets. Feel free to delete the previous post.

To be honest I find the criteria a little vague. What language should we use? How much of the standard libraries can we use? If you're not too hung up on the solution being a stand-alone program that understands your calling syntax, I have a pretty short Matlab solution. It consists of two parts: loading the file and computing the maximum:

n=load('numbers.txt'); % loading: 22 characters
max(<sum(n),sum(n')>) % computing + printing back to console: 21 characters

That's 43 characters if I omit excess whitespace. If you would allow me to rename the file to something like 'n.txt', I could do this:

load n.txt; % 11 characters

Allowing me to rename it to 'n.mat' would allow me to omit 4 more characters:

load n; % 7 characters

If I'm allowed to assume that the number of columns is always equal to the number of rows, the second part can also be shortened:

max(sum(<n n'>)) % 16 characters

So depending on the rules, I either have no valid solution, or a solution of between 43 and 23 characters. Here is the whole shortest solution:

load n;max(sum(<n n'>))
Matlab 'solution' Kirit Sælensminde 22nd October, 2009 10:26 (UTC)

The square brackets thing is really a pain for programming languages isn't it. That's the mediawiki markup — I'd love to lose it really now and switch to something like tinymce. Wonder when I'll have time?

JordiB said

To be honest I find the criteria a little vague.

Yeah, a certain amount of that is on purpose :) Even as a software practitioner I'm not sure that it is possible to define a specification so tightly that nobody will have any questions about it.

What language should we use? How much of the standard libraries can we use? If you're not too hung up on the solution being a stand-alone program that understands your calling syntax, I have a pretty short Matlab solution. It consists of two parts: loading the file and computing the maximum:

I know ktui also has a solution that doesn't read from stdin. I'll try to get him to post his. I think he used awk (eek)


To join in the discussion you should register or log in