Data commit
This commit is contained in:
parent
7387c8f97b
commit
cb5bb5e222
199093 changed files with 3378972 additions and 0 deletions
|
|
@ -0,0 +1,3 @@
|
|||
function ack(m, n) {
|
||||
return m === 0 ? n + 1 : ack(m - 1, n === 0 ? 1 : ack(m, n - 1));
|
||||
}
|
||||
|
|
@ -0,0 +1,6 @@
|
|||
function ack(M,N) {
|
||||
for (; M > 0; M--) {
|
||||
N = N === 0 ? 1 : ack(M,N-1);
|
||||
}
|
||||
return N+1;
|
||||
}
|
||||
20
Task/Ackermann-function/JavaScript/ackermann-function-3.js
Normal file
20
Task/Ackermann-function/JavaScript/ackermann-function-3.js
Normal file
|
|
@ -0,0 +1,20 @@
|
|||
function stackermann(M, N) {
|
||||
const stack = [];
|
||||
for (;;) {
|
||||
if (M === 0) {
|
||||
N++;
|
||||
if (stack.length === 0) return N;
|
||||
const r = stack[stack.length-1];
|
||||
if (r[1] === 1) stack.length--;
|
||||
else r[1]--;
|
||||
M = r[0];
|
||||
} else if (N === 0) {
|
||||
M--;
|
||||
N = 1;
|
||||
} else {
|
||||
M--
|
||||
stack.push([M, N]);
|
||||
N = 1;
|
||||
}
|
||||
}
|
||||
}
|
||||
26
Task/Ackermann-function/JavaScript/ackermann-function-4.js
Normal file
26
Task/Ackermann-function/JavaScript/ackermann-function-4.js
Normal file
|
|
@ -0,0 +1,26 @@
|
|||
#!/usr/bin/env nodejs
|
||||
function ack(M, N){
|
||||
const next = new Float64Array(M + 1);
|
||||
const goal = new Float64Array(M + 1).fill(1, 0, M);
|
||||
const n = N + 1;
|
||||
|
||||
// This serves as a sentinel value;
|
||||
// next[M] never equals goal[M] == -1,
|
||||
// so we don't need an extra check for
|
||||
// loop termination below.
|
||||
goal[M] = -1;
|
||||
|
||||
let v;
|
||||
do {
|
||||
v = next[0] + 1;
|
||||
let m = 0;
|
||||
while (next[m] === goal[m]) {
|
||||
goal[m] = v;
|
||||
next[m++]++;
|
||||
}
|
||||
next[m]++;
|
||||
} while (next[M] !== n);
|
||||
return v;
|
||||
}
|
||||
var args = process.argv;
|
||||
console.log(ack(parseInt(args[2]), parseInt(args[3])));
|
||||
38
Task/Ackermann-function/JavaScript/ackermann-function-5.js
Normal file
38
Task/Ackermann-function/JavaScript/ackermann-function-5.js
Normal file
|
|
@ -0,0 +1,38 @@
|
|||
(() => {
|
||||
'use strict';
|
||||
|
||||
// ackermann :: Int -> Int -> Int
|
||||
const ackermann = m => n => {
|
||||
const go = (m, n) =>
|
||||
0 === m ? (
|
||||
succ(n)
|
||||
) : go(pred(m), 0 === n ? (
|
||||
1
|
||||
) : go(m, pred(n)));
|
||||
return go(m, n);
|
||||
};
|
||||
|
||||
// TEST -----------------------------------------------
|
||||
const main = () => console.log(JSON.stringify(
|
||||
[0, 1, 2, 3].map(
|
||||
flip(ackermann)(3)
|
||||
)
|
||||
));
|
||||
|
||||
|
||||
// GENERAL FUNCTIONS ----------------------------------
|
||||
|
||||
// flip :: (a -> b -> c) -> b -> a -> c
|
||||
const flip = f =>
|
||||
x => y => f(y)(x);
|
||||
|
||||
// pred :: Enum a => a -> a
|
||||
const pred = x => x - 1;
|
||||
|
||||
// succ :: Enum a => a -> a
|
||||
const succ = x => 1 + x;
|
||||
|
||||
|
||||
// MAIN ---
|
||||
return main();
|
||||
})();
|
||||
Loading…
Add table
Add a link
Reference in a new issue