divide each digit by 2 starting from the MSD using int div, if you have remainder it means you have to add 5 to the next digit AFTER dividing it by 2.
Examples:
- 1687
- 1/2 = 0, carry 5 because odd
- 6/2 = 3, 3+5 = 8
- 8/2 = 4
- 7/2 = 3, carry 5
divide each digit by 2 starting from the MSD using int div, if you have remainder it means you have to add 5 to the next digit AFTER dividing it by 2.
Examples:
Use binary 111110000 as example...
Add up the powers of 2, then use bit shift/multiplication/addition identities to simplify the sum of all divisors. You'll get the original Perfect number
Divisors: 1, 10, 100, 1000, 10000, 11111, 111110, 1111100, 11111000
(WIP) I'm planning on improving this, then I'll make a YT video or a GHP-blog/post about it
addEventListener('keydown', k => console.table(k.keyCode, k.code, k.key, String.fromCharCode(k.keyCode))) |
from typing import Final, TypeVar | |
_T = TypeVar('_T') | |
# is there some way to avoid union type? | |
def slice_by_search(inp: (list | tuple)[_T], start: _T, end: _T): | |
'''LICENSE: Unlicense''' | |
i: Final = 1 + inp.index(start) | |
return inp[i: inp.index(end, i + 1)] |
from typing import Final | |
BYTES_PER_PIXEL: Final = 3 # 24bit color, 8 per channel | |
def decoded_video_size(*, w: Final[int], h: Final[int], s: Final[float], fps: Final[float]): | |
pixels_per_frame: Final = w * h # px/px^2 = 1/px = px^-1 | |
total_frames: Final = fps * s # px^2/s * s = px^2 | |
total_pixels: Final = pixels_per_frame * total_frames # px^-1 * px^2 = px^2 / px^1 = px | |
total_bytes: Final = total_pixels * BYTES_PER_PIXEL # px * B/px = B | |
return total_bytes |
This website seems to have a SQL-injection vulnerability, at the password reset and login sections.
I noticed this when using a password with random symbols.
I posted this gist to remind myself to tell them to fix it, and to notify everyone else about this
/// # Greatest Common Divisor / Highest Common Factor | |
/// between `a` & `b`, | |
/// using https://en.wikipedia.org/wiki/Euclidean_algorithm. | |
/// | |
/// It only supports unsigneds, | |
/// because it's easier to avoid bugs, | |
/// and allows wider input ranges. | |
const fn gcd(mut a: u128, mut b: u128) -> u128 { | |
// rustc doesn't have TCO, so recursion is not an option | |
while b != 0 { |
from typing import Final, TypeVar | |
T = TypeVar('T') | |
def remove_dupes(inp: list[T], keep_last: bool = False) -> list[T]: | |
''' | |
creates a list from input, | |
such that all ocurrences (but 1) of each value are removed | |
(order is preserved). |
#!/usr/bin/env python3 | |
from typing import Final | |
from string import digits, ascii_letters | |
from sys import argv | |
FULL_CHARSET: Final = digits + ascii_letters | |
def to_radix(n: int, charset='0123456789', lil_endian=False): |
'use strict' | |
const alt_bit = function*() { | |
let n = 0n | |
let even = true | |
while (true) { | |
yield n | |
n <<= 1n | |
if (even) n |= 1n | |
even = !even |