Created
December 19, 2021 02:52
-
-
Save emasaka/25fd35460f972f0ac7cc8c1e4abe4a09 to your computer and use it in GitHub Desktop.
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
#!/usr/bin/env ruby | |
nums = [2, 3, 7, 9] | |
nums.permutation do |ns| | |
%i(+ - * /).repeated_permutation(ns.size - 1) do |ops| | |
begin | |
x, *xs = ns | |
z = ops.zip(xs).inject(Rational(x)) {|r, v| r.send(*v) } | |
p ns.zip(ops).flatten.compact if z == Rational(10) | |
rescue ZeroDivisionError | |
end | |
end | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment