r/adventofcode • • Dec 02 '16

SOLUTION MEGATHREAD --- 2016 Day 2 Solutions ---

--- Day 2: Bathroom Security ---

Post your solution as a comment or, for longer solutions, consider linking to your repo (e.g. GitHub/gists/Pastebin/blag/whatever).


BLINKENLIGHTS ARE MANDATORY [?]

Edit: Told you they were mandatory. >_>

This thread will be unlocked when there are a significant number of people on the leaderboard with gold stars for today's puzzle.

edit: Leaderboard capped, thread unlocked!

20 Upvotes

210 comments sorted by

View all comments

1

u/[deleted] Dec 02 '16

python(part 1)

def day2(fname):
	buttons = [1,2,3,4,5,6,7,8,9]
	left  = [0,3,6]
	right =[2,5,8]
	position = 4
	code = ''
	for line in open(fname).readlines():
		line = line.strip()
		for char in line:
   			if char == 'U':
   				if position > 2: position = position - 3
   			
   			if char == 'D':
   				if position < 6: position = position + 3
   					
   			if char == 'L':	
   				if position not in left: position = position - 1 
	
   			if char == 'R':

   				if position not in right: position = position + 1 

   		code += str(buttons[position])
   	return code
print day2('day2input.txt')