Compare commits
No commits in common. "e190b4dd3bd34d50993c6f91409023cae687f194" and "789f2f89e6c863249cdffca1373a45720e7f2d56" have entirely different histories.
e190b4dd3b
...
789f2f89e6
|
@ -1,24 +0,0 @@
|
||||||
#!/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
1000
2022/d04/ex1/input
File diff suppressed because it is too large
Load diff
|
@ -1,24 +0,0 @@
|
||||||
#!/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
1000
2022/d04/ex2/input
File diff suppressed because it is too large
Load diff
Loading…
Reference in a new issue