OLD | NEW |
(Empty) | |
| 1 dart_library.library('language/fannkuch_test', null, /* Imports */[ |
| 2 'dart_sdk', |
| 3 'expect' |
| 4 ], function load__fannkuch_test(exports, dart_sdk, expect) { |
| 5 'use strict'; |
| 6 const core = dart_sdk.core; |
| 7 const _interceptors = dart_sdk._interceptors; |
| 8 const dart = dart_sdk.dart; |
| 9 const dartx = dart_sdk.dartx; |
| 10 const expect$ = expect.expect; |
| 11 const fannkuch_test = Object.create(null); |
| 12 let JSArrayOfint = () => (JSArrayOfint = dart.constFn(_interceptors.JSArray$(c
ore.int)))(); |
| 13 let VoidTodynamic = () => (VoidTodynamic = dart.constFn(dart.definiteFunctionT
ype(dart.dynamic, [])))(); |
| 14 fannkuch_test.FannkuchTest = class FannkuchTest extends core.Object { |
| 15 static fannkuch(n) { |
| 16 let p = core.List.new(core.int._check(n)), q = core.List.new(core.int._che
ck(n)), s = core.List.new(core.int._check(n)); |
| 17 let sign = 1, maxflips = 0, sum = 0, m = dart.dsend(n, '-', 1); |
| 18 for (let i = 0; i < dart.notNull(core.num._check(n)); i++) { |
| 19 p[dartx.set](i, i); |
| 20 q[dartx.set](i, i); |
| 21 s[dartx.set](i, i); |
| 22 } |
| 23 do { |
| 24 let q0 = p[dartx.get](0); |
| 25 if (!dart.equals(q0, 0)) { |
| 26 for (let i = 1; i < dart.notNull(core.num._check(n)); i++) |
| 27 q[dartx.set](i, p[dartx.get](i)); |
| 28 let flips = 1; |
| 29 do { |
| 30 let qq = q[dartx.get](core.int._check(q0)); |
| 31 if (dart.equals(qq, 0)) { |
| 32 sum = sum + sign * flips; |
| 33 if (flips > maxflips) maxflips = flips; |
| 34 break; |
| 35 } |
| 36 q[dartx.set](core.int._check(q0), q0); |
| 37 if (dart.test(dart.dsend(q0, '>=', 3))) { |
| 38 let i = 1, j = dart.dsend(q0, '-', 1), t = null; |
| 39 do { |
| 40 t = q[dartx.get](i); |
| 41 q[dartx.set](i, q[dartx.get](core.int._check(j))); |
| 42 q[dartx.set](core.int._check(j), t); |
| 43 i++; |
| 44 j = dart.dsend(j, '-', 1); |
| 45 } while (i < dart.notNull(core.num._check(j))); |
| 46 } |
| 47 q0 = qq; |
| 48 flips++; |
| 49 } while (true); |
| 50 } |
| 51 if (sign == 1) { |
| 52 let t = p[dartx.get](1); |
| 53 p[dartx.set](1, p[dartx.get](0)); |
| 54 p[dartx.set](0, t); |
| 55 sign = -1; |
| 56 } else { |
| 57 let t = p[dartx.get](1); |
| 58 p[dartx.set](1, p[dartx.get](2)); |
| 59 p[dartx.set](2, t); |
| 60 sign = 1; |
| 61 for (let i = 2; i < dart.notNull(core.num._check(n)); i++) { |
| 62 let sx = s[dartx.get](i); |
| 63 if (!dart.equals(sx, 0)) { |
| 64 s[dartx.set](i, dart.dsend(sx, '-', 1)); |
| 65 break; |
| 66 } |
| 67 if (dart.equals(i, m)) { |
| 68 return JSArrayOfint().of([sum, maxflips]); |
| 69 } |
| 70 s[dartx.set](i, i); |
| 71 t = p[dartx.get](0); |
| 72 for (let j = 0; j <= i; j++) { |
| 73 p[dartx.set](j, p[dartx.get](j + 1)); |
| 74 } |
| 75 p[dartx.set](i + 1, t); |
| 76 } |
| 77 } |
| 78 } while (true); |
| 79 } |
| 80 static testMain() { |
| 81 let n = 6; |
| 82 let pf = fannkuch_test.FannkuchTest.fannkuch(n); |
| 83 expect$.Expect.equals(49, dart.dindex(pf, 0)); |
| 84 expect$.Expect.equals(10, dart.dindex(pf, 1)); |
| 85 core.print(dart.str`${dart.dindex(pf, 0)}\nPfannkuchen(${n}) = ${dart.dind
ex(pf, 1)}`); |
| 86 } |
| 87 }; |
| 88 dart.setSignature(fannkuch_test.FannkuchTest, { |
| 89 statics: () => ({ |
| 90 fannkuch: dart.definiteFunctionType(dart.dynamic, [dart.dynamic]), |
| 91 testMain: dart.definiteFunctionType(dart.dynamic, []) |
| 92 }), |
| 93 names: ['fannkuch', 'testMain'] |
| 94 }); |
| 95 fannkuch_test.main = function() { |
| 96 fannkuch_test.FannkuchTest.testMain(); |
| 97 }; |
| 98 dart.fn(fannkuch_test.main, VoidTodynamic()); |
| 99 // Exports: |
| 100 exports.fannkuch_test = fannkuch_test; |
| 101 }); |
OLD | NEW |