--zhCMOmXpKuAK7kK2Mkz
Content-Type: text/plain
Content-Transfer-Encoding: 7bit

I like this excentricity. Added it to my script.

> By tweaking a bit the script you can easily obtain a
> Sierpinski triangle, as mentioned in a previous post:

Traditionally, this is done by number%2, but this 2 could be
a 3 or a 4 has well, giving different results:

 cell  ow[cell_nr]%sierpinski ? " " : "*"

I patched my script.

Thanks.

gegroet,
Erik V. - http://www.erikveen.dds.nl/


--zhCMOmXpKuAK7kK2Mkz
Content-Disposition: attachment; filename=pascaltriangle.rb
Content-Type: text/plain; name=pascaltriangle.rb; charset=utf-8
Content-Transfer-Encoding: 7bit

rows		 ARGV.shift || 10).to_i						# The number of rows: >sierpinski	 ARGV.shift || 0).to_i						# Sierpinski: 
excentricity	 ARGV.shift || 0.0).to_f						# Excentricity: -1.0..+1.0

sierpinski	 	if sierpinski 1						# Prevent an empty output.

fac	 ambda{|n| n <? 1 : (1..n).inject{|a, b| a*b}}				# Faculty of n.
cell	 ambda{|r, c| fac[r-1]/fac[c-1]/fac[r-c]}					# The content of a specific cell.
biggest	 ell[rows, rows/2+1]								# The biggest number in the last row.
width	 iggest.to_s.length								# The width of each cell...
width	+if width % 2 0							# ...but it shouldn't be even.
width	 	if sierpinski > 0

(1..rows).inject([1]) do |row, row_nr|							# Start with row].
  line (0...row_nr).map do |cell_nr|								# Each cell should have the correct width.
    cell	 ow[cell_nr].to_s							# Get the contents of the cell.
    cell	 ow[cell_nr]%sierpinski ? " " : "*"	if sierpinski > 0
    rhs  lhs	 ell_nr < row_nr/2							# Are we in the right hand side or in the left hand side of the triangle?
    left	 width+1 - cell.length)/2	if lhs					# Number of padding characters at the left, within the cell, erroring to the right.
    left	 width+0 - cell.length)/2	if rhs					# Number of padding characters at the left, within the cell, erroring to the left.
    right	 width - cell.length - left)

    " "*left + cell + " "*right								# The new contents of the cell.
  end.join(" ")										# Join the cells into a line.

  left		 rows - row_nr) * (width/2+1)						# Number of padding characters at the left, on the line.
  left		 excentricity + 1.0) * left						# "Lean" to the left, or to the right.
  line		  "*left + line

  margin	 idth/2								# Half the cell width...
  line		 ine[margin...-margin]	unless sierpinski > 0			# ...can be stripped at the left and at the right of the line.

  puts line										# Print it!

  ([0]+row).zip(row+[0]).map{|a, b| a+b}	unless row_nr rows			# Build the next row. It's explained below.
end

--zhCMOmXpKuAK7kK2Mkz--