mirror of
https://github.com/ruby/ruby.git
synced 2022-11-09 12:17:21 -05:00
f44446c45d
mesurement time makes less accuracy. * benchmark/bm_app_factorial.rb: ditto. * benchmark/bm_app_mandelbrot.rb: ditto. * benchmark/bm_app_strconcat.rb: ditto. * benchmark/bm_io_file_create.rb: ditto. * benchmark/bm_io_file_read.rb: ditto. * benchmark/bm_io_file_write.rb: ditto. * benchmark/bm_so_concatenate.rb: ditto. * benchmark/bm_so_lists.rb: ditto. * benchmark/bm_so_matrix.rb: ditto. * benchmark/bm_so_random.rb: ditto. * benchmark/bm_so_sieve.rb: ditto. * benchmark/bm_vm_thread_mutex1.rb: ditto. * benchmark/bm_vm_thread_mutex2.rb: ditto. * benchmark/bm_vm_thread_mutex3.rb: ditto. * benchmark/bm_vm1_block.rb: cleanup. * benchmark/bm_vm1_const.rb: cleanup. * benchmark/bm_vm1_ensure.rb: cleanup. * benchmark/bm_vm1_ivar.rb: cleanup. * benchmark/bm_vm1_length.rb: cleanup. * benchmark/bm_vm1_neq.rb: cleanup. * benchmark/bm_vm1_not.rb: cleanup. * benchmark/bm_vm1_rescue.rb: cleanup. * benchmark/bm_vm1_simplereturn.rb: cleanup. * benchmark/bm_vm1_swap.rb: cleanup. * benchmark/bm_vm2_array.rb: cleanup. * benchmark/bm_vm2_case.rb: cleanup. * benchmark/bm_vm2_defined_method.rb: cleanup. * benchmark/bm_vm2_eval.rb: cleanup. * benchmark/bm_vm2_method.rb: cleanup. * benchmark/bm_vm2_mutex.rb: cleanup. * benchmark/bm_vm2_poly_method.rb: cleanup. * benchmark/bm_vm2_poly_method_ov.rb: cleanup. * benchmark/bm_vm2_proc.rb: cleanup. * benchmark/bm_vm2_regexp.rb: cleanup. * benchmark/bm_vm2_send.rb: cleanup. * benchmark/bm_vm2_super.rb: cleanup. * benchmark/bm_vm2_unif1.rb: cleanup. * benchmark/bm_vm2_zsuper.rb: cleanup. * benchmark/bm_vm_thread_alive_check1.rb: cleanup. git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@32356 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
45 lines
928 B
Ruby
45 lines
928 B
Ruby
# The Computer Language Shootout
|
|
# http://shootout.alioth.debian.org/
|
|
# Contributed by Sokolov Yura
|
|
# Modified by Ryan Williams
|
|
|
|
def fannkuch(n)
|
|
maxFlips, m, r, check = 0, n-1, n, 0
|
|
count = (1..n).to_a
|
|
perm = (1..n).to_a
|
|
|
|
while true
|
|
if check < 30
|
|
puts "#{perm}"
|
|
check += 1
|
|
end
|
|
|
|
while r != 1
|
|
count[r-1] = r
|
|
r -= 1
|
|
end
|
|
|
|
if perm[0] != 1 and perm[m] != n
|
|
perml = perm.clone #.dup
|
|
flips = 0
|
|
while (k = perml.first ) != 1
|
|
perml = perml.slice!(0, k).reverse + perml
|
|
flips += 1
|
|
end
|
|
maxFlips = flips if flips > maxFlips
|
|
end
|
|
while true
|
|
if r==n then return maxFlips end
|
|
perm.insert r,perm.shift
|
|
break if (count[r] -= 1) > 0
|
|
r += 1
|
|
end
|
|
end
|
|
end
|
|
|
|
def puts *args
|
|
end
|
|
|
|
N = 9 # (ARGV[0] || 1).to_i
|
|
puts "Pfannkuchen(#{N}) = #{fannkuch(N)}"
|
|
|