initial commit, day 10
This commit is contained in:
40
01b.py
Executable file
40
01b.py
Executable file
@@ -0,0 +1,40 @@
|
||||
#!/usr/bin/python
|
||||
|
||||
with open('01a.txt') as f:
|
||||
text = f.read().strip()
|
||||
|
||||
lines = text.split('\n')
|
||||
|
||||
a = [None] * len(lines)
|
||||
b = [None] * len(lines)
|
||||
|
||||
for i in range(len(lines)):
|
||||
spl = lines[i].split(' ', maxsplit=1)
|
||||
a[i] = int(spl[0].strip())
|
||||
b[i] = int(spl[1].strip())
|
||||
|
||||
a.sort()
|
||||
b.sort()
|
||||
|
||||
total = 0
|
||||
|
||||
# for x, y in zip(a, b):
|
||||
# total += abs(x - y)
|
||||
|
||||
# print(total)
|
||||
|
||||
i_a = 0
|
||||
i_b = 0
|
||||
|
||||
while i_a < len(lines) and i_b < len(lines):
|
||||
x_a = a[i_a]
|
||||
x_b = b[i_b]
|
||||
if x_a == x_b:
|
||||
total += x_b
|
||||
i_b += 1
|
||||
elif x_a < x_b:
|
||||
i_a += 1
|
||||
else:
|
||||
i_b += 1
|
||||
|
||||
print(total)
|
||||
Reference in New Issue
Block a user