35 lines
		
	
	
		
			879 B
		
	
	
	
		
			Python
		
	
	
		
			Executable File
		
	
	
	
	
			
		
		
	
	
			35 lines
		
	
	
		
			879 B
		
	
	
	
		
			Python
		
	
	
		
			Executable File
		
	
	
	
	
| def read_from_file(file_name):
 | |
|     _file = open(file_name, 'r')
 | |
|     _read = _file.read()
 | |
|     _file.close()
 | |
|     return _read
 | |
| 
 | |
| directions = read_from_file('inputs/day03.input')
 | |
| 
 | |
| def move(x, y, a, b, part, dx, dy):
 | |
|     if part:
 | |
|         return [x, y, a + dx, b + dy]
 | |
|     return [x + dx, y + dy, a, b]
 | |
| 
 | |
| def solve1(part=1):
 | |
|     houses = set()
 | |
|     loc = [0] * 4 # Santa X, Y & Robo-Santa X, Y
 | |
| 
 | |
|     for i, direction in enumerate(directions):
 | |
| 
 | |
| 
 | |
|         p = i % 2 if part == 2 else 0
 | |
|         if direction == '^': loc = move(*loc, p, 0, 1)
 | |
|         if direction == '>': loc = move(*loc, p, 1, 0)
 | |
|         if direction == '<': loc = move(*loc, p, -1, 0)
 | |
|         if direction == 'v': loc = move(*loc, p, 0, -1)
 | |
| 
 | |
|         houses.add(tuple(loc[:2]))
 | |
|         houses.add(tuple(loc[2:]))
 | |
|         
 | |
|     return len(houses)
 | |
| 
 | |
| def solve2(): return solve1(2)
 | |
| 
 | |
| print("Pt1:", solve1())
 | |
| print("Pt2:", solve2()) |