Initial data commit
This commit is contained in:
parent
72d218235f
commit
f23f22d71c
199087 changed files with 3378941 additions and 0 deletions
|
|
@ -0,0 +1,23 @@
|
|||
(function () {
|
||||
|
||||
// wakeSplit :: Int -> Int -> Int -> Int
|
||||
function wakeSplit(intNuts, intSailors, intDepth) {
|
||||
var nDepth = intDepth !== undefined ? intDepth : intSailors,
|
||||
portion = Math.floor(intNuts / intSailors),
|
||||
remain = intNuts % intSailors;
|
||||
|
||||
return 0 >= portion || remain !== (nDepth ? 1 : 0) ?
|
||||
null : nDepth ? wakeSplit(
|
||||
intNuts - portion - remain, intSailors, nDepth - 1
|
||||
) : intNuts;
|
||||
}
|
||||
|
||||
// TEST for 5, 6, and 7 intSailors
|
||||
return [5, 6, 7].map(function (intSailors) {
|
||||
var intNuts = intSailors;
|
||||
|
||||
while (!wakeSplit(intNuts, intSailors)) intNuts += 1;
|
||||
|
||||
return intNuts;
|
||||
});
|
||||
})();
|
||||
|
|
@ -0,0 +1 @@
|
|||
[3121, 233275, 823537]
|
||||
|
|
@ -0,0 +1,61 @@
|
|||
(() => {
|
||||
"use strict";
|
||||
|
||||
// wakeSplit :: Int -> Int -> Int -> Int
|
||||
const wakeSplit = intSailors =>
|
||||
(intNuts, intDepth) => {
|
||||
const
|
||||
nDepth = intDepth !== undefined ? (
|
||||
intDepth
|
||||
) : intSailors,
|
||||
portion = Math.floor(intNuts / intSailors),
|
||||
remain = intNuts % intSailors;
|
||||
|
||||
return 0 >= portion || remain !== (
|
||||
nDepth ? (
|
||||
1
|
||||
) : 0
|
||||
) ? (
|
||||
null
|
||||
) : nDepth ? (
|
||||
wakeSplit(
|
||||
intSailors
|
||||
)(
|
||||
intNuts - portion - remain,
|
||||
nDepth - 1
|
||||
)
|
||||
) : intNuts;
|
||||
};
|
||||
|
||||
// ---------------------- TEST -----------------------
|
||||
const main = () =>
|
||||
// TEST for 5, 6, and 7 Sailors
|
||||
[5, 6, 7].map(intSailors => {
|
||||
const intNuts = intSailors;
|
||||
|
||||
return until(
|
||||
wakeSplit(intNuts)
|
||||
)(x => 1 + x)(intNuts);
|
||||
});
|
||||
|
||||
|
||||
// --------------------- GENERIC ---------------------
|
||||
|
||||
// until :: (a -> Bool) -> (a -> a) -> a -> a
|
||||
const until = p =>
|
||||
// The value resulting from repeated applications
|
||||
// of f to the seed value x, terminating when
|
||||
// that result returns true for the predicate p.
|
||||
f => x => {
|
||||
let v = x;
|
||||
|
||||
while (!p(v)) {
|
||||
v = f(v);
|
||||
}
|
||||
|
||||
return v;
|
||||
};
|
||||
|
||||
// MAIN ---
|
||||
return main();
|
||||
})();
|
||||
|
|
@ -0,0 +1 @@
|
|||
[3121, 233275, 823537]
|
||||
Loading…
Add table
Add a link
Reference in a new issue