I cheated for part one and used combinations-method 😋 import itertools, time def puzzle_input(): with open("input.txt") as f: data = [int(line.replace(" ", "")) for line in f] return data puzzle = puzzle_input() def solution_1(data): width = 25 for x in range(width, len(data)): sums = list(map(sum, list(itertools.combinations(data[x - width:x], 2)))) if data[x] not in sums: return data[x] def solution_2(data): for x in range(1, data.index(sum_to_find)): for y in range(0, data.index(sum_to_find)): if sum(data[y:y + x]) == sum_to_find: return min(data[y:y + x]) + max(data[y:y + x]) start = time.perf_counter() print(solution_1(puzzle), time.perf_counter() - start) sum_to_find = solution_1(puzzle) start = time.perf_counter() print(solution_2(puzzle), time.perf_counter() - start)
what does data[i] do
data[i] will access an element in the input list. In this case, data[i] represents the number that we are checking is corrupted or not.
you really gotta update that java dude or mute the notification lol
lol I'll get rid of it
I cheated for part one and used combinations-method 😋
import itertools, time
def puzzle_input():
with open("input.txt") as f:
data = [int(line.replace("
", "")) for line in f]
return data
puzzle = puzzle_input()
def solution_1(data):
width = 25
for x in range(width, len(data)):
sums = list(map(sum, list(itertools.combinations(data[x - width:x], 2))))
if data[x] not in sums:
return data[x]
def solution_2(data):
for x in range(1, data.index(sum_to_find)):
for y in range(0, data.index(sum_to_find)):
if sum(data[y:y + x]) == sum_to_find:
return min(data[y:y + x]) + max(data[y:y + x])
start = time.perf_counter()
print(solution_1(puzzle), time.perf_counter() - start)
sum_to_find = solution_1(puzzle)
start = time.perf_counter()
print(solution_2(puzzle), time.perf_counter() - start)
Dang those solutions are so short! I've never tried itertools before.