summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorlonkaars <loek@pipeframe.xyz>2023-12-01 20:40:44 +0100
committerlonkaars <loek@pipeframe.xyz>2023-12-01 20:40:44 +0100
commit88f3954385b272d74fac09b57544cd9ab3490668 (patch)
tree0726dc4fafc44c235d4af23adbc9aa4e3c1ce669
garbage man day 1
-rw-r--r--.gitignore1
-rwxr-xr-x01/main.py39
2 files changed, 40 insertions, 0 deletions
diff --git a/.gitignore b/.gitignore
new file mode 100644
index 0000000..e427dd8
--- /dev/null
+++ b/.gitignore
@@ -0,0 +1 @@
+*/input.txt
diff --git a/01/main.py b/01/main.py
new file mode 100755
index 0000000..9897dae
--- /dev/null
+++ b/01/main.py
@@ -0,0 +1,39 @@
+#!/bin/python3
+import sys
+import re
+
+MAP = {
+ "one": "1",
+ "two": "2",
+ "three": "3",
+ "four": "4",
+ "five": "5",
+ "six": "6",
+ "seven": "7",
+ "eight": "8",
+ "nine": "9",
+}
+sum = 0
+
+for line in sys.stdin:
+ line = line.strip()
+ real_line = ""
+ for c in range(len(line)):
+ match = re.search("one|two|three|four|five|six|seven|eight|nine|[0-9]", line[c:])
+ if match is None:
+ continue
+ if match.start() != 0:
+ continue
+
+ found = match.group(0)
+ if not found in MAP:
+ real_line += found
+ else:
+ real_line += MAP[found]
+
+ print(real_line)
+ num = int(real_line[0]) * 10 + int(real_line[-1])
+ sum += num
+
+print(f">> {sum}")
+