Post-Season Fun: Christmas Tree with *

I know this comes a bit late, but this made me want to give it a bash in Ruby… So here is my Christmas tree with ‘*’ in Ruby.

WIDTH = 10

(1..3).each do
  |j|
  1.step(WIDTH, 2) do
	|i|
	# This if truncates the top of the triangles for level 2 and 3.
	if not(j>1 and i==1)
	  ((WIDTH-i)/2).times{ print " "  }
	  i.times{ print "*" }
	  puts ""
	end
  end
end
(1..3).each do
  |i|
  ((WIDTH-3)/2).times{ print " " }
  3.times{ print "*" }
  puts ""
end

This gives:

    *
   ***
  *****
 *******
*********
   ***
  *****
 *******
*********
   ***
  *****
 *******
*********
   ***
   ***
   ***

Oooooh!

 
---

Comment

your_ip_is_blacklisted_by sbl.spamhaus.org

---