2025: d03: ex1: add solution
This commit is contained in:
parent
a1e99ff1e2
commit
a4f740f825
1 changed files with 25 additions and 0 deletions
25
2025/d03/ex1/ex1.py
Executable file
25
2025/d03/ex1/ex1.py
Executable file
|
|
@ -0,0 +1,25 @@
|
||||||
|
#!/usr/bin/env python
|
||||||
|
|
||||||
|
import sys
|
||||||
|
|
||||||
|
|
||||||
|
def solve(input: list[str]) -> int:
|
||||||
|
def parse(input: list[str]) -> list[list[int]]:
|
||||||
|
return [[int(c) for c in line] for line in input]
|
||||||
|
|
||||||
|
def max_joltage(bank: list[int]) -> int:
|
||||||
|
first = bank.index(max(bank[:-1]))
|
||||||
|
second = bank.index(max(bank[first + 1 :]))
|
||||||
|
return bank[first] * 10 + bank[second]
|
||||||
|
|
||||||
|
batteries = parse(input)
|
||||||
|
return sum(map(max_joltage, batteries))
|
||||||
|
|
||||||
|
|
||||||
|
def main() -> None:
|
||||||
|
input = sys.stdin.read().splitlines()
|
||||||
|
print(solve(input))
|
||||||
|
|
||||||
|
|
||||||
|
if __name__ == "__main__":
|
||||||
|
main()
|
||||||
Loading…
Add table
Add a link
Reference in a new issue