solved day1 part2 and day2

This commit is contained in:
0x01FE 2024-12-02 11:26:52 -06:00
parent ca9736d8ec
commit 0e732811ad
4 changed files with 1060 additions and 3 deletions

View File

@ -34,9 +34,12 @@ print(f'Part 1: {total}')
lc = left.copy()
rc = right.copy()
while min(lc) != float('inf'):
total = 0
for i in range(0, len(lc)):
lowest_left = min(lc)
lowest_right = min(rc)
total += lowest_left * rc.count(lowest_left)
lc.pop(lc.index(lowest_left))
print(f'Part 2: {total}')

1000
2024/day2/input.text Normal file

File diff suppressed because it is too large Load Diff

48
2024/day2/main.py Normal file
View File

@ -0,0 +1,48 @@
with open('input.text', 'r') as file:
data: list[str] = file.readlines()
# Parse Input
cases = []
for line in data:
cases.append([int(s) for s in line.split(' ')])
def test_levels(levels: list[int]) -> bool:
negative = levels[0] - levels[1] <= 0
for i in range(0, len(levels) - 1):
change = levels[i] - levels[i + 1]
if (change <= 0) != negative or abs(change) > 3 or change == 0:
return False
return True
# Part 1
total = 0
for levels in cases:
if test_levels(levels):
total += 1
print(f'Part 1: {total}')
# Part 2
total = 0
for levels in cases:
safe = test_levels(levels)
if safe:
total += 1
else:
for i in range(0, len(levels)):
temp_levels = levels.copy()
temp_levels.pop(i)
if test_levels(temp_levels):
total += 1
break
print(f'Part 1: {total}')

6
2024/day2/test.text Normal file
View File

@ -0,0 +1,6 @@
7 6 4 2 1
1 2 7 8 9
9 7 6 2 1
1 3 2 4 5
8 6 4 4 1
1 3 6 7 9