Skip to content

Instantly share code, notes, and snippets.

@youxkei
Created December 11, 2017 13:24
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save youxkei/6d41552776f89f5087d87e95bd44ddae to your computer and use it in GitHub Desktop.
Save youxkei/6d41552776f89f5087d87e95bd44ddae to your computer and use it in GitHub Desktop.
(0..9).to_a.repeated_combination(4).each do |fourDigits|
ten = false
first = false
fourDigits.permutation.each do |a, b, c, d|
['+', '-', '*', '/'].repeated_permutation(3).each do |op1, op2, op3|
term = "((#{a}.0#{op1}#{b}.0)#{op2}#{c}.0)#{op3}#{d}.0"
if (eval(term) == 10.0 rescue false)
ten = true
break
end
term = "(#{a}.0#{op1}#{b}.0)#{op2}(#{c}.0#{op3}#{d}.0)"
if (eval(term) == 10.0 rescue false)
ten = true
break
end
end
end
p fourDigits unless ten
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment