Cleanup 2015 solutions
This commit is contained in:
parent
5a5e843129
commit
a48f3608b2
7 changed files with 26 additions and 51 deletions
|
|
@ -23,10 +23,10 @@ class BaseSolution:
|
|||
)
|
||||
|
||||
def solve(self, puzzle_input):
|
||||
raise NotImplemented
|
||||
raise NotImplementedError
|
||||
|
||||
def solve_again(self, puzzle_input):
|
||||
raise NotImplemented
|
||||
raise NotImplementedError
|
||||
|
||||
def parse_input(self, data):
|
||||
raise NotImplemented
|
||||
raise NotImplementedError
|
||||
|
|
|
|||
|
|
@ -1,7 +1,8 @@
|
|||
import re
|
||||
from solutions import BaseSolution
|
||||
from collections import defaultdict
|
||||
|
||||
from solutions import BaseSolution
|
||||
|
||||
|
||||
class Solution(BaseSolution):
|
||||
input_file = "06.txt"
|
||||
|
|
@ -26,6 +27,8 @@ class Solution(BaseSolution):
|
|||
m[(r, c)] = True
|
||||
case "turn off":
|
||||
m[(r, c)] = False
|
||||
p1 = sum(m.values())
|
||||
assert p1 == 569999
|
||||
return sum(m.values())
|
||||
|
||||
def solve_again(self, puzzle_input):
|
||||
|
|
@ -42,7 +45,9 @@ class Solution(BaseSolution):
|
|||
m[(r, c)] += 1
|
||||
case "turn off":
|
||||
m[(r, c)] = max(m[(r, c)] - 1, 0)
|
||||
return sum(m.values())
|
||||
p2 = sum(m.values())
|
||||
assert p2 == 17836115
|
||||
return p2
|
||||
|
||||
|
||||
if __name__ == "__main__":
|
||||
|
|
|
|||
|
|
@ -1,5 +1,3 @@
|
|||
import re
|
||||
|
||||
from solutions import BaseSolution
|
||||
|
||||
|
||||
|
|
|
|||
|
|
@ -1,7 +1,7 @@
|
|||
from collections import defaultdict
|
||||
from solutions import BaseSolution
|
||||
import re
|
||||
from random import shuffle, choice
|
||||
from random import shuffle
|
||||
|
||||
from solutions import BaseSolution
|
||||
|
||||
|
||||
class Solution(BaseSolution):
|
||||
|
|
|
|||
|
|
@ -1,4 +1,5 @@
|
|||
from collections import defaultdict
|
||||
|
||||
from solutions import BaseSolution
|
||||
|
||||
|
||||
|
|
@ -9,17 +10,17 @@ class Solution(BaseSolution):
|
|||
return "Day 20: Infinite Elves and Infinite Houses"
|
||||
|
||||
def solve(self, pi):
|
||||
hn = 831601
|
||||
x1 = defaultdict(int)
|
||||
for i in range(1, hn):
|
||||
for n in range(0, hn, i):
|
||||
if n == 0:
|
||||
continue
|
||||
x1[n] += i * 10
|
||||
return max(x1.items(), key=lambda y: y[1])[0]
|
||||
|
||||
def solve_again(self, pi):
|
||||
S = 36_000_000
|
||||
# hn = 831601
|
||||
# x1 = defaultdict(int)
|
||||
# for i in range(1, hn):
|
||||
# for n in range(0, hn, i):
|
||||
# if n == 0:
|
||||
# continue
|
||||
# x1[n] += i * 10
|
||||
# for k, v in x1.items():
|
||||
# if v >= S:
|
||||
# print(k, v)
|
||||
hn = 885000
|
||||
hc = 50
|
||||
x2 = defaultdict(int)
|
||||
|
|
@ -28,12 +29,7 @@ class Solution(BaseSolution):
|
|||
if n == 0:
|
||||
continue
|
||||
x2[n] += i * 11
|
||||
# p1 = max(x1.items(), key=lambda y: y[1])[0]
|
||||
p2 = min(filter(lambda x: x[1] >= S, x2.items()), key=lambda y: y[0])[0]
|
||||
return 0, p2
|
||||
|
||||
def solve_again(self, pi):
|
||||
return pi
|
||||
return min(filter(lambda x: x[1] >= S, x2.items()), key=lambda y: y[0])[0]
|
||||
|
||||
def parse_input(self, data):
|
||||
return data.strip()
|
||||
|
|
@ -41,11 +37,4 @@ class Solution(BaseSolution):
|
|||
|
||||
if __name__ == "__main__":
|
||||
solution = Solution()
|
||||
# solution.show_results()
|
||||
|
||||
dummy = """
|
||||
replace me
|
||||
""".strip()
|
||||
|
||||
print(solution.solve(dummy))
|
||||
# solution.solve_again(dummy)
|
||||
solution.show_results()
|
||||
|
|
|
|||
|
|
@ -53,13 +53,3 @@ class Solution(BaseSolution):
|
|||
if __name__ == "__main__":
|
||||
solution = Solution()
|
||||
solution.show_results()
|
||||
|
||||
dummy = """
|
||||
inc a
|
||||
jio a, +2
|
||||
tpl a
|
||||
inc a
|
||||
""".strip()
|
||||
|
||||
# solution.solve(dummy)
|
||||
# solution.solve_again(dummy)
|
||||
|
|
|
|||
|
|
@ -41,10 +41,3 @@ class Solution(BaseSolution):
|
|||
if __name__ == "__main__":
|
||||
solution = Solution()
|
||||
solution.show_results()
|
||||
|
||||
dummy = """
|
||||
1,2,3,4,5,7,8,9,10,11
|
||||
""".strip()
|
||||
|
||||
solution.solve(dummy)
|
||||
# solution.solve_again(dummy)
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue