define CTZ(a * b^c, b) = c
; where GCD(a, b^c) = 1
following is in binary:
0.0101 -> -10
101 * 10^-100 -> -100 (contradiction)
'use strict' | |
const | |
/**Python's `bool` ported to JS (doesn't work quite the same) */ | |
bool = x => x == true, | |
logicXOR = (a, b) => !a != !b ? a : b, | |
logicXNOR = (a, b) => !a == !b ? a : b, | |
logicXORalt = (a, b) => !a != !b ? a || b : a && b, | |
logicXNORalt = (a, b) => !a == !b ? a || b : a && b, |
'use strict' | |
const assert = function(bool, msg) {if (!bool) throw new Error(msg)} | |
let dominance = true | |
assert(dominance, 'dominance not asserted') | |
//I'm so based that I purposefully ignored `console.assert` | |
console.log('dominance successfully asserted lol') | |
dominance = false //dominance doesn't last forever |
'use strict' | |
const {trunc} = Math | |
/** mantissa bit-length of IEEE 754 "binary64" double-float */ | |
const M_LEN = 52n | |
/** | |
Bitcast. Keep in-memory bits the same, but change the type. | |
@param {number} f | |
*/ |
export const count_values = <T,>(it: Iterable<T>) => { | |
const counts: Map<T, bigint> = new Map | |
for (const x of it) | |
counts.set(x, (counts.get(x) ?? 0n) + 1n) | |
return counts | |
} |
'use strict' | |
/** | |
Calculates the minimum int-num of payload bits needed to encode the given data. | |
It does so with a simple algorithm: | |
- `boolean`: `1` (duh). | |
- `bigint`: bitcount - Most Significant One + sign-bit (only if negative), `sizeof 0n == 0`. | |
- `number`: Same as `bigint` (MSO is the implicit-bit) + bits after radix-point (not including the point itself). | |
- `string`: Number of code-points multiplied by the bits-per-char. BPC is calculated from min-charset-size. |
'use strict' | |
/** | |
@param {number | bigint | Iterable} a | |
@param {number | bigint | Iterable} b | |
@license Unlicense | |
*/ | |
const Hamming_dist = (a, b) => { | |
const get_chars = x => { | |
const t = typeof x | |
return 'number' == t || 'bigint' == t |
'use strict' | |
/** | |
@param {unknown} struct | |
@param {Iterable<unknown>} keys | |
*/ | |
const get_in = (struct, keys) => { | |
for (const k of keys) | |
struct = | |
struct instanceof Map || |
// Prime | |
foo {// 0 isn't prime, but we need it | |
bar {// 1 gets totally ignored lol | |
baz { | |
quz { | |
quux { | |
corge { | |
grault { | |
garply { | |
// waldoo |
Because_the_essence_of_programming_is_repeating = "Because the essence of programming is repeating".split() | |
while True: | |
for word in Because_the_essence_of_programming_is_repeating: | |
for _ in range(len(Because_the_essence_of_programming_is_repeating)): | |
print(word) | |
# LICENSE: https://unlicense.org |
define CTZ(a * b^c, b) = c
; where GCD(a, b^c) = 1
following is in binary:
0.0101 -> -10
101 * 10^-100 -> -100 (contradiction)