2025 lets goooo
This commit is contained in:
@@ -0,0 +1,68 @@
|
||||
testing = False
|
||||
|
||||
if not testing:
|
||||
with open(r"2025/01/input.txt", "r") as file:
|
||||
input = file.read()
|
||||
else:
|
||||
input = '''L68
|
||||
L30
|
||||
R48
|
||||
L5
|
||||
R60
|
||||
L55
|
||||
L1
|
||||
L99
|
||||
R14
|
||||
L82'''
|
||||
answer:int = 0
|
||||
TEST_EXPECTED_ANSWER:int = 3
|
||||
|
||||
# make a list to simulate dial?
|
||||
dial = [i for i in range(100)]
|
||||
#print(dial)
|
||||
|
||||
direction = {
|
||||
'L':'-=',
|
||||
'R':'+='
|
||||
}
|
||||
|
||||
position:int = 50
|
||||
|
||||
def perform_operation(value, operator, operand):
|
||||
if operator == "+=":
|
||||
return value + operand
|
||||
elif operator == "-=":
|
||||
return value - operand
|
||||
else:
|
||||
raise ValueError("Unsupported operator")
|
||||
|
||||
def move_dial(position, movement):
|
||||
#print(movement)
|
||||
direction_to_move = movement[0]
|
||||
amount_to_move = movement[1:]
|
||||
#print(direction_to_move)
|
||||
#print(amount_to_move)
|
||||
decide = direction[direction_to_move]
|
||||
#print(decide)
|
||||
new_position = perform_operation(int(position), decide, int(amount_to_move))
|
||||
return new_position % 100
|
||||
|
||||
win_counter:int = 0
|
||||
for step in input.split('\n'):
|
||||
#print(position)
|
||||
position = move_dial(position, step)
|
||||
#print(position)
|
||||
#print(dial[position])
|
||||
if dial[position] == 0:
|
||||
win_counter += 1
|
||||
|
||||
answer = win_counter
|
||||
|
||||
if testing:
|
||||
if answer == TEST_EXPECTED_ANSWER:
|
||||
print('test successful')
|
||||
else:
|
||||
print(f'wrong... expected {TEST_EXPECTED_ANSWER} received {answer}')
|
||||
else:
|
||||
print(answer)
|
||||
|
||||
@@ -0,0 +1,67 @@
|
||||
testing = False
|
||||
|
||||
if not testing:
|
||||
with open(r"2025/01/input.txt", "r") as file:
|
||||
input = file.read()
|
||||
else:
|
||||
input = '''L68
|
||||
L30
|
||||
R48
|
||||
L5
|
||||
R60
|
||||
L55
|
||||
L1
|
||||
L99
|
||||
R14
|
||||
L82'''
|
||||
|
||||
answer:int = 0
|
||||
TEST_EXPECTED_ANSWER:int = 6
|
||||
|
||||
# make a list to simulate dial?
|
||||
dial = [i for i in range(100)]
|
||||
|
||||
position:int = 50
|
||||
zero_count: int = 0
|
||||
|
||||
def move_dial_with_zero_count(current_position, movement):
|
||||
direction_to_move = movement[0]
|
||||
amount_to_move = int(movement[1:])
|
||||
|
||||
# Determine the direction
|
||||
if direction_to_move == 'L':
|
||||
step = -1
|
||||
elif direction_to_move == 'R':
|
||||
step = 1
|
||||
else:
|
||||
raise ValueError("Invalid direction")
|
||||
|
||||
# Count how many times we hit 0 during this rotation
|
||||
count = 0
|
||||
current = current_position
|
||||
|
||||
# Go through each step of the rotation
|
||||
for _ in range(amount_to_move):
|
||||
current = (current + step) % 100
|
||||
if current == 0:
|
||||
count += 1
|
||||
|
||||
return current, count
|
||||
|
||||
# Process each step
|
||||
for step in input.strip().split('\n'):
|
||||
#print(f"Before: {position}")
|
||||
position, zero_count_increment = move_dial_with_zero_count(position, step)
|
||||
zero_count += zero_count_increment
|
||||
#print(f"After: {position} (zero hits: {zero_count_increment})")
|
||||
|
||||
answer = zero_count
|
||||
|
||||
if testing:
|
||||
if answer == TEST_EXPECTED_ANSWER:
|
||||
print('test successful')
|
||||
else:
|
||||
print(f'wrong... expected {TEST_EXPECTED_ANSWER} received {answer}')
|
||||
else:
|
||||
print(answer)
|
||||
|
||||
Reference in New Issue
Block a user