Skip to content

Commit e77d2b4

Browse files
authored
Is day 14 too late to start a repo?
1 parent 7061aee commit e77d2b4

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

58 files changed

+7761
-0
lines changed

1.in

+1,000
Large diffs are not rendered by default.

1.py

+18
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
list1 = []
2+
list2 = []
3+
print("a")
4+
f = open("1.in")
5+
for line in f.readlines():
6+
a = list(map(int, line.split()))
7+
list1.append(a[0])
8+
list2.append(a[1])
9+
total = 0
10+
while len(list1) > 0:
11+
a = min(list1)
12+
b = min(list2)
13+
total += abs(a - b)
14+
list1.remove(a)
15+
list2.remove(b)
16+
print(len(list1))
17+
print(len(list2))
18+
print(total)

10.py

+64
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,64 @@
1+
from collections import defaultdict
2+
3+
f = open("9.in")
4+
5+
is_lesser_than = defaultdict(list)
6+
is_greater_than = defaultdict(list)
7+
docs = []
8+
sum = 0
9+
10+
for line in f.readlines():
11+
if "|" in line:
12+
a,b = list(map(int, line.split("|")))
13+
is_lesser_than[a].append(b)
14+
is_greater_than[b].append(a)
15+
else:
16+
docs.append(list(map(int, line.split(","))))
17+
bad_docs = []
18+
19+
for doc in docs:
20+
good_doc = True
21+
for page in doc:
22+
lesser = is_lesser_than[page]
23+
greater = is_greater_than[page]
24+
good_lesser = True
25+
for item in lesser:
26+
if item in doc:
27+
if doc.index(item) < doc.index(page):
28+
good_lesser = False
29+
good_greater = True
30+
for item in greater:
31+
if item in doc:
32+
if doc.index(item) > doc.index(page):
33+
good_greater = False
34+
if not (good_greater and good_lesser):
35+
good_doc = False
36+
if not good_doc:
37+
bad_docs.append(doc)
38+
for doc in bad_docs:
39+
did_fix = True
40+
while did_fix:
41+
did_fix = False
42+
for page in doc:
43+
lesser = is_lesser_than[page]
44+
greater = is_greater_than[page]
45+
for item in lesser:
46+
if item in doc:
47+
if doc.index(item) < doc.index(page):
48+
temp = doc[doc.index(page)]
49+
doc[doc.index(page)] = doc[doc.index(item)]
50+
doc[doc.index(item)] = temp
51+
did_fix = True
52+
break
53+
for item in greater:
54+
if item in doc:
55+
if doc.index(item) > doc.index(page):
56+
temp = doc[doc.index(page)]
57+
doc[doc.index(page)] = doc[doc.index(item)]
58+
doc[doc.index(item)] = temp
59+
did_fix = True
60+
break
61+
sum = 0
62+
for doc in bad_docs:
63+
sum += doc[int((len(doc)-1)/2)]
64+
print(sum)

11.in

+130
Large diffs are not rendered by default.

11.py

+38
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
f = open("11.in")
2+
obstacles = []
3+
visited = set()
4+
pos = (0,0)
5+
dir = "up"
6+
for i, line in enumerate(f.readlines()):
7+
for j, spot in enumerate(line):
8+
if spot == "#":
9+
obstacles.append((i,j))
10+
elif spot == "^":
11+
pos = (i,j)
12+
while pos[0] < 130 and pos[0] >= 0 and pos[1] < 130 and pos[1] >= 0:
13+
visited.add(pos)
14+
if dir == "up":
15+
next = (pos[0]-1,pos[1])
16+
if next in obstacles:
17+
dir = "right"
18+
else:
19+
pos = next
20+
if dir == "right":
21+
next = (pos[0],pos[1]+1)
22+
if next in obstacles:
23+
dir = "down"
24+
else:
25+
pos = next
26+
if dir == "down":
27+
next = (pos[0]+1,pos[1])
28+
if next in obstacles:
29+
dir = "left"
30+
else:
31+
pos = next
32+
if dir == "left":
33+
next = (pos[0],pos[1]-1)
34+
if next in obstacles:
35+
dir = "up"
36+
else:
37+
pos = next
38+
print(len(visited))

12.py

+57
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,57 @@
1+
from collections import defaultdict
2+
f = open("11.in")
3+
obstacles = []
4+
visited = defaultdict(list)
5+
pos = (0,0)
6+
dir = "up"
7+
for i, line in enumerate(f.readlines()):
8+
for j, spot in enumerate(line):
9+
if spot == "#":
10+
obstacles.append((i,j))
11+
elif spot == "^":
12+
pos = (i,j)
13+
14+
def check(obstacles, pos, dir):
15+
visited.clear()
16+
while pos[0] < 130 and pos[0] >= 0 and pos[1] < 130 and pos[1] >= 0:
17+
if dir in visited[pos]:
18+
return True
19+
visited[pos].append(dir)
20+
if dir == "up":
21+
next = (pos[0]-1,pos[1])
22+
if next in obstacles:
23+
dir = "right"
24+
else:
25+
pos = next
26+
if dir == "right":
27+
next = (pos[0],pos[1]+1)
28+
if next in obstacles:
29+
dir = "down"
30+
else:
31+
pos = next
32+
if dir == "down":
33+
next = (pos[0]+1,pos[1])
34+
if next in obstacles:
35+
dir = "left"
36+
else:
37+
pos = next
38+
if dir == "left":
39+
next = (pos[0],pos[1]-1)
40+
if next in obstacles:
41+
dir = "up"
42+
else:
43+
pos = next
44+
return False
45+
46+
count = 0
47+
48+
for i in range(130):
49+
for j in range(130):
50+
new_obs = obstacles.copy()
51+
new_obs.append((i,j))
52+
if check(new_obs, pos, "up"):
53+
count += 1
54+
print(count)
55+
if j == 0:
56+
print("I" + str(i))
57+
print(count)

0 commit comments

Comments
 (0)