Completed Day 1, parts 1 and 2.
This commit is contained in:
parent
9b9d4abeaf
commit
ec852a996a
2 changed files with 4098 additions and 0 deletions
4036
2025/Day 1/input.txt
Normal file
4036
2025/Day 1/input.txt
Normal file
File diff suppressed because it is too large
Load diff
62
2025/Day 1/main.py
Normal file
62
2025/Day 1/main.py
Normal file
|
|
@ -0,0 +1,62 @@
|
||||||
|
import os
|
||||||
|
|
||||||
|
def main():
|
||||||
|
#Starting value.
|
||||||
|
current_point = 50
|
||||||
|
part_one_zeroes = 0
|
||||||
|
part_two_zeroes = 0
|
||||||
|
|
||||||
|
#Read file into content variable, split by endline characters.
|
||||||
|
base_dir = os.path.dirname(__file__)
|
||||||
|
file_path = os.path.join(base_dir, "input.txt")
|
||||||
|
with open(file_path, 'r') as f:
|
||||||
|
content = f.read().split('\n')
|
||||||
|
|
||||||
|
#For each line in our input text, turn the dial.
|
||||||
|
for x in content:
|
||||||
|
current_point = part_one(x, current_point)
|
||||||
|
if current_point == 0:
|
||||||
|
part_one_zeroes += 1
|
||||||
|
|
||||||
|
print("Part 1 Answer: " + str(part_one_zeroes))
|
||||||
|
|
||||||
|
current_point = 50
|
||||||
|
|
||||||
|
for x in content:
|
||||||
|
current_point, hits = part_two(x, current_point)
|
||||||
|
part_two_zeroes += hits
|
||||||
|
|
||||||
|
print("Part 1 Answer: " + str(part_two_zeroes))
|
||||||
|
|
||||||
|
def part_one(turn_input, current_point):
|
||||||
|
direction = turn_input[0]
|
||||||
|
amount = int(turn_input[1:])
|
||||||
|
|
||||||
|
if direction == 'L':
|
||||||
|
current_point = (current_point - amount) % 100
|
||||||
|
|
||||||
|
if direction == 'R':
|
||||||
|
current_point = (current_point + amount) % 100
|
||||||
|
|
||||||
|
return current_point
|
||||||
|
|
||||||
|
def part_two(turn_input, current_point):
|
||||||
|
direction = turn_input[0]
|
||||||
|
amount = int(turn_input[1:])
|
||||||
|
|
||||||
|
zero_hits = 0
|
||||||
|
|
||||||
|
for _ in range(amount):
|
||||||
|
if direction == 'L':
|
||||||
|
current_point = (current_point - 1) % 100
|
||||||
|
|
||||||
|
if direction == 'R':
|
||||||
|
current_point = (current_point + 1) % 100
|
||||||
|
|
||||||
|
if current_point == 0:
|
||||||
|
zero_hits += 1
|
||||||
|
|
||||||
|
return current_point, zero_hits
|
||||||
|
|
||||||
|
if __name__ == "__main__":
|
||||||
|
main()
|
||||||
Loading…
Add table
Reference in a new issue