mirror of
https://github.com/cupcakearmy/advent-of-code.git
synced 2024-10-31 23:54:11 +01:00
2021/01
This commit is contained in:
parent
5814ef2181
commit
cf8e454682
2001
2021/01/input.txt
Normal file
2001
2021/01/input.txt
Normal file
File diff suppressed because it is too large
Load Diff
6
2021/01/main.py
Normal file
6
2021/01/main.py
Normal file
@ -0,0 +1,6 @@
|
|||||||
|
|
||||||
|
|
||||||
|
# 1
|
||||||
|
with open('./input.txt', 'r') as f:
|
||||||
|
for line in f.readlines():
|
||||||
|
print(line.strip())
|
52
2021/01/python/main.py
Normal file
52
2021/01/python/main.py
Normal file
@ -0,0 +1,52 @@
|
|||||||
|
#!/usr/bin/env python
|
||||||
|
|
||||||
|
from os.path import join, dirname
|
||||||
|
from typing import List
|
||||||
|
|
||||||
|
# Day 01
|
||||||
|
|
||||||
|
# Common
|
||||||
|
|
||||||
|
|
||||||
|
def read_input(filename) -> str:
|
||||||
|
data = join(dirname(__file__), '..', filename)
|
||||||
|
with open(data) as f:
|
||||||
|
return f.read()
|
||||||
|
|
||||||
|
|
||||||
|
def parse(raw):
|
||||||
|
return [int(x) for x in raw.strip().split('\n')]
|
||||||
|
|
||||||
|
|
||||||
|
test = parse(read_input('test.txt'))
|
||||||
|
test2 = parse(read_input('test_2.txt'))
|
||||||
|
data = parse(read_input('input.txt'))
|
||||||
|
|
||||||
|
# 1
|
||||||
|
|
||||||
|
|
||||||
|
def count_increasing(data: List[int]) -> int:
|
||||||
|
total = 0
|
||||||
|
for x in range(1, len(data)):
|
||||||
|
if data[x] > data[x - 1]:
|
||||||
|
total += 1
|
||||||
|
return total
|
||||||
|
|
||||||
|
|
||||||
|
print('1. ')
|
||||||
|
print(f"Test: {count_increasing(test)}")
|
||||||
|
print(f"Result: {count_increasing(data)}")
|
||||||
|
|
||||||
|
# 2
|
||||||
|
|
||||||
|
|
||||||
|
def data_to_windows(data: List, size: int) -> List:
|
||||||
|
windows = []
|
||||||
|
for x in range(0, len(data) - size + 1):
|
||||||
|
windows.append(sum(data[x:x + size]))
|
||||||
|
return windows
|
||||||
|
|
||||||
|
|
||||||
|
print('2.')
|
||||||
|
print(f"Test: {count_increasing(data_to_windows(test2, 3))}")
|
||||||
|
print(f"Result: {count_increasing(data_to_windows(data, 3))}")
|
10
2021/01/test.txt
Normal file
10
2021/01/test.txt
Normal file
@ -0,0 +1,10 @@
|
|||||||
|
199
|
||||||
|
200
|
||||||
|
208
|
||||||
|
210
|
||||||
|
200
|
||||||
|
207
|
||||||
|
240
|
||||||
|
269
|
||||||
|
260
|
||||||
|
263
|
8
2021/01/test_2.txt
Normal file
8
2021/01/test_2.txt
Normal file
@ -0,0 +1,8 @@
|
|||||||
|
607
|
||||||
|
618
|
||||||
|
618
|
||||||
|
617
|
||||||
|
647
|
||||||
|
716
|
||||||
|
769
|
||||||
|
792
|
Loading…
Reference in New Issue
Block a user