Initial data commit

This commit is contained in:
Ingy döt Net 2023-07-01 11:58:00 -04:00
parent 72d218235f
commit f23f22d71c
199087 changed files with 3378941 additions and 0 deletions

View file

@ -0,0 +1,6 @@
function sumDigits(n) {
n += ''
for (var s=0, i=0, e=n.length; i<e; i+=1) s+=parseInt(n.charAt(i),36)
return s
}
for (var n of [1, 12345, 0xfe, 'fe', 'f0e', '999ABCXYZ']) document.write(n, ' sum to ', sumDigits(n), '<br>')

View file

@ -0,0 +1,27 @@
(function () {
'use strict';
// digitsSummed :: (Int | String) -> Int
function digitsSummed(number) {
// 10 digits + 26 alphabetics
// give us glyphs for up to base 36
var intMaxBase = 36;
return number
.toString()
.split('')
.reduce(function (a, digit) {
return a + parseInt(digit, intMaxBase);
}, 0);
}
// TEST
return [1, 12345, 0xfe, 'fe', 'f0e', '999ABCXYZ']
.map(function (x) {
return x + ' -> ' + digitsSummed(x);
})
.join('\n');
})();

View file

@ -0,0 +1,27 @@
(() => {
"use strict";
// -------------- INTEGER DIGITS SUMMED --------------
// digitsSummed :: (Int | String) -> Int
const digitsSummed = number => {
// 10 digits + 26 alphabetics
// give us glyphs for up to base 36
const intMaxBase = 36;
return `${number}`
.split("")
.reduce(
(sofar, digit) => sofar + parseInt(
digit, intMaxBase
),
0
);
};
// ---------------------- TEST -----------------------
return [1, 12345, 0xfe, "fe", "f0e", "999ABCXYZ"]
.map((x) => `${x} -> ${digitsSummed(x)}`)
.join("\n");
})();