Compare commits
2 Commits
0fe4c0d032
...
a7aa40381e
Author | SHA1 | Date |
---|---|---|
kwout | a7aa40381e | 2 months ago |
kwout | c02f2ec040 | 3 months ago |
3 changed files with 71 additions and 1 deletions
@ -0,0 +1,53 @@ |
|||||||
|
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) |
@ -0,0 +1,16 @@ |
|||||||
|
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