Created
October 16, 2025 15:33
-
-
Save mrphlip/b7ed66548f2091984591742a60bbf5b7 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
| #!/usr/bin/python | |
| from fractions import Fraction | |
| from math import floor | |
| # "time" datatype is [0,1) where 0 represents 0:00:00 and 1 represents 12:00:00 | |
| # "angle" datatype is [0,1) where 1 represents 360 degrees | |
| def str_time(t): | |
| h, m, s = time_to_hands(t) | |
| return f"{floor(h*12)}:{floor(m*60):02d}:{s*60:05.2f}" | |
| def time_to_hands(t): | |
| return t%1, (t*12)%1, (t*720)%1 | |
| def time_to_angles(t): | |
| h, m, s = time_to_hands(t) | |
| return (m-h)%1, (s-h)%1 | |
| def hm_angle_to_times(x): | |
| for i in range(11): | |
| yield (x + i)/11 | |
| def solve(hm_angle, hs_angle): | |
| for t in hm_angle_to_times(hm_angle): | |
| hm_res, hs_res = time_to_angles(t) | |
| assert hm_res == hm_angle | |
| if hs_res == hs_angle: | |
| yield t | |
| def solve_all(angle1, angle2): | |
| yield from solve(angle1, (angle1 + angle2) % 1) | |
| yield from solve((angle1 + angle2) % 1, angle1) | |
| yield from solve(angle2, (-angle1) % 1) | |
| yield from solve((-angle1) % 1, angle2) | |
| yield from solve((-angle2) % 1, (-angle1 - angle2) % 1) | |
| yield from solve((-angle1 - angle2) % 1, (-angle2) % 1) | |
| def main(): | |
| for t in solve_all(Fraction(155,360), Fraction(60,360)): | |
| print(str_time(t)) | |
| if __name__ == "__main__": | |
| main() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment