September Morn Update
This commit is contained in:
parent
4e2d22a71d
commit
aac6731f2c
6856 changed files with 141342 additions and 21127 deletions
|
|
@ -5,7 +5,7 @@
|
|||
const roman = n =>
|
||||
concat(snd(mapAccumL((balance, [k, v]) => {
|
||||
const [q, r] = quotRem(balance, v);
|
||||
return [r, q > 0 ? concat(replicate(q, k)) : ''];
|
||||
return [r, q > 0 ? k.repeat(q) : ''];
|
||||
}, n, [
|
||||
['M', 1000],
|
||||
['CM', 900],
|
||||
|
|
@ -49,12 +49,6 @@
|
|||
// quotRem :: Integral a => a -> a -> (a, a)
|
||||
const quotRem = (m, n) => [Math.floor(m / n), m % n];
|
||||
|
||||
// replicate :: Int -> a -> [a]
|
||||
const replicate = (n, x) =>
|
||||
Array.from({
|
||||
length: n
|
||||
}, () => x);
|
||||
|
||||
// show :: a -> String
|
||||
const show = (...x) =>
|
||||
JSON.stringify.apply(
|
||||
|
|
|
|||
|
|
@ -0,0 +1,18 @@
|
|||
function toRoman(num) {
|
||||
return 'I'
|
||||
.repeat(num)
|
||||
.replace(/IIIII/g, 'V')
|
||||
.replace(/VV/g, 'X')
|
||||
.replace(/XXXXX/g, 'L')
|
||||
.replace(/LL/g, 'C')
|
||||
.replace(/CCCCC/g, 'D')
|
||||
.replace(/DD/g, 'M')
|
||||
.replace(/VIIII/g, 'IX')
|
||||
.replace(/LXXXX/g, 'XC')
|
||||
.replace(/XXXX/g, 'XL')
|
||||
.replace(/DCCCC/g, 'CM')
|
||||
.replace(/CCCC/g, 'CD')
|
||||
.replace(/IIII/g, 'IV');
|
||||
}
|
||||
|
||||
console.log(toRoman(1666));
|
||||
|
|
@ -0,0 +1 @@
|
|||
MDCLXVI
|
||||
Loading…
Add table
Add a link
Reference in a new issue