Data commit
This commit is contained in:
parent
7387c8f97b
commit
cb5bb5e222
199093 changed files with 3378972 additions and 0 deletions
|
|
@ -0,0 +1,55 @@
|
|||
(() => {
|
||||
"use strict";
|
||||
|
||||
// - APPROXIMATION OF E OBTAINED AFTER N ITERATIONS --
|
||||
|
||||
// eApprox : Int -> Float
|
||||
const eApprox = n =>
|
||||
sum(
|
||||
scanl(mul)(1)(
|
||||
enumFromTo(1)(n)
|
||||
)
|
||||
.map(x => 1 / x)
|
||||
);
|
||||
|
||||
|
||||
// ---------------------- TEST -----------------------
|
||||
const main = () =>
|
||||
eApprox(20);
|
||||
|
||||
|
||||
// ---------------- GENERIC FUNCTIONS ----------------
|
||||
|
||||
// enumFromTo :: Int -> Int -> [Int]
|
||||
const enumFromTo = m =>
|
||||
n => Array.from({
|
||||
length: 1 + n - m
|
||||
}, (_, i) => m + i);
|
||||
|
||||
|
||||
// mul (*) :: Num a => a -> a -> a
|
||||
const mul = a =>
|
||||
// The arithmetic product of a and b.
|
||||
b => a * b;
|
||||
|
||||
|
||||
// scanl :: (b -> a -> b) -> b -> [a] -> [b]
|
||||
const scanl = f => startValue => xs =>
|
||||
// The series of interim values arising
|
||||
// from a catamorphism. Parallel to foldl.
|
||||
xs.reduce((a, x) => {
|
||||
const v = f(a[0])(x);
|
||||
|
||||
return [v, a[1].concat(v)];
|
||||
}, [startValue, [startValue]])[1];
|
||||
|
||||
|
||||
// sum :: [Num] -> Num
|
||||
const sum = xs =>
|
||||
// The numeric sum of all values in xs.
|
||||
xs.reduce((a, x) => a + x, 0);
|
||||
|
||||
|
||||
// MAIN ---
|
||||
return main();
|
||||
})();
|
||||
|
|
@ -0,0 +1,32 @@
|
|||
(() => {
|
||||
"use strict";
|
||||
|
||||
// --------------- APPROXIMATION OF E ----------------
|
||||
|
||||
const eApprox = n =>
|
||||
// Approximation of E obtained after Nth iteration.
|
||||
enumFromTo(1)(n).reduce(
|
||||
([fl, e], x) => (
|
||||
flx => [flx, e + (1 / flx)]
|
||||
)(
|
||||
fl * x
|
||||
),
|
||||
[1, 1]
|
||||
)[1];
|
||||
|
||||
// ---------------------- TEST -----------------------
|
||||
// main :: IO ()
|
||||
const main = () =>
|
||||
eApprox(20);
|
||||
|
||||
// --------------------- GENERIC ---------------------
|
||||
|
||||
// enumFromTo :: Int -> Int -> [Int]
|
||||
const enumFromTo = m =>
|
||||
n => Array.from({
|
||||
length: 1 + n - m
|
||||
}, (_, i) => m + i);
|
||||
|
||||
// MAIN ---
|
||||
return main();
|
||||
})();
|
||||
Loading…
Add table
Add a link
Reference in a new issue