Compare commits
No commits in common. "7ef6dd8af97e7a504eb91d80c209c660bf76e1ca" and "53c344b22334e56d677d4813e7c57aae6476d12e" have entirely different histories.
7ef6dd8af9
...
53c344b223
4 changed files with 0 additions and 2060 deletions
|
|
@ -1,20 +0,0 @@
|
|||
#!/usr/bin/env python
|
||||
|
||||
import sys
|
||||
|
||||
|
||||
def solve(input: list[str]) -> int:
|
||||
def value(line: str) -> int:
|
||||
digits = [int(c) for c in line if c.isdigit()]
|
||||
return digits[0] * 10 + digits[-1]
|
||||
|
||||
return sum(value(line) for line in input)
|
||||
|
||||
|
||||
def main() -> None:
|
||||
input = sys.stdin.read().splitlines()
|
||||
print(solve(input))
|
||||
|
||||
|
||||
if __name__ == "__main__":
|
||||
main()
|
||||
1000
2023/d01/ex1/input
1000
2023/d01/ex1/input
File diff suppressed because it is too large
Load diff
|
|
@ -1,40 +0,0 @@
|
|||
#!/usr/bin/env python
|
||||
|
||||
import sys
|
||||
|
||||
|
||||
def solve(input: list[str]) -> int:
|
||||
def extract_digits(line: str) -> list[int]:
|
||||
# Just do a search and replace to simplify our lives
|
||||
digits = {
|
||||
"zero": 0,
|
||||
"one": 1,
|
||||
"two": 2,
|
||||
"three": 3,
|
||||
"four": 4,
|
||||
"five": 5,
|
||||
"six": 6,
|
||||
"seven": 7,
|
||||
"eight": 8,
|
||||
"nine": 9,
|
||||
}
|
||||
# The solution expects "sevenine" to translate to 79, so keep first/last character
|
||||
# as a work-around.
|
||||
for word, value in digits.items():
|
||||
line = line.replace(word, word[0] + str(value) + word[-1])
|
||||
return [int(c) for c in line if c.isdigit()]
|
||||
|
||||
def value(line: str) -> int:
|
||||
digits = extract_digits(line)
|
||||
return digits[0] * 10 + digits[-1]
|
||||
|
||||
return sum(value(line) for line in input)
|
||||
|
||||
|
||||
def main() -> None:
|
||||
input = sys.stdin.read().splitlines()
|
||||
print(solve(input))
|
||||
|
||||
|
||||
if __name__ == "__main__":
|
||||
main()
|
||||
1000
2023/d01/ex2/input
1000
2023/d01/ex2/input
File diff suppressed because it is too large
Load diff
Loading…
Add table
Add a link
Reference in a new issue