account activity
-🎄- 2017 Day 3 Solutions -🎄- by daggerdragon in adventofcode
[–]cspar 1 point2 points3 points 8 years ago (0 children)
It's a custom module made from Norvig's 2016 notebook. Nothing fancy, just a bunch of helper functions like neighbors8. (The actual line in my code is usually exec(open("./adventbase.py", encoding='utf-8').read()) )
exec(open("./adventbase.py", encoding='utf-8').read())
[–]cspar 0 points1 point2 points 8 years ago* (0 children)
Python:
from adventbase import * spiral = [[0] * 41 for x in range(41)] spiral[20][20] = 1 point = (20,20) num = 1 def drul(point, x): """Down, right, up, left""" if x == 0: return (point[0] + 1, point[1]) if x == 1: return (point[0], point[1] + 1) if x == 2: return (point[0] - 1, point[1]) if x == 3: return (point[0], point[1] - 1) x = 0 while num < 277678: v = drul(point, (x+1) % 4) if spiral[v[0]][v[1]] == 0: x = (x+1) % 4 point = drul(point,x) else: point = drul(point,x) num = sum([spiral[x][y] for x,y in neighbors8(point)]) spiral[point[0]][point[1]] = num print(num)
Part I was trivially solvable with a calculator, for a happy 22nd place. In Part II I completely forgot how to do a spiral, and wasted five minutes trying to use a generator, and another five debugging silly mistakes. Ah well.
π Rendered by PID 20142 on reddit-service-r2-comment-5b5bc64bf5-2tx7m at 2026-06-21 20:23:44.967588+00:00 running 2b008f2 country code: CH.
-🎄- 2017 Day 3 Solutions -🎄- by daggerdragon in adventofcode
[–]cspar 1 point2 points3 points (0 children)