mirror of
https://github.com/Xevion/advent-of-code.git
synced 2025-12-06 19:14:19 -06:00
2015 day 3 part 1 & 2
This commit is contained in:
28
2015/day-3/python/part_1.py
Normal file
28
2015/day-3/python/part_1.py
Normal file
@@ -0,0 +1,28 @@
|
||||
import os
|
||||
import sys
|
||||
|
||||
from collections import defaultdict
|
||||
|
||||
PATH = os.path.join(sys.path[0], '..', 'input')
|
||||
DATA = open(PATH).read()
|
||||
|
||||
pos = [0, 0]
|
||||
|
||||
def UP():
|
||||
pos[1] += 1
|
||||
|
||||
def DOWN():
|
||||
pos[1] -= 1
|
||||
def RIGHT():
|
||||
pos[0] += 1
|
||||
def LEFT():
|
||||
pos[0] -= 1
|
||||
|
||||
DIRECTIONS = {'^' : UP, '<' : LEFT, '>' : RIGHT, 'v' : DOWN}
|
||||
|
||||
houses = defaultdict(int)
|
||||
for direction in DATA:
|
||||
DIRECTIONS[direction]()
|
||||
houses[f'{pos[0]},{pos[1]}'] += 1
|
||||
|
||||
print(len(list(v for v in houses.values() if v >= 1)))
|
||||
Reference in New Issue
Block a user