Data update

This commit is contained in:
Ingy döt Net 2024-07-13 15:19:22 -07:00
parent 29a5eea0d4
commit 5c1bb7bfa9
2011 changed files with 35081 additions and 3229 deletions

View file

@ -7,9 +7,9 @@
const roman = n =>
mapAccumL(residue =>
([k, v]) => second(
q => 0 < q ? (
k.repeat(q)
) : ""
q => 0 < q
? k.repeat(q)
: ""
)(remQuot(residue)(v))
)(n)(
zip([
@ -27,11 +27,31 @@
// main :: IO ()
const main = () => (
[2016, 1990, 2008, 2000, 2020, 1666].map(roman)
).join("\n");
)
.join("\n");
// ---------------- GENERIC FUNCTIONS ----------------
// Tuple (,) :: a -> b -> (a, b)
const Tuple = a =>
// A pair of values, possibly of
// different types.
b => ({
type: "Tuple",
"0": a,
"1": b,
length: 2,
*[Symbol.iterator]() {
for (const k in this) {
if (!isNaN(k)) {
yield this[k];
}
}
}
});
// mapAccumL :: (acc -> x -> (acc, y)) -> acc ->
// [x] -> (acc, [y])
const mapAccumL = f =>
@ -39,14 +59,11 @@
// obtained by a combined map and fold,
// with accumulation from left to right.
acc => xs => [...xs].reduce(
(a, x) => {
const tpl = f(a[0])(x);
return [
tpl[0],
a[1].concat(tpl[1])
];
},
([a, bs], x) => second(
v => [...bs, v]
)(
f(a)(x)
),
[acc, []]
);
@ -61,7 +78,11 @@
// A function over a simple value lifted
// to a function over a tuple.
// f (a, b) -> (a, f(b))
xy => [xy[0], f(xy[1])];
xy => Tuple(
xy[0]
)(
f(xy[1])
);
// zip :: [a] -> [b] -> [(a, b)]