Compare commits
4 commits
789f2f89e6
...
e190b4dd3b
Author | SHA1 | Date | |
---|---|---|---|
Bruno BELANYI | e190b4dd3b | ||
Bruno BELANYI | 0d9076f8a1 | ||
Bruno BELANYI | acde34de85 | ||
Bruno BELANYI | df29663c52 |
24
2022/d04/ex1/ex1.py
Executable file
24
2022/d04/ex1/ex1.py
Executable file
|
@ -0,0 +1,24 @@
|
|||
#!/usr/bin/env python
|
||||
|
||||
import sys
|
||||
|
||||
|
||||
def solve(input: list[str]) -> int:
|
||||
def is_redundant(line: str) -> bool:
|
||||
def assignment_to_set(elf: str) -> set[int]:
|
||||
start, end = elf.split("-")
|
||||
return set(range(int(start), int(end) + 1))
|
||||
|
||||
elf1, elf2 = map(assignment_to_set, line.split(","))
|
||||
return elf1.issubset(elf2) or elf2.issubset(elf1)
|
||||
|
||||
return sum(map(is_redundant, input))
|
||||
|
||||
|
||||
def main() -> None:
|
||||
input = sys.stdin.read().splitlines()
|
||||
print(solve(input))
|
||||
|
||||
|
||||
if __name__ == "__main__":
|
||||
main()
|
1000
2022/d04/ex1/input
Normal file
1000
2022/d04/ex1/input
Normal file
File diff suppressed because it is too large
Load diff
24
2022/d04/ex2/ex2.py
Executable file
24
2022/d04/ex2/ex2.py
Executable file
|
@ -0,0 +1,24 @@
|
|||
#!/usr/bin/env python
|
||||
|
||||
import sys
|
||||
|
||||
|
||||
def solve(input: list[str]) -> int:
|
||||
def is_overlapping(line: str) -> bool:
|
||||
def assignment_to_set(elf: str) -> set[int]:
|
||||
start, end = elf.split("-")
|
||||
return set(range(int(start), int(end) + 1))
|
||||
|
||||
elf1, elf2 = map(assignment_to_set, line.split(","))
|
||||
return bool(elf1 & elf2)
|
||||
|
||||
return sum(map(is_overlapping, input))
|
||||
|
||||
|
||||
def main() -> None:
|
||||
input = sys.stdin.read().splitlines()
|
||||
print(solve(input))
|
||||
|
||||
|
||||
if __name__ == "__main__":
|
||||
main()
|
1000
2022/d04/ex2/input
Normal file
1000
2022/d04/ex2/input
Normal file
File diff suppressed because it is too large
Load diff
Loading…
Reference in a new issue