From: "Mauricio Fernández" Date: 2004-12-08T20:35:22+09:00 Subject: Re: Ruby 2.0 On Wed, Dec 08, 2004 at 02:52:35PM +0900, Oliver Cromm wrote: > > 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}' > > Obvious 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: Nice catch, we save 1 char. > 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. Yes, that's what I had in mind. > Accepting the extra indent, my shortest now 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]}}' ruby -e'a=[];10.times{|n|a<<1;puts" "*(9-n)*3+"%6d"*(n+1)%a;n. times{|i|a[n]+=a[n-=1]}}' It can be made to fit in a canonical 80-char line (actually 78): a=[];10.times{|n|a<<1;puts" "*(9-n)*3+"%6d"*(n+1)%a;n.times{|i|a[n]+=a[n-=1]}} The indentation code might allow further optimization. -- Hassle-free packages for Ruby? RPA is available from http://www.rubyarchive.org/