Guest User

Untitled

a guest
Dec 13th, 2017
75
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.53 KB | None | 0 0
  1. (0..9).to_a.repeated_combination(4).each do |fourDigits|
  2. ten = false
  3. first = false
  4. fourDigits.permutation.each do |a, b, c, d|
  5. ['+', '-', '*', '/'].repeated_permutation(3).each do |op1, op2, op3|
  6. term = "((#{a}.0#{op1}#{b}.0)#{op2}#{c}.0)#{op3}#{d}.0"
  7. if (eval(term) == 10.0 rescue false)
  8. ten = true
  9. break
  10. end
  11.  
  12. term = "(#{a}.0#{op1}#{b}.0)#{op2}(#{c}.0#{op3}#{d}.0)"
  13. if (eval(term) == 10.0 rescue false)
  14. ten = true
  15. break
  16. end
  17. end
  18. end
  19.  
  20. p fourDigits unless ten
  21. end
Add Comment
Please, Sign In to add comment