day 1
This commit is contained in:
commit
02c8ed3933
1
.gitignore
vendored
Normal file
1
.gitignore
vendored
Normal file
@ -0,0 +1 @@
|
||||
.DS_Store
|
15
1/a.py
Normal file
15
1/a.py
Normal file
@ -0,0 +1,15 @@
|
||||
with open("input.txt") as f:
|
||||
lines = [int(i) for i in f.readlines()]
|
||||
|
||||
|
||||
hits = 0
|
||||
last = None
|
||||
|
||||
for line in lines:
|
||||
if last is not None and line > last:
|
||||
hits += 1
|
||||
|
||||
last = line
|
||||
|
||||
|
||||
print(hits)
|
20
1/b.py
Normal file
20
1/b.py
Normal file
@ -0,0 +1,20 @@
|
||||
with open("input.txt") as f:
|
||||
lines = [int(i) for i in f.readlines()]
|
||||
|
||||
|
||||
hits = 0
|
||||
window = lines[0:3]
|
||||
|
||||
for line in lines[3:]:
|
||||
oldwindow = list(window)
|
||||
window.pop(0)
|
||||
window.append(line)
|
||||
|
||||
if sum(oldwindow) < sum(window):
|
||||
hits += 1
|
||||
|
||||
|
||||
print(hits)
|
||||
|
||||
|
||||
# 5m41s
|
13
1/b_best.py
Normal file
13
1/b_best.py
Normal file
@ -0,0 +1,13 @@
|
||||
with open("input.txt") as f:
|
||||
lines = [int(i) for i in f.readlines()]
|
||||
|
||||
hits = 0
|
||||
winsize = 3
|
||||
last = sum([lines[0], lines[1], lines[2]])
|
||||
|
||||
for i in range(3, len(lines)):
|
||||
now = last - lines[i - 3] + lines[i]
|
||||
if now > last:
|
||||
hits += 1
|
||||
|
||||
print(hits)
|
15
1/b_better.py
Normal file
15
1/b_better.py
Normal file
@ -0,0 +1,15 @@
|
||||
with open("input.txt") as f:
|
||||
lines = [int(i) for i in f.readlines()]
|
||||
|
||||
|
||||
hits = 0
|
||||
winsize = 3
|
||||
last = None
|
||||
|
||||
for i in range(0, len(lines) - 2):
|
||||
window = sum([lines[i], lines[i + 1], lines[i + 2]])
|
||||
if last is not None and window > last:
|
||||
hits +=1
|
||||
last = window
|
||||
|
||||
print(hits)
|
2000
1/input.txt
Normal file
2000
1/input.txt
Normal file
File diff suppressed because it is too large
Load Diff
Loading…
Reference in New Issue
Block a user