Data update
This commit is contained in:
parent
29a5eea0d4
commit
5c1bb7bfa9
2011 changed files with 35081 additions and 3229 deletions
|
|
@ -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)]
|
||||
|
|
|
|||
|
|
@ -0,0 +1,21 @@
|
|||
var anums := |1000, 900, 500, 400, 100, 90, 50, 40, 10, 9, 5, 4, 1|;
|
||||
var rnums := 'M CM D CD C XC L XL X IX V IV I'.split;
|
||||
|
||||
function ToRoman(x: integer): string;
|
||||
begin
|
||||
Result := '';
|
||||
foreach var (a,r) in anums.Zip(rnums) do
|
||||
begin
|
||||
var n := x div a;
|
||||
x := x mod a;
|
||||
Result += r * n;
|
||||
end;
|
||||
end;
|
||||
|
||||
begin
|
||||
var test := |1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 25, 30, 40,
|
||||
50, 60, 69, 70, 80, 90, 99, 100, 200, 300, 400, 500, 600, 666, 700, 800, 900, 1000,
|
||||
1009, 1444, 1666, 1945, 1997, 1999, 2000, 2008, 2010, 2011, 2500, 3000, 3999|;
|
||||
foreach var x in test do
|
||||
Println($'{x} - {ToRoman(x)}')
|
||||
end.
|
||||
Loading…
Add table
Add a link
Reference in a new issue