Data commit

This commit is contained in:
Ingy döt Net 2023-07-01 11:58:00 -04:00
parent 7387c8f97b
commit cb5bb5e222
199093 changed files with 3378972 additions and 0 deletions

View file

@ -0,0 +1,27 @@
module BinaryDigits {
@Inject Console console;
void run() {
Int64[] tests = [0, 1, 5, 50, 9000];
Int longestInt = tests.map(n -> n.estimateStringLength())
.reduce(0, (max, len) -> max.notLessThan(len));
Int longestBin = tests.map(n -> (64-n.leadingZeroCount).notLessThan(1))
.reduce(0, (max, len) -> max.maxOf(len));
function String(Int64) num = n -> {
Int indent = longestInt - n.estimateStringLength();
return $"{' ' * indent}{n}";
};
function String(Int64) bin = n -> {
Int index = n.leadingZeroCount.minOf(63);
Int indent = index - (64 - longestBin);
val bits = n.toBitArray()[index ..< 64];
return $"{' ' * indent}{bits.toString().substring(2)}";
};
for (Int64 test : tests) {
console.print($"The decimal value {num(test)} should produce an output of {bin(test)}");
}
}
}