From: Michael Ulm Date: 2006-09-28T15:23:40+09:00 Subject: Re: [ANN] Code Golf Challenge : Oblongular Number Spirals Carl Drinkwater wrote: > Hi all, > > For those who found the 1,000 Digits of Pi problem too daunting, here's > something a little simpler for you. The new Code Golf[1] challenge > involves you having to create a number spiral such as : > > 1 2 3 > 10 11 4 > 9 12 5 > 8 7 6 > > and > > 1 2 3 4 5 > 18 19 20 21 6 > 17 28 29 22 7 > 16 27 30 23 8 > 15 26 25 24 9 > 14 13 12 11 10 > > Seems pretty simple, huh? The URL to the full challenge description is > > http://codegolf.com/oblongular-number-spirals > > I found it more difficult than I first thought it would be, but the code > was a lot of fun to write. At the time of writing the best Ruby entry > is 169 bytes. Can you beat it? > > Regards, > Carl. > > > [1] http://codegolf.com/ - "allows you to show off your code-fu by > trying to solve coding problems using the least number of keystrokes." > I finally found some time for golfing again. Here is my current solution. Not very impressive, but may give others some ideas. def f(n,m,k,o) n*m==0?[]:(k>0?f(n-1,m-1,m-k-1,n+m-1+o).reverse<< n+k+o:(o+1..n+o).to_a) end x,y=ARGV.map{|t|t.to_i} y.times{|i|puts f(x,y,i,0).map{|t|t.to_s.rjust((x*y).to_s.size)}*" "} regards, Michael -- Michael Ulm R&D Team ISIS Information Systems Austria tel: +43 2236 27551-219, fax: +43 2236 21081 e-mail: michael.ulm@isis-papyrus.com Visit our Website: www.isis-papyrus.com