From: Oliver Cromm Date: 2004-12-08T14:37:34+09:00 Subject: Re: Ruby 2.0 Mauricio Fern�ndez wrote: > On Wed, Dec 08, 2004 at 08:53:27AM +0900, trans. (T. Onoma) wrote: >> On Tuesday 07 December 2004 06:12 pm, Oliver Cromm wrote: >>| ruby -e'require "matrix";a=[1];(1..10).each{|n| print " >>| "*(10-n)*3,a.map{|i|\ >>| i.to_s.center(6)}.join,$/;a.push(0);a=(Vector[*a]+Vector[*a.reverse]).to_a} >>|' >> >> A touch smaller: >> >> ruby -e'require"matrix";a=[1];(1..10).each{|n|print" "*(10-n)*3,a.map{|i|\ >> i.to_s.center(6)}.join,$/;a<<0;a=(Vector[*a]+Vector[*a.reverse]).to_a}' > > Some obvious modifications: > > ruby -rmatrix -le'a=[1];10.times{|n|print" "*(9-n)*3,"%3d "*a.size%a;a<<0;a=( > Vector[*a]+Vector[*a.reverse]).to_a}' Optimal once you know the stuff - I'm learning! > There's still potential for further optimization but I prefer to zzzZZ. a.size = n+1, better yet: ruby -rmatrix -le'a=[1];1.upto(10){|n|print" "*(10-n)*3,"%3d "*n%a a<<0;a=(Vector[*a]+Vector[*a.reverse]).to_a}' I found the Vector stuff /kakkou ii/, but without, it's shorter. Accepting the extra indent, my shortest is: ruby -le'a=[];10.times{|n|a<<1;print" "*(9-n)*3,"%6d"*(n+1)%a n.downto(1){|i|a[i]+=a[i-1]}}' -- Oliver C.