Skip to content

Instantly share code, notes, and snippets.

@colorbox
Last active September 29, 2019 06:30
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 colorbox/306c805c8fb9490b4065ae963c05848d to your computer and use it in GitHub Desktop.
Save colorbox/306c805c8fb9490b4065ae963c05848d to your computer and use it in GitHub Desktop.
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

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

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