summary refs log blame commit diff stats
path: root/day3.py
blob: 8d5854eb88d054e2e9ad7db1cbd5822db0be0ca9 (plain) (tree)




















































                                         
#!/usr/bin/env python

from collections import defaultdict
with open('day3.txt') as data:
    directions = data.read().strip()
# part 1
x, y = 0, 0
houses = defaultdict(int)
houses[(x, y)] = 1
for direction in directions:
    match direction:
        case '^':
            y += 1
        case 'v':
            y -= 1
        case '>':
            x += 1
        case '<':
            x -= 1
    houses[(x, y)] += 1

print(len(houses))

# part 2
santaX, santaY, roboX, roboY = 0, 0, 0, 0
houses = defaultdict(int)
houses[(0, 0)] = 2
isSanta = True
for direction in directions:
    if isSanta:
        match direction:
            case '^':
                santaY += 1
            case 'v':
                santaY -= 1
            case '>':
                santaX += 1
            case '<':
                santaX -= 1
        houses[(santaX, santaY)] += 1
    else:
        match direction:
            case '^':
                roboY += 1
            case 'v':
                roboY -= 1
            case '>':
                roboX += 1
            case '<':
                roboX -= 1
        houses[(roboX, roboY)] += 1
    isSanta = not isSanta
print(len(houses))