Data commit
This commit is contained in:
parent
7387c8f97b
commit
cb5bb5e222
199093 changed files with 3378972 additions and 0 deletions
8
Task/Towers-of-Hanoi/JavaScript/towers-of-hanoi-1.js
Normal file
8
Task/Towers-of-Hanoi/JavaScript/towers-of-hanoi-1.js
Normal 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");
|
||||
16
Task/Towers-of-Hanoi/JavaScript/towers-of-hanoi-2.js
Normal file
16
Task/Towers-of-Hanoi/JavaScript/towers-of-hanoi-2.js
Normal 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];
|
||||
});
|
||||
})();
|
||||
4
Task/Towers-of-Hanoi/JavaScript/towers-of-hanoi-3.js
Normal file
4
Task/Towers-of-Hanoi/JavaScript/towers-of-hanoi-3.js
Normal file
|
|
@ -0,0 +1,4 @@
|
|||
["left -> right", "left -> mid",
|
||||
"right -> mid", "left -> right",
|
||||
"mid -> left", "mid -> right",
|
||||
"left -> right"]
|
||||
26
Task/Towers-of-Hanoi/JavaScript/towers-of-hanoi-4.js
Normal file
26
Task/Towers-of-Hanoi/JavaScript/towers-of-hanoi-4.js
Normal 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");
|
||||
})();
|
||||
Loading…
Add table
Add a link
Reference in a new issue