"Gregory Brown" <gregory.t.brown / gmail.com> writes: > So much for the pp part, but this does the Pascal just fine: > > ---------------------- > require "rational" > > # I derived the nCk formula myself, didn't wanna cheat. > class Fixnum > def choose(k); (1..k-1).inject(1){ |s,e| s *= Rational(self,e) - 1 }; end > end > > # not to disappoint JEG2, I decided to maintain my record of > # "never completing a ruby quiz", so take the formatting with a grain of salt. > 1.upto(ARGV[0].to_i) { |n| puts((1..n).map {|k| n.choose k }.join("|")) } > ---------------------- Given this, I can't resist but "break the rules" even further---by not even writing the solution in Ruby. ;-) It's pretty nice to do in Haskell: > pascal = iterate (\last -> zipWith (+) ([0] ++ last) (last ++ [0])) [1] > > pp n = mapM_ (putStrLn . join "|" . map (show)) $ take n $ pascal > where join s (x:xs) | xs == [] = x > | otherwise = x ++ s ++ join s xs > > main = pp 666 > 1 > 1|1 > 1|2|1 > 1|3|3|1 > 1|4|6|4|1 > 1|5|10|10|5|1 > 1|6|15|20|15|6|1 ... -- Christian Neukirchen <chneukirchen / gmail.com> http://chneukirchen.org