fujidig #5096(2008/01/01 14:18 GMT) [ Ruby ] Rating1/1=1.00
user system total real 38.657000 0.109000 38.766000 ( 39.703000) result : f( 837799 ) = 524 でした><
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38
def f n step = 0 _n = n while n != 1 if n.class == Fixnum && $cache[n] != nil step += $cache[n] break end if n % 2 == 0 n = n / 2 else n = 3 * n + 1 end step += 1 end $cache[_n] = step return step end $cache = [] require 'benchmark' max_f = 0 max_i = 0 puts Benchmark::CAPTION puts Benchmark.measure { for i in 1..2**20 f_i = f(i) if f_i > max_f max_f = f_i max_i = i end end } puts "result : f( #{max_i} ) = #{max_f}"
Rating1/1=1.00-0+
1 reply [ reply ]
fujidig #5097(2008/01/01 14:21 GMT) Rating0/0=0.00
[ reply ]
fujidig
#5096()
[
Ruby
]
Rating1/1=1.00
Rating1/1=1.00-0+
1 reply [ reply ]