Merge Chromium + Blink git repositories
[chromium-blink-merge.git] / chrome / test / data / dromaeo / tests / sunspider-access-fannkuch.html
blob55044289a356c06b1a547bb3a92517db348fa62a
1 <html>
2 <head>
3 <script src="../htmlrunner.js"></script>
4 <script>
5 /* The Great Computer Language Shootout
6 http://shootout.alioth.debian.org/
7 contributed by Isaac Gouy */
9 function fannkuch(n) {
10 var check = 0;
11 var perm = Array(n);
12 var perm1 = Array(n);
13 var count = Array(n);
14 var maxPerm = Array(n);
15 var maxFlipsCount = 0;
16 var m = n - 1;
18 for (var i = 0; i < n; i++) perm1[i] = i;
19 var r = n;
21 while (true) {
22 // write-out the first 30 permutations
23 if (check < 30){
24 var s = "";
25 for(var i=0; i<n; i++) s += (perm1[i]+1).toString();
26 check++;
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];
33 var flipsCount = 0;
34 var k;
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;
41 flipsCount++;
44 if (flipsCount > maxFlipsCount) {
45 maxFlipsCount = flipsCount;
46 for (var i = 0; i < n; i++) maxPerm[i] = perm1[i];
50 while (true) {
51 if (r == n) return maxFlipsCount;
52 var perm0 = perm1[0];
53 var i = 0;
54 while (i < r) {
55 var j = i + 1;
56 perm1[i] = perm1[j];
57 i = j;
59 perm1[r] = perm0;
61 count[r] = count[r] - 1;
62 if (count[r] > 0) break;
63 r++;
68 window.onload = function(){ startTest("sunspider-access-fannkuch", '786198fd');
70 var ret;
72 test( "Pfannkuchen", function(){
73 ret = fannkuch(7);
74 });
76 endTest(); };
77 </script>
78 </head>
79 <body></body>
80 </html>