Add tags

Add tags to the following comment

演算子の重複順列を5進数00000000から44444444で表現して総当たり。

10進数を"%08d" % i.to_s(5)で8桁の5進数に変換。

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
n = (1..9).to_a
op = ["",".0/","+","-","*"]
for i in 0..((5**8)-1)
  a = n.zip(("%08d" % i.to_s(5)).chars.map{|j|op[j.to_i]}).to_s
  puts a.tr("*/+-","×÷+-").concat("=#{eval(a)}").gsub(/\.0/,"") if eval(a) == 100.0
end

# => 123+45-67+8-9=100
# => 123+4-5+67-89=100
# => 123+4×5-6×7+8-9=100
# => 123-45-67+89=100
# => 123-4-5-6-7+8-9=100
# => 12÷3÷4+5×6+78-9=100
# => 12÷3+4×5-6-7+89=100
# => 12÷3+4×5×6-7-8-9=100
# => 12÷3+4×5×6×7÷8-9=100
# => 12+34+5×6+7+8+9=100
#...101個表示。

Add tags

The input will be splited to tags with space.

Index

Feed

Other

Link

Pathtraq

loading...