Skip to content

Instantly share code, notes, and snippets.

@britto
Created June 20, 2012 01:42
Show Gist options
  • Save britto/2957618 to your computer and use it in GitHub Desktop.
Save britto/2957618 to your computer and use it in GitHub Desktop.
numbers = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10]
operators = ["+", "-", ""]
operations = numbers.size - 1
expressions = operators.repeated_permutation(operations).map do |sequence|
numbers.zip(sequence).join
end
p "Exploring #{expressions.size} possibilities."
hit = expressions.find { |exp| eval(exp) == 100 }
p "Found! #{hit} == 100"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment