redid my day 1 to not suck
This commit is contained in:
parent
6f90d90356
commit
f7f8f632bd
@ -14,32 +14,19 @@ for line in data:
|
||||
|
||||
# Part 1
|
||||
|
||||
lc = left.copy()
|
||||
rc = right.copy()
|
||||
left.sort()
|
||||
right.sort()
|
||||
|
||||
total = 0
|
||||
while min(lc) != float('inf'):
|
||||
lowest_left = min(lc)
|
||||
lowest_right = min(rc)
|
||||
|
||||
total += abs(lowest_left - lowest_right)
|
||||
|
||||
lc[lc.index(lowest_left)] = float('inf')
|
||||
rc[rc.index(lowest_right)] = float('inf')
|
||||
for i, n in enumerate(left):
|
||||
total += abs(n - right[i])
|
||||
|
||||
print(f'Part 1: {total}')
|
||||
|
||||
# Part 2
|
||||
|
||||
lc = left.copy()
|
||||
rc = right.copy()
|
||||
|
||||
total = 0
|
||||
for i in range(0, len(lc)):
|
||||
lowest_left = min(lc)
|
||||
|
||||
total += lowest_left * rc.count(lowest_left)
|
||||
|
||||
lc.pop(lc.index(lowest_left))
|
||||
for i, n in enumerate(left):
|
||||
total += n * right.count(n)
|
||||
|
||||
print(f'Part 2: {total}')
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user