2 <!-- MOZ_INSERT_CONTENT_HOOK -->
3 <script src = runner.js
></script>
5 var onlyName
= 'Pfannkuchen', onlyNum
= 8;
8 /* The Great Computer Language Shootout
9 http://shootout.alioth.debian.org/
10 contributed by Isaac Gouy */
12 function fannkuch(n
) {
17 var maxPerm
= Array(n
);
18 var maxFlipsCount
= 0;
21 for (var i
= 0; i
< n
; i
++) perm1
[i
] = i
;
25 // write-out the first 30 permutations
28 for(var i
=0; i
<n
; i
++) s
+= (perm1
[i
]+1).toString();
32 while (r
!= 1) { count
[r
- 1] = r
; r
--; }
33 if (!(perm1
[0] == 0 || perm1
[m
] == m
)) {
34 for (var i
= 0; i
< n
; i
++) perm
[i
] = perm1
[i
];
39 while (!((k
= perm
[0]) == 0)) {
40 var k2
= (k
+ 1) >> 1;
41 for (var i
= 0; i
< k2
; i
++) {
42 var temp
= perm
[i
]; perm
[i
] = perm
[k
- i
]; perm
[k
- i
] = temp
;
47 if (flipsCount
> maxFlipsCount
) {
48 maxFlipsCount
= flipsCount
;
49 for (var i
= 0; i
< n
; i
++) maxPerm
[i
] = perm1
[i
];
54 if (r
== n
) return maxFlipsCount
;
64 count
[r
] = count
[r
] - 1;
65 if (count
[r
] > 0) break;
71 startTest("real-fannkuch");
75 for ( var n
= 5; n
<= 8; n
++ ) (function(n
){
76 test( "Pfannkuchen", n
, function(){
84 <body onload=
"thisTest()"></body></html>