mirror of
https://github.com/tanishq-dubey/aoc2023.git
synced 2025-04-11 17:33:34 -04:00
wtf was this problem
This commit is contained in:
parent
a3820f7e2a
commit
5fe809517d
67
day1/main.py
67
day1/main.py
@ -9,9 +9,10 @@ total = 0
|
|||||||
|
|
||||||
for d in data:
|
for d in data:
|
||||||
dstring = ''.join(filter(str.isdigit, d))
|
dstring = ''.join(filter(str.isdigit, d))
|
||||||
|
if len(dstring) < 1:
|
||||||
|
continue
|
||||||
d1 = dstring[0]
|
d1 = dstring[0]
|
||||||
d2 = dstring[-1]
|
d2 = dstring[-1]
|
||||||
print(d1, "-", d2)
|
|
||||||
total = total + int(f"{d1}{d2}")
|
total = total + int(f"{d1}{d2}")
|
||||||
|
|
||||||
|
|
||||||
@ -22,3 +23,67 @@ print("=======")
|
|||||||
|
|
||||||
|
|
||||||
# Part 2
|
# Part 2
|
||||||
|
total = 0
|
||||||
|
|
||||||
|
dtt = {
|
||||||
|
"one": "o1e",
|
||||||
|
"two": "t2o",
|
||||||
|
"three": "t3e",
|
||||||
|
"four": "f4r",
|
||||||
|
"five": "f5e",
|
||||||
|
"six": "s6x",
|
||||||
|
"seven": "s7n",
|
||||||
|
"eight": "e8t",
|
||||||
|
"nine": "n9n",
|
||||||
|
}
|
||||||
|
|
||||||
|
for d in data:
|
||||||
|
tmp = d
|
||||||
|
|
||||||
|
for _, _ in dtt.items():
|
||||||
|
minidx = 10000000000
|
||||||
|
minval = "invalid"
|
||||||
|
for k,v in dtt.items():
|
||||||
|
try:
|
||||||
|
if tmp.index(k) < minidx:
|
||||||
|
minidx = tmp.index(k)
|
||||||
|
minval = k
|
||||||
|
except ValueError as e:
|
||||||
|
if "substring not found" in str(e):
|
||||||
|
continue
|
||||||
|
if minval != "invalid":
|
||||||
|
tmp = tmp.replace(minval, str(dtt[minval]), 1)
|
||||||
|
|
||||||
|
dstring = ''.join(filter(str.isdigit, tmp))
|
||||||
|
if len(dstring) < 1:
|
||||||
|
continue
|
||||||
|
d1 = dstring[0]
|
||||||
|
d2 = dstring[-1]
|
||||||
|
#print(d1, "-", d2, "----", tmp.strip(), d.strip())
|
||||||
|
total = total + int(f"{d1}{d2}")
|
||||||
|
|
||||||
|
|
||||||
|
print("======= PT 2")
|
||||||
|
print(total)
|
||||||
|
print("=======")
|
||||||
|
|
||||||
|
|
||||||
|
total = 0
|
||||||
|
for d in data:
|
||||||
|
tmp = d
|
||||||
|
for k, v in dtt.items():
|
||||||
|
try:
|
||||||
|
tmp = tmp.replace(k, str(v))
|
||||||
|
except Exception as e:
|
||||||
|
pass
|
||||||
|
dstring = ''.join(filter(str.isdigit, tmp))
|
||||||
|
if len(dstring) < 1:
|
||||||
|
continue
|
||||||
|
d1 = dstring[0]
|
||||||
|
d2 = dstring[-1]
|
||||||
|
#print(d1, "-", d2, "----", tmp.strip(), d.strip())
|
||||||
|
total = total + int(f"{d1}{d2}")
|
||||||
|
|
||||||
|
print("======= PT 2 - 2")
|
||||||
|
print(total)
|
||||||
|
print("=======")
|
||||||
|
Loading…
x
Reference in New Issue
Block a user