Comment detail

法演算 (Nested Flatten)
こんなもんでいいのかな.
1
2
3
4
5
6
7
8
9
OPRS = ['\+', '\-', '\*']
EQN = "1 - 4 * 5".split(/([#{OPRS.join}])/)
N = 5
#
result = EQN[0]
(EQN.size - 1).div(2).times{|i|
  result = (eval "#{result}#{EQN[2*i+1]}#{EQN[2*i+2]}").modulo(N)
}
p "#{EQN}: #{result}"

Index

Feed

Other

Link

Pathtraq

loading...