Created
December 30, 2025 10:18
-
-
Save todashuta/ac452a8944d4a8a2a883ea87485f8f46 to your computer and use it in GitHub Desktop.
コラッツの問題の数列ジェネレーター
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
| def collatz_gen(n): | |
| yield n | |
| while n > 1: | |
| if n % 2 == 0: | |
| n = n // 2 | |
| else: | |
| n = n * 3 + 1 | |
| yield n | |
| #print(list(collatz_gen(6)) == [6, 3, 10, 5, 16, 8, 4, 2, 1]) | |
| for i in collatz_gen(6): | |
| print(i) |
Author
todashuta
commented
Dec 30, 2025
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment