Enable Javascript in your browser and then refresh this page, for a much enhanced experience.
itertools solution in Creative category for Hexagon Spiral by gyahun_dash
from itertools import chain, cycle, islice, repeat
units = (2, 0), (1, 1), (-1, 1), (-2, 0), (-1, -1), (1, -1)
def hex_spiral(*pair):
directions = enumerate(cycle(units))
spiral = (repeat(u, i // 6 + (u != (1, 1))) for i, u in directions)
segment = islice(chain.from_iterable(spiral), *sorted(n - 1 for n in pair))
latitude, longitude = map(abs, map(sum, zip(*segment)))
return max(0, latitude - longitude) // 2 + longitude
Nov. 11, 2014
Comments: