first 3 days

This commit is contained in:
2024-12-03 00:39:30 -08:00
commit f2ea7c157e
14 changed files with 3150 additions and 0 deletions

1000
1/1.input Normal file

File diff suppressed because it is too large Load Diff

13
1/1.py Normal file
View File

@@ -0,0 +1,13 @@
def distances(left: list[int], right: list[int]) -> list[int]:
left, right = sorted(left), sorted(right)
return [abs(l-r) for l, r in zip(left, right)]
if __name__ == '__main__':
with open('1.input') as file:
left, right = [], []
for line in file:
l, r = line.split()
l, r = int(l), int(r)
left.append(l)
right.append(r)
print(sum(distances(left, right)))

28
1/2.py Normal file
View File

@@ -0,0 +1,28 @@
def counts(nums: list[int]) -> dict[int, int]:
ret = {}
for n in nums:
if n in ret:
ret[n] += 1
else:
ret[n] = 1
return ret
if __name__ == '__main__':
with open('1.input') as file:
left, right = [], []
for line in file:
l, r = line.split()
l, r = int(l), int(r)
left.append(l)
right.append(r)
# how many times does each number apear in each list
right = counts(right)
score = 0
for n in left:
if n not in right: continue
score += n * right[n]
print(score)

6
1/sample.input Normal file
View File

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