Created
June 16, 2025 23:18
-
-
Save Mercerenies/46882f83800de56bbe1f16aeae26477c 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
| # Pi calculation: https://github.com/TianmuTNT/PiDigits | |
| # Depends on `python3 -m pip install rubik-cube` | |
| from typing import Iterable | |
| from rubik.cube import Cube | |
| def pi_digits() -> Iterable[int]: | |
| q, r, t, i = 1, 180, 60, 2 | |
| while True: | |
| u = 3 * (3 * i + 1) * (3 * i + 2) | |
| y = (q * (27 * i - 12) + 5 * r) // (5 * t) | |
| yield y | |
| q, r, t, i = 10 * q * i * (2 * i - 1), 10 * u * (q * (5 * i - 2) + r - y * t), t * u, i + 1 | |
| def digit_to_move(n: int): | |
| match n: | |
| case 1: | |
| return Cube.U | |
| case 2: | |
| return Cube.D | |
| case 3: | |
| return Cube.L | |
| case 4: | |
| return Cube.R | |
| case 5: | |
| return Cube.F | |
| case 6: | |
| return Cube.B | |
| case 7: | |
| return Cube.Ui | |
| case 8: | |
| return Cube.Di | |
| case 9: | |
| return Cube.Li | |
| case 0: | |
| return Cube.Ri | |
| c = Cube("OOOOOOOOOYYYWWWGGGBBBYYYWWWGGGBBBYYYWWWGGGBBBRRRRRRRRR") | |
| n = 0 | |
| for d in pi_digits(): | |
| digit_to_move(d)(c) | |
| if c.is_solved(): | |
| print(n) | |
| exit(0) | |
| n += 1 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment