aoc

My solutions for the Advent of Code
git clone https://git.tronto.net/aoc
Download | Log | Files | Refs | README

b.py (322B)


      1 import fileinput
      2 
      3 with fileinput.input() as lines:
      4 	rows = [line[:-1] for line in lines]
      5 	pos = {rows[0].find('S'): 1}
      6 
      7 for row in rows[1:]:
      8 	newpos = {}
      9 	for p, w in pos.items():
     10 		for pp in [p-1,p+1] if row[p] == '^' else [p]:
     11 			t = newpos.get(pp, 0)
     12 			newpos[pp] = t + w
     13 	pos = dict(newpos)
     14 
     15 print(sum(pos.values()))