Skip to content

Instantly share code, notes, and snippets.

@sauron
Last active December 31, 2015 21:09
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save sauron/8044613 to your computer and use it in GitHub Desktop.
Save sauron/8044613 to your computer and use it in GitHub Desktop.
What it takes to make a scalable Christmas tree in Ruby?
#Simple tree that will look as an arrow :D
height = 20
((1..height).to_a+[6]*height.div(5)).map do |i|
puts ('*'*i*2).center(80)
end
#Simple tree that look more like a doodle christmas tree
height = 20
(
(1..height.div(2)).to_a +
(height.div(4)..(height.div(2)+height.div(4))).to_a +
(height.div(2)..height).to_a +
[3]*height.div(3)
).map do |i|
puts ('*'*i*4).center(80)
end
#Or almost one liner
height = 20
((1..height.div(2)).to_a+(height.div(4)..(height.div(2)+height.div(4))).to_a+(height.div(2)..height).to_a+[3]*height.div(3)).map do |i|
puts ('*'*i*4).center(80)
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment