Compare commits
No commits in common. 'a7aa40381e3a70279d4d5074d62aaec350178be3' and '0fe4c0d032268a4e75d41020dbb299f064321869' have entirely different histories.
a7aa40381e
...
0fe4c0d032
3 changed files with 1 additions and 71 deletions
@ -1,53 +0,0 @@ |
|||||||
input = [[i for i in l] for l in open("input.txt", 'r').read().splitlines()] |
|
||||||
traversed = [] |
|
||||||
|
|
||||||
whereami = (0, 0) |
|
||||||
next = (0,0) |
|
||||||
|
|
||||||
|
|
||||||
for x in range(len(input)): |
|
||||||
for y in range(len(input[x])): |
|
||||||
if input[x][y] == 'S': |
|
||||||
whereami = (x, y) |
|
||||||
if x > 0 and input[x-1][y] in ['|', '7', 'F']: |
|
||||||
next = (x-1, y) |
|
||||||
break |
|
||||||
if x+1 < len(input) and input[x+1][y] in ['|', 'L', 'J']: |
|
||||||
next = (x+1, y) |
|
||||||
break |
|
||||||
if y > 0 and input[x][y-1] in ['-', 'L', 'F']: |
|
||||||
next = (x, y-1) |
|
||||||
break |
|
||||||
if y+1 < len(input[0]) and input[x][y+1] in ['-', '7', 'J']: |
|
||||||
next = (x, y+1) |
|
||||||
break |
|
||||||
|
|
||||||
while True: |
|
||||||
x, y = next |
|
||||||
traversed.append((x,y)) |
|
||||||
if input[x][y] == 'F': |
|
||||||
next = (x+1, y) if whereami == (x,y+1) else (x, y+1) |
|
||||||
elif input[x][y] == '|': |
|
||||||
next = (x+1, y) if whereami == (x-1,y) else (x-1, y) |
|
||||||
elif input[x][y] == '-': |
|
||||||
next = (x, y+1) if whereami == (x,y-1) else (x, y-1) |
|
||||||
elif input[x][y] == 'L': |
|
||||||
next = (x-1, y) if whereami == (x,y+1) else (x, y+1) |
|
||||||
elif input[x][y] == 'J': |
|
||||||
next = (x-1, y) if whereami == (x,y-1) else (x, y-1) |
|
||||||
elif input[x][y] == '7': |
|
||||||
next = (x+1, y) if whereami == (x,y-1) else (x, y-1) |
|
||||||
if next in traversed: |
|
||||||
break |
|
||||||
whereami = (x, y) |
|
||||||
|
|
||||||
print(len(traversed)/2) |
|
||||||
|
|
||||||
area = 0 |
|
||||||
for i in range(len(traversed)-1): |
|
||||||
area += (traversed[i][1] + traversed[i+1][1]) * (traversed[i][0] - traversed[i+1][0]) |
|
||||||
area += (traversed[-1][1] + traversed[0][1]) * (traversed[-1][0] - traversed[0][0]) |
|
||||||
area = abs(area / 2) |
|
||||||
|
|
||||||
points = area - len(traversed) / 2 + 1 |
|
||||||
print(points) |
|
@ -1,16 +0,0 @@ |
|||||||
list1, list2, summa, summa2 = [], [], 0, 0 |
|
||||||
|
|
||||||
for l in open("input.txt", 'r').read().splitlines(): |
|
||||||
tup = [int(n) for n in l.split(' ')] |
|
||||||
list1.append(tup[0]) |
|
||||||
list2.append(tup[1]) |
|
||||||
|
|
||||||
list1.sort() |
|
||||||
list2.sort() |
|
||||||
|
|
||||||
for i in range(len(list1)): |
|
||||||
summa += abs(list1[i] - list2[i]) |
|
||||||
summa2 += list2.count(list1[i]) * list1[i] |
|
||||||
|
|
||||||
print(summa) |
|
||||||
print(summa2) |
|
Loading…
Reference in new issue