2016 Update
This commit is contained in:
parent
948b86eafa
commit
dcf5d15da3
7965 changed files with 139854 additions and 31002 deletions
|
|
@ -0,0 +1,40 @@
|
|||
(() => {
|
||||
'use strict';
|
||||
|
||||
// hofQSeq :: Int -> [Int]
|
||||
const hofQSeq = x =>
|
||||
x > 2 ? tail(foldl((Q, n) =>
|
||||
n < 3 ? Q : Q.concat(
|
||||
Q[n - Q[n - 1]] + Q[n - Q[n - 2]]
|
||||
), [0, 1, 1],
|
||||
range(1, x))) : (x > 0 ? take(x, [1, 1]) : undefined);
|
||||
|
||||
|
||||
// GENERIC FUNCTIONS -------------------------------------------
|
||||
|
||||
// foldl :: (b -> a -> b) -> b -> [a] -> b
|
||||
const foldl = (f, a, xs) => xs.reduce(f, a),
|
||||
|
||||
// range :: Int -> Int -> [Int]
|
||||
range = (m, n) =>
|
||||
Array.from({
|
||||
length: Math.floor(n - m) + 1
|
||||
}, (_, i) => m + i),
|
||||
|
||||
// tail :: [a] -> [a]
|
||||
tail = xs => xs.length ? xs.slice(1) : undefined,
|
||||
|
||||
// last :: [a] -> a
|
||||
last = xs => xs.length ? xs.slice(-1)[0] : undefined,
|
||||
|
||||
// Int -> [a] -> [a]
|
||||
take = (n, xs) => xs.slice(0, n);
|
||||
|
||||
// TEST --------------------------------------------------------
|
||||
return {
|
||||
firstTen: hofQSeq(10),
|
||||
thousandth: last(hofQSeq(1000)),
|
||||
'Q<Q-1UpTo10E5': hofQSeq(100000)
|
||||
.reduce((a, x, i, xs) => x < xs[i - 1] ? a + 1 : a, 0)
|
||||
};
|
||||
})();
|
||||
|
|
@ -0,0 +1,3 @@
|
|||
{"firstTen":[1, 1, 2, 3, 3, 4, 5, 5, 6, 6],
|
||||
"thousandth":502,
|
||||
"Q<Q-1UpTo10E5":49798}
|
||||
Loading…
Add table
Add a link
Reference in a new issue