mirror of
https://github.com/ershisan99/advent-of-code.git
synced 2025-12-16 12:32:49 +00:00
2015 day 3 boilerplate
This commit is contained in:
1
2015/day-3/input.txt
Normal file
1
2015/day-3/input.txt
Normal file
File diff suppressed because one or more lines are too long
31
2015/day-3/part-1.py
Normal file
31
2015/day-3/part-1.py
Normal file
@@ -0,0 +1,31 @@
|
||||
import os
|
||||
|
||||
file_path = os.path.join(os.path.dirname(__file__), "./input.txt")
|
||||
# file_path = os.path.join(os.path.dirname(__file__), "./test-input.txt")
|
||||
input = open(file_path).read().strip()
|
||||
|
||||
|
||||
def next_coordinates(current, symbol):
|
||||
if symbol == "^":
|
||||
return (current[0] - 1, current[1])
|
||||
if symbol == "v":
|
||||
return (current[0] + 1, current[1])
|
||||
if symbol == ">":
|
||||
return (current[0], current[1] + 1)
|
||||
if symbol == "<":
|
||||
return (current[0], current[1] - 1)
|
||||
|
||||
|
||||
count = 0
|
||||
visited = {(0, 0)}
|
||||
|
||||
x = 0
|
||||
y = 0
|
||||
for dir in list(input):
|
||||
next = next_coordinates((x, y), dir)
|
||||
x = next[0]
|
||||
y = next[1]
|
||||
visited.add(next)
|
||||
print(next)
|
||||
|
||||
print(len(visited))
|
||||
49
2015/day-3/part-2.py
Normal file
49
2015/day-3/part-2.py
Normal file
@@ -0,0 +1,49 @@
|
||||
import os
|
||||
|
||||
file_path = os.path.join(os.path.dirname(__file__), "./input.txt")
|
||||
# file_path = os.path.join(os.path.dirname(__file__), "./test-input.txt")
|
||||
input = open(file_path).read().strip()
|
||||
|
||||
|
||||
def next_coordinates(current, symbol):
|
||||
if symbol == "^":
|
||||
return (current[0] - 1, current[1])
|
||||
if symbol == "v":
|
||||
return (current[0] + 1, current[1])
|
||||
if symbol == ">":
|
||||
return (current[0], current[1] + 1)
|
||||
if symbol == "<":
|
||||
return (current[0], current[1] - 1)
|
||||
|
||||
|
||||
count = 0
|
||||
|
||||
visited = {(0, 0)}
|
||||
|
||||
santa_queue = []
|
||||
robot_queue = []
|
||||
|
||||
for i, foo in enumerate(list(input)):
|
||||
if i % 2 == 0:
|
||||
santa_queue.append(foo)
|
||||
else:
|
||||
robot_queue.append(foo)
|
||||
|
||||
|
||||
def deliver(queue):
|
||||
x = 0
|
||||
y = 0
|
||||
|
||||
for dir in queue:
|
||||
next = next_coordinates((x, y), dir)
|
||||
visited.add(next)
|
||||
|
||||
x = next[0]
|
||||
y = next[1]
|
||||
|
||||
|
||||
deliver(santa_queue)
|
||||
deliver(robot_queue)
|
||||
|
||||
|
||||
print(len(visited))
|
||||
1
2015/day-3/test-input.txt
Normal file
1
2015/day-3/test-input.txt
Normal file
@@ -0,0 +1 @@
|
||||
^v^v^v^v^v
|
||||
Reference in New Issue
Block a user