added day01
This commit is contained in:
parent
b884754d87
commit
e80b51f95e
BIN
01/.solve01.py.swp
Normal file
BIN
01/.solve01.py.swp
Normal file
Binary file not shown.
BIN
01/.solve02.py.swp
Normal file
BIN
01/.solve02.py.swp
Normal file
Binary file not shown.
2000
01/input01.txt
Normal file
2000
01/input01.txt
Normal file
File diff suppressed because it is too large
Load Diff
2000
01/input02.txt
Normal file
2000
01/input02.txt
Normal file
File diff suppressed because it is too large
Load Diff
16
01/solve01.py
Normal file
16
01/solve01.py
Normal file
@ -0,0 +1,16 @@
|
||||
#!/usr/bin/env python
|
||||
|
||||
prev = None
|
||||
inc = 0
|
||||
|
||||
with open("input01.txt", "r") as f:
|
||||
for line in f:
|
||||
num = int(line)
|
||||
if prev is None:
|
||||
prev = num
|
||||
continue
|
||||
if prev < num:
|
||||
inc += 1
|
||||
prev = num
|
||||
|
||||
print(inc)
|
19
01/solve02.py
Normal file
19
01/solve02.py
Normal file
@ -0,0 +1,19 @@
|
||||
#!/usr/bin/env python
|
||||
|
||||
window = []
|
||||
inc = 0
|
||||
|
||||
with open("input02.txt", "r") as f:
|
||||
for line in f:
|
||||
num = int(line)
|
||||
window.append(num)
|
||||
if len(window) < 4:
|
||||
continue
|
||||
x1 = sum(window[0:3])
|
||||
x2 = sum(window[1:4])
|
||||
if x1 < x2:
|
||||
inc += 1
|
||||
window.pop(0)
|
||||
|
||||
|
||||
print(inc)
|
Loading…
x
Reference in New Issue
Block a user