Skip to content

Instantly share code, notes, and snippets.

@track8
Last active August 25, 2017 03:14
Show Gist options
  • Save track8/34ecd29debad8195957c082084ab3982 to your computer and use it in GitHub Desktop.
Save track8/34ecd29debad8195957c082084ab3982 to your computer and use it in GitHub Desktop.
require 'mathn'
car, *cdr = (1..9).map{|i| ['', '+', '-', '*', '/'].map { |o| o + i.to_s }}
exps = car.product(*cdr).map {|exp| exp.join}.delete_if{|e| e =~ /^[\+|\*|\/]/}
komachies = exps.select{|e| eval(e) == 100}
komachies.each {|k| puts k}
puts "#{komachies.count} / #{exps.count}"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment