Created
June 24, 2011 04:55
-
-
Save podopie/1044256 to your computer and use it in GitHub Desktop.
using || operator to determine sequencing
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
def find_sequence goal | |
def find start, history, goal | |
if start == goal | |
history | |
elsif start > goal | |
nil | |
else | |
find(start + 5, '(' + history + ' + 5)', goal) || find(start * 3, '(' + history + ' * 3)', goal) | |
end | |
end | |
find(1, "1", goal) | |
end | |
puts findSequence(24) # => (((1 * 3) + 5) * 3) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment