Skip to content

Instantly share code, notes, and snippets.

@podopie
Created June 24, 2011 04:55
Show Gist options
  • Save podopie/1044256 to your computer and use it in GitHub Desktop.
Save podopie/1044256 to your computer and use it in GitHub Desktop.
using || operator to determine sequencing
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