Last active
September 29, 2019 06:30
-
-
Save colorbox/306c805c8fb9490b4065ae963c05848d to your computer and use it in GitHub Desktop.
This file contains hidden or 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
def split_num(num) | |
("%04d" % num).split('').map(&:to_i) | |
end | |
def split_num_f(num) | |
split_num(num).map(&:to_f) | |
end | |
def twined(nums, symbols) | |
nums.zip(symbols).flatten.compact.map(&:to_s).join('') | |
end | |
S = [:+, :-, :*, :/].repeated_permutation(3) | |
def check(num) | |
sp = split_num_f(num) | |
return if sp.any?(&:zero?) || sp.uniq.count!=4 | |
S.map.select do |symbols| | |
eval(twined(sp, symbols))==10 | |
end | |
end | |
r = 10_000.times.map { |num| | |
c = check(num) | |
unless c.nil? || c.empty? | |
c.map{|cc| twined(split_num(num), cc)} | |
end | |
}.flatten.compact | |
p r | |
p"---" | |
p r.length |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
ありがとう!参考にやってみます。