Skip to content

Instantly share code, notes, and snippets.

@VictorTaelin
Created February 23, 2026 12:49
Show Gist options
  • Select an option

  • Save VictorTaelin/ab95a01b1622b1fcfea09dcc4c1a9696 to your computer and use it in GitHub Desktop.

Select an option

Save VictorTaelin/ab95a01b1622b1fcfea09dcc4c1a9696 to your computer and use it in GitHub Desktop.
bunjs - 15x slower
export const Nat = null;
export const List = null;
export const Char = null;
export const String = null;
export function $steps(n, acc) {
while (true) {
if (((n >>> 0) === (1 >>> 0)) ? 1 : 0) {
return acc;
}
const rem = (2 === 0 ? 0 : ((n >>> 0) % (2 >>> 0)) >>> 0);
if (((rem >>> 0) === (0 >>> 0)) ? 1 : 0) {
n = (2 === 0 ? 0 : ((n >>> 0) / (2 >>> 0)) >>> 0);
acc = ((acc + 1) >>> 0);
continue;
} else {
n = ((Math.imul(n, 3) >>> 0) + 1) >>> 0;
acc = ((acc + 1) >>> 0);
continue;
}
}
}
export const steps = () => (a0) => (a1) => $steps(a0, a1);
export function $total(n, acc) {
while (true) {
if (((n >>> 0) === (0 >>> 0)) ? 1 : 0) {
return acc;
}
const k = n;
n = ((k - 1) >>> 0);
acc = ((acc + $steps(k, 0)) >>> 0);
continue;
}
}
export const total = () => (a0) => (a1) => $total(a0, a1);
export function $main() {
return $total(8000000, 0);
}
export const main = () => $main();
console.log(JSON.stringify(main()));
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment