Last active
December 31, 2015 21:09
-
-
Save sauron/8044613 to your computer and use it in GitHub Desktop.
What it takes to make a scalable Christmas tree in Ruby?
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#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