From: "Alexandru E. Ungur" Date: 2006-06-26T14:39:24+09:00 Subject: [SOLUTION] [QUIZ] pp Pascal (#84) --OgqxwSJOaUobr8KG Content-Type: text/plain; charset=us-ascii Content-Disposition: inline Hi all, Here's my solution to the quiz: I attached two different solutions actually. First is pascal.rb, which is the first I did before asking for any clarifications/hints :) The triangle resulted is far from perfect, but I liked being able to use the 'multi' module which I just learned about :) The second, pascal-mini, does output a perfect triangle, and allows for playing with two options: 'B' and 'S'. B represents the numerotation based. By default it is 10, so nothing unusual, but you can change it to 16 and display hexa numbers, or even to 32 and display numbers in the 32 based numerotation system :) Looks nicer and more compact for larger triangles. All triangles in the attached sample.txt are from this script. The Ruby code however is very ugly I agree, I just wanted to find out how much I can squeeze it :) Thanks for the fun Ruby quiz! Have a great day everyone, Alex --OgqxwSJOaUobr8KG Content-Type: text/plain; charset=us-ascii Content-Disposition: attachment; filename="pascal-mini.rb" f=proc{|n|n>1?n*f[n-1]:1} # Factorial c=proc{|r,i|f[r]/(f[i]*f[r-i])} # Compute cell[r(ow),i(ndex)] t,rows,B,S=[],(ARGV[0]||10).to_i,10,' '; W=c[rows-1,rows/2].to_s(B).length # Init vars rows.times{|r|l=[];(r+1).times{|i|l<<(((s=c[r,i].to_s(B)).length