Created
November 19, 2014 00:44
-
-
Save glpunk/b501f42851a5898a6071 to your computer and use it in GitHub Desktop.
utopian tree example
This file contains hidden or 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
#!/usr/bin/ruby | |
class Utopiantree | |
def cycle n | |
size = 1 | |
if n > 0 | |
for val in 0..n-1 | |
if val % 2 == 0 | |
size = size * 2 | |
else | |
size = size + 1 | |
end | |
end | |
end | |
size | |
end | |
end | |
p = Utopiantree.new | |
t = gets.to_i | |
for val in 1..t | |
p p.cycle gets.to_i | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment