Last active
July 7, 2021 15:50
-
-
Save ymotongpoo/b185aaef169f22af03296046e2571023 to your computer and use it in GitHub Desktop.
コラッツ予想を1千万まで回してみた
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/env/python3 | |
def even(x: int) -> int: | |
return x // 2 | |
def odd(x: int) -> int: | |
return 3 * x + 1 | |
def collatz(memo: set[int], x: int) -> None: | |
original = x | |
while x != 1: | |
if x in memo: | |
break | |
memo.add(x) | |
if x % 2 == 0: | |
x = even(x) | |
else: | |
x = odd(x) | |
print(f"{original} meets collatz problem") | |
def main() -> None: | |
memo = set() | |
i = 0 | |
while i < 10_000_000: | |
collatz(memo, i) | |
i+=1 | |
if __name__ == "__main__": | |
main() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment