1 # The Computer Language Shootout
2 # http://shootout.alioth.debian.org/
3 # Contributed by Sokolov Yura
4 # Modified by Ryan Williams
7 maxFlips
, m
, r
, check
= 0, n-1
, n
, 0
22 if perm
[0] != 1 and perm
[m
] != n
23 perml
= perm
.clone
#.dup
25 while (k
= perml
.first
) != 1
26 perml
= perml
.slice
!(0, k
).reverse
+ perml
29 maxFlips
= flips
if flips
> maxFlips
32 if r
==n
: return maxFlips
end
33 perm
.insert r
,perm
.shift
34 break if (count
[r
] -= 1) > 0
40 N
= (ARGV[0] || 1).to_i
41 puts
"Pfannkuchen(#{N}) = #{fannkuch(N)}"