Enable Javascript in your browser and then refresh this page, for a much enhanced experience.
First solution in Clear category for Exploring Wythoff Array by freeman_lex
from math import sqrt, floor
from itertools import count
def wythoff_array(n: int) -> tuple[int, int]:
a, b, phi = 1, 2, (1 + sqrt(5)) / 2
for row in count():
if a == n: return row, 0
c, d = a, b
for col in count(1):
if d == n: return row, col
if d > n: break
c, d = d, c + d
a1 = floor(floor((row + 2) * phi) * phi)
a, b = a1, b + 3 + 2 * (a1 - a != 2)
print("Example:")
print(wythoff_array(21))
# These "asserts" are used for self-checking
assert wythoff_array(21) == (0, 6)
assert wythoff_array(47) == (1, 5)
assert wythoff_array(1042) == (8, 8)
print("The mission is done! Click 'Check Solution' to earn rewards!")
Aug. 7, 2023