Move everything to a 2017 folder
This commit is contained in:
parent
32d7dded75
commit
fc87233242
15 changed files with 94 additions and 4017 deletions
37
2017/day2.py
Normal file
37
2017/day2.py
Normal file
|
|
@ -0,0 +1,37 @@
|
|||
def parse(text):
|
||||
return [[int(num) for num in line.split('\t')] for line in text.splitlines()]
|
||||
|
||||
with open('input/day2') as inp:
|
||||
puzzle_input = parse(inp.read())
|
||||
|
||||
def part1(sheet):
|
||||
return sum(max(row) - min(row) for row in sheet)
|
||||
|
||||
assert part1([
|
||||
[5, 1, 9, 5],
|
||||
[7, 5, 3],
|
||||
[2, 4, 6, 8],
|
||||
]) == 18
|
||||
|
||||
print(part1(puzzle_input))
|
||||
|
||||
from itertools import combinations
|
||||
|
||||
def part2(sheet):
|
||||
s = 0
|
||||
for row in sheet:
|
||||
for n, m in combinations(row, 2):
|
||||
lo = min(n, m)
|
||||
hi = max(n, m)
|
||||
if hi % lo == 0:
|
||||
s += hi // lo
|
||||
break
|
||||
return s
|
||||
|
||||
assert part2([
|
||||
[5, 9, 2, 8],
|
||||
[9, 4, 7, 3],
|
||||
[3, 8, 6, 5],
|
||||
]) == 9
|
||||
|
||||
print(part2(puzzle_input))
|
||||
Loading…
Reference in a new issue