This commit is contained in:
cupcakearmy 2021-12-01 14:46:26 +01:00
parent 5814ef2181
commit cf8e454682
No known key found for this signature in database
GPG Key ID: 3235314B4D31232F
5 changed files with 2077 additions and 0 deletions

2001
2021/01/input.txt Normal file

File diff suppressed because it is too large Load Diff

6
2021/01/main.py Normal file
View 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
View 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
View File

@ -0,0 +1,10 @@
199
200
208
210
200
207
240
269
260
263

8
2021/01/test_2.txt Normal file
View File

@ -0,0 +1,8 @@
607
618
618
617
647
716
769
792