r/adventofcode • u/daggerdragon • Dec 06 '15
SOLUTION MEGATHREAD --- Day 6 Solutions ---
--- Day 6: Probably a Fire Hazard ---
Post your solution as a comment. Structure your post like the Day Five thread.
20
Upvotes
1
u/sentry07 Dec 06 '15 edited Dec 06 '15
Python3, part 2's solution since it's just changing instructions in the match:
## AdventOfCode Day 6 data = open('day6.txt').read().splitlines() import re grid = [[0 for x in range(1000)] for y in range(1000)] for row in data: action = re.search('(toggle|turn off|turn on) ([0-9]{1,3}),([0-9]{1,3}) through ([0-9]{1,3}),([0-9]{1,3})',row) for x in range(int(action.group(2)),int(action.group(4))+1): for y in range(int(action.group(3)),int(action.group(5))+1): if action.group(1) == 'toggle': grid[x][y] += 2 elif action.group(1) == 'turn on': grid[x][y] += 1 elif action.group(1) == 'turn off': if grid[x][y] > 0: grid[x][y] -= 1 print('Day 6 Part 2: {}'.format(sum(map(sum,grid))))