Initial data commit

This commit is contained in:
Ingy döt Net 2023-07-01 11:58:00 -04:00
parent 72d218235f
commit f23f22d71c
199087 changed files with 3378941 additions and 0 deletions

View file

@ -0,0 +1,8 @@
function move(n, a, b, c) {
if (n > 0) {
move(n-1, a, c, b);
console.log("Move disk from " + a + " to " + c);
move(n-1, b, a, c);
}
}
move(4, "A", "B", "C");

View file

@ -0,0 +1,16 @@
(function () {
// hanoi :: Int -> String -> String -> String -> [[String, String]]
function hanoi(n, a, b, c) {
return n ? hanoi(n - 1, a, c, b)
.concat([
[a, b]
])
.concat(hanoi(n - 1, c, b, a)) : [];
}
return hanoi(3, 'left', 'right', 'mid')
.map(function (d) {
return d[0] + ' -> ' + d[1];
});
})();

View file

@ -0,0 +1,4 @@
["left -> right", "left -> mid",
"right -> mid", "left -> right",
"mid -> left", "mid -> right",
"left -> right"]

View file

@ -0,0 +1,26 @@
(() => {
"use strict";
// ----------------- TOWERS OF HANOI -----------------
// hanoi :: Int -> String -> String ->
// String -> [[String, String]]
const hanoi = n =>
(a, b, c) => {
const go = hanoi(n - 1);
return Boolean(n) ? [
...go(a, c, b),
...[
[a, b]
],
...go(c, b, a)
] : [];
};
// ---------------------- TEST -----------------------
return hanoi(3)("left", "right", "mid")
.map(d => `${d[0]} -> ${d[1]}`)
.join("\n");
})();