3 <script src=
"../htmlrunner.js"></script>
5 /* The Great Computer Language Shootout
6 http://shootout.alioth.debian.org/
7 contributed by Isaac Gouy */
14 var maxPerm
= Array(n
);
15 var maxFlipsCount
= 0;
18 for (var i
= 0; i
< n
; i
++) perm1
[i
] = i
;
22 // write-out the first 30 permutations
25 for(var i
=0; i
<n
; i
++) s
+= (perm1
[i
]+1).toString();
29 while (r
!= 1) { count
[r
- 1] = r
; r
--; }
30 if (!(perm1
[0] == 0 || perm1
[m
] == m
)) {
31 for (var i
= 0; i
< n
; i
++) perm
[i
] = perm1
[i
];
36 while (!((k
= perm
[0]) == 0)) {
37 var k2
= (k
+ 1) >> 1;
38 for (var i
= 0; i
< k2
; i
++) {
39 var temp
= perm
[i
]; perm
[i
] = perm
[k
- i
]; perm
[k
- i
] = temp
;
44 if (flipsCount
> maxFlipsCount
) {
45 maxFlipsCount
= flipsCount
;
46 for (var i
= 0; i
< n
; i
++) maxPerm
[i
] = perm1
[i
];
51 if (r
== n
) return maxFlipsCount
;
61 count
[r
] = count
[r
] - 1;
62 if (count
[r
] > 0) break;
68 window
.onload = function(){ startTest("sunspider-access-fannkuch", '786198fd');
72 test( "Pfannkuchen", function(){