Skip to content

Instantly share code, notes, and snippets.

@colorbox
Last active Sep 29, 2019
Embed
What would you like to do?
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
@kenjihiranabe
Copy link

kenjihiranabe commented Sep 29, 2019

ありがとう!参考にやってみます。

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment