Compare commits
5 commits
da90cd8472
...
9f280f2e3d
Author | SHA1 | Date | |
---|---|---|---|
Bruno BELANYI | 9f280f2e3d | ||
Bruno BELANYI | bfe380bfec | ||
Bruno BELANYI | f91c575008 | ||
Bruno BELANYI | 3b34ce63fb | ||
Bruno BELANYI | fd75f099db |
2
.gitignore
vendored
Normal file
2
.gitignore
vendored
Normal file
|
@ -0,0 +1,2 @@
|
|||
# Generated by Nix
|
||||
/.pre-commit-config.yaml
|
18
2021/d01/ex1/ex1.py
Executable file
18
2021/d01/ex1/ex1.py
Executable file
|
@ -0,0 +1,18 @@
|
|||
#!/usr/bin/env python
|
||||
|
||||
import itertools
|
||||
import sys
|
||||
from typing import List
|
||||
|
||||
|
||||
def solve(input: List[int]) -> int:
|
||||
return sum(prev < cur for (prev, cur) in itertools.pairwise(input))
|
||||
|
||||
|
||||
def main() -> None:
|
||||
input = [int(line) for line in sys.stdin.readlines()]
|
||||
print(solve(input))
|
||||
|
||||
|
||||
if __name__ == "__main__":
|
||||
main()
|
2000
2021/d01/ex1/input
Normal file
2000
2021/d01/ex1/input
Normal file
File diff suppressed because it is too large
Load diff
30
2021/d01/ex2/ex2.py
Executable file
30
2021/d01/ex2/ex2.py
Executable file
|
@ -0,0 +1,30 @@
|
|||
#!/usr/bin/env python
|
||||
|
||||
import collections
|
||||
import itertools
|
||||
import sys
|
||||
from typing import List
|
||||
|
||||
|
||||
def sliding_window(iterable, n):
|
||||
it = iter(iterable)
|
||||
window = collections.deque(itertools.islice(it, n), maxlen=n)
|
||||
if len(window) == n:
|
||||
yield tuple(window)
|
||||
for x in it:
|
||||
window.append(x)
|
||||
yield tuple(window)
|
||||
|
||||
|
||||
def solve(input: List[int]) -> int:
|
||||
windowed = [sum(window) for window in sliding_window(input, 3)]
|
||||
return sum(prev < cur for (prev, cur) in itertools.pairwise(windowed))
|
||||
|
||||
|
||||
def main() -> None:
|
||||
input = [int(line) for line in sys.stdin.readlines()]
|
||||
print(solve(input))
|
||||
|
||||
|
||||
if __name__ == "__main__":
|
||||
main()
|
2000
2021/d01/ex2/input
Normal file
2000
2021/d01/ex2/input
Normal file
File diff suppressed because it is too large
Load diff
Loading…
Reference in a new issue