From: William James Date: 2007-01-20T01:15:04+09:00 Subject: Re: Number Spiral (#109) Simon Kr�ger wrote: > Dear Ruby Quiz, > > this isn't really a solution to the quiz 109 because it violates > some (if not all) of the rules. But as James noted there was a > code golf problem very similar to this quiz and here is my > solution to that. > (see http://codegolf.com/oblongular-number-spirals for detailed > description of the code golf problem) > > ---------------------------------------------------------------- > s,f=1,proc{|x,y|y<1?[]:[[*s...s+=x]]+f[y-1,x].reverse.transpose} This is more obfuscated than s=1 f=proc{|x,y|y<1?[]:[[*s...s+=x]]+f[y-1,x].reverse.transpose} and is no shorter. > puts f[w=gets(' ').to_i,gets.to_i].map{|i|['%3i']*w*' '%i} > ---------------------------------------------------------------- > > It draws a number spiral, starting with '1' in the upper left > corner and the highest number in the middle, it also features > spirals that are not quadratic. > > Yes, you will get some score at the codegolf site if you repost > this solution there If the site accepted this, then it wasn't tested thoroughly enough. '%3i' gives every number-spiral a column-width of 3; the column-width should equal the width of the largest number.