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,9 @@
function toBinary(number) {
return new Number(number)
.toString(2);
}
var demoValues = [5, 50, 9000];
for (var i = 0; i < demoValues.length; ++i) {
// alert() in a browser, wscript.echo in WSH, etc.
print(toBinary(demoValues[i]));
}

View file

@ -0,0 +1,24 @@
(() => {
"use strict";
// ------------------ BINARY DIGITS ------------------
// showBinary :: Int -> String
const showBinary = n =>
showIntAtBase_(2)(n);
// showIntAtBase_ :: // Int -> Int -> String
const showIntAtBase_ = base =>
n => n.toString(base);
// ---------------------- TEST -----------------------
const main = () => [5, 50, 9000]
.map(n => `${n} -> ${showBinary(n)}`)
.join("\n");
// MAIN ---
return main();
})();

View file

@ -0,0 +1,56 @@
(() => {
"use strict";
// -------------- DIGITS FOR GIVEN BASE --------------
// showIntAtBase :: Int -> (Int -> Char) ->
// Int -> String -> String
const showIntAtBase = base =>
// A string representation of n, in the given base,
// using a supplied (Int -> Char) function for digits,
// and a supplied suffix string.
toChr => n => rs => {
const go = ([x, d], r) => {
const r_ = toChr(d) + r;
return 0 !== x ? (
go(quotRem(x)(base), r_)
) : r_;
};
const e = "error: showIntAtBase applied to";
return 1 >= base ? (
`${e} unsupported base`
) : 0 > n ? (
`${e} negative number`
) : go(quotRem(n)(base), rs);
};
// ---------------------- TEST -----------------------
const main = () => {
// showHanBinary :: Int -> String
const showHanBinary = n =>
showIntAtBase(2)(
x => "〇一" [x]
)(n)("");
return [5, 50, 9000]
.map(
n => `${n} -> ${showHanBinary(n)}`
)
.join("\n");
};
// --------------------- GENERIC ---------------------
// quotRem :: Integral a => a -> a -> (a, a)
const quotRem = m =>
// The quotient, tupled with the remainder.
n => [Math.trunc(m / n), m % n];
// MAIN ---
return main();
})();