Compare commits

...

6 commits

6 changed files with 2091 additions and 14 deletions

20
2023/d01/ex1/ex1.py Executable file
View file

@ -0,0 +1,20 @@
#!/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 Normal file

File diff suppressed because it is too large Load diff

39
2023/d01/ex2/ex2.py Executable file
View file

@ -0,0 +1,39 @@
#!/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 = {
"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 Normal file

File diff suppressed because it is too large Load diff

44
flake.lock generated
View file

@ -3,11 +3,11 @@
"flake-compat": {
"flake": false,
"locked": {
"lastModified": 1668681692,
"narHash": "sha256-Ht91NGdewz8IQLtWZ9LCeNXMSXHUss+9COoqu6JLmXU=",
"lastModified": 1673956053,
"narHash": "sha256-4gtG9iQuiKITOjNQQeQIpoIB6b16fm+504Ch3sNKLd8=",
"owner": "edolstra",
"repo": "flake-compat",
"rev": "009399224d5e398d03b22badca40a37ac85412a1",
"rev": "35bb57c0c8d8b62bbfd284272c928ceb64ddbde9",
"type": "github"
},
"original": {
@ -17,17 +17,20 @@
}
},
"futils": {
"inputs": {
"systems": "systems"
},
"locked": {
"lastModified": 1667395993,
"narHash": "sha256-nuEHfE/LcWyuSWnS8t12N1wc105Qtau+/OdUAjtQ0rA=",
"lastModified": 1694529238,
"narHash": "sha256-zsNZZGTGnMOf9YpHKJqMSsa0dXbfmxeoJ7xHlrt+xmY=",
"owner": "numtide",
"repo": "flake-utils",
"rev": "5aed5285a952e0b949eb3ba02c12fa4fcfef535f",
"rev": "ff7b65b44d01cf9ba6a71320833626af21126384",
"type": "github"
},
"original": {
"owner": "numtide",
"ref": "master",
"ref": "main",
"repo": "flake-utils",
"type": "github"
}
@ -55,11 +58,11 @@
},
"nixpkgs": {
"locked": {
"lastModified": 1669809720,
"narHash": "sha256-RMT77f6CPOYtLLQ2esj+EJ1BPVWxf4RDidjrSvA5OhI=",
"lastModified": 1701336116,
"narHash": "sha256-kEmpezCR/FpITc6yMbAh4WrOCiT2zg5pSjnKrq51h5Y=",
"owner": "NixOS",
"repo": "nixpkgs",
"rev": "227de2b3bbec142f912c09d5e8a1b4e778aa54fb",
"rev": "f5c27c6136db4d76c30e533c20517df6864c46ee",
"type": "github"
},
"original": {
@ -84,11 +87,11 @@
]
},
"locked": {
"lastModified": 1669829516,
"narHash": "sha256-laWMD/TZzyrulu8xLNoSPertXOxjRD7BrcAVwKl+NyQ=",
"lastModified": 1700922917,
"narHash": "sha256-ej2fch/T584b5K9sk1UhmZF7W6wEfDHuoUYpFN8dtvM=",
"owner": "cachix",
"repo": "pre-commit-hooks.nix",
"rev": "471c7f1ecace25e39099206431300322632d25c4",
"rev": "e5ee5c5f3844550c01d2131096c7271cec5e9b78",
"type": "github"
},
"original": {
@ -104,6 +107,21 @@
"nixpkgs": "nixpkgs",
"pre-commit-hooks": "pre-commit-hooks"
}
},
"systems": {
"locked": {
"lastModified": 1681028828,
"narHash": "sha256-Vy1rq5AaRuLzOxct8nz4T6wlgyUR7zLU309k9mBC768=",
"owner": "nix-systems",
"repo": "default",
"rev": "da67096a3b9bf56a91d16901293e51ba5b49a27e",
"type": "github"
},
"original": {
"owner": "nix-systems",
"repo": "default",
"type": "github"
}
}
},
"root": "root",

View file

@ -6,7 +6,7 @@
type = "github";
owner = "numtide";
repo = "flake-utils";
ref = "master";
ref = "main";
};
nixpkgs = {