Skip to content

Instantly share code, notes, and snippets.

@mandel59
Created September 6, 2021 08:09
Show Gist options
  • Save mandel59/e85224355f63d228992b7665099d0391 to your computer and use it in GitHub Desktop.
Save mandel59/e85224355f63d228992b7665099d0391 to your computer and use it in GitHub Desktop.
コラッツの数列を表示
let i = BigInt(Deno.args[0]);
while (true) {
if (i <= 0n) throw new RangeError();
console.log(String(i));
if (i === 1n) break;
if (i % 2n === 0n) {
i /= 2n;
} else {
i = i * 3n + 1n;
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment