Enable Javascript in your browser and then refresh this page, for a much enhanced experience.
Recursion in the complex field solution in Clear category for Ulam-Warburton Automaton Hex by Tinus_Trotyl
def automaton(step: int) -> int:
from cmath import isclose, rect, pi
def encounter(item, container): # check if item is encountered in the container
for i in container: # whitin a centain tolerance
if isclose(item, i, abs_tol=tolerance): return 1
return 0
def stepper(lastpoints, step):
nonlocal occupied
if step > 0: # if not done
newpoints = [] # prepare for a list of new points
for lastadd in lastpoints: # for all by the last time added points
for alpha in sixways: # go for 6 directions
candidate = lastadd + rect(1, alpha) # make a candidate point
if not encounter(candidate, occupied): # and when not engaged allready
count = 0 # count for the 6 possible neighbors
for betha in sixways:
neighbor = candidate + rect(1, betha)
count += encounter(neighbor, occupied)
if count == 1: # and when there only 1 in the surrounding
newpoints.append(candidate) # add the new point
occupied += newpoints
stepper(newpoints, step - 1) # and go for the next step
return
tolerance = 0.000001 # goniometric tolerance = 1/1000000
sixways = [d * pi / 3 for d in range(6)] # go in six ways (6 x 60 degrees)
occupied = [0] # first complex number = 0
stepper(occupied, step - 1) # first call
return len(occupied) # return the number of complex numbers
Feb. 16, 2023
Comments: