講習中などで出れない場合があります


超多面的パラグライダー情報サイト
2020/08/06 19:24
プログラムで解こうとしたら、30分はかかった TARGET = 10 SIGNS = %i[+ - / *] [2, 2, 8, 9].collect(&:to_f).permutation(4).find do |a, b, c, d| SIGNS.permutation(3).find do |x, y, z| { "a.b.c.d": a.send(x, b).send(y, c).send(z, d), "a.(b.(c.d))": a.send(x, b.send(y, c.send(z, d))), "(a.b).(c.d)": a.send(x, b).send(y, c.send(z, d)), "(a.(b.c)).d": a.send(x, b.send(y, c)).send(z, d), "a.((b.c).d)": a.send(x, b.send(y, c).send(z, d)) }.find do |formula, value| (value == TARGET).tap do |found| puts "#{formula} => #{[a, x, b, y, c, z, d].join}" if found end end end end
コメントの投稿には メンバー認証 が必要です。