First day finish
This commit is contained in:
parent
c7a4428965
commit
cd48a3bfec
@ -1,20 +1,55 @@
|
|||||||
sum = 0
|
sum = 0
|
||||||
|
|
||||||
nums = ["one", "two", "three", "four", "five", "six", "seven", "eight", "nine"]
|
nums = {"one": 1,
|
||||||
|
"two": 2,
|
||||||
|
"three": 3,
|
||||||
|
"four": 4,
|
||||||
|
"five": 5,
|
||||||
|
"six": 6,
|
||||||
|
"seven": 7,
|
||||||
|
"eight": 8,
|
||||||
|
"nine": 9}
|
||||||
|
|
||||||
with open("test.txt") as f:
|
# with open("input.txt") as f:
|
||||||
|
# for curr in f.readlines():
|
||||||
|
# for n in nums:
|
||||||
|
# print(curr[:-1])
|
||||||
|
# num = []
|
||||||
|
# for c in range(len(curr)):
|
||||||
|
# if curr[c].isnumeric():
|
||||||
|
# num.append(curr[c])
|
||||||
|
# break
|
||||||
|
|
||||||
|
# for c in range(len(curr), 0, -1):
|
||||||
|
# if curr[c-1].isnumeric():
|
||||||
|
# num.append(curr[c-1])
|
||||||
|
# break
|
||||||
|
# print(int("".join(num)))
|
||||||
|
# sum += int("".join(num))
|
||||||
|
# print(sum)
|
||||||
|
|
||||||
|
with open("input.txt") as f:
|
||||||
for curr in f.readlines():
|
for curr in f.readlines():
|
||||||
print(curr[:-1])
|
num_pos = { 1: [], 2: [], 3: [], 4: [], 5: [], 6: [], 7: [], 8: [], 9: [], }
|
||||||
num = []
|
for k, v in enumerate(curr):
|
||||||
for c in range(len(curr)):
|
if v.isnumeric():
|
||||||
if curr[c].isnumeric():
|
num_pos[int(v)].append(k)
|
||||||
num.append(curr[c])
|
for k, v in nums.items():
|
||||||
break
|
foundL = curr.find(k)
|
||||||
|
foundR = curr.rfind(k)
|
||||||
for c in range(len(curr), 0, -1):
|
foundR = -1 if foundL == foundR else foundR
|
||||||
if curr[c-1].isnumeric():
|
if foundL >= 0:
|
||||||
num.append(curr[c-1])
|
num_pos[v].append(foundL)
|
||||||
break
|
if foundR >= 0:
|
||||||
print(int("".join(num)))
|
num_pos[v].append(foundR)
|
||||||
sum += int("".join(num))
|
minpos = (999, -1)
|
||||||
|
maxpos = (-1, -1)
|
||||||
|
for k, v in num_pos.items():
|
||||||
|
for e in v:
|
||||||
|
minpos = (min(minpos[0], e), k) if min(minpos[0], e) != minpos[0] else minpos
|
||||||
|
maxpos = (max(maxpos[0], e), k) if max(maxpos[0], e) != maxpos[0] else maxpos
|
||||||
|
print(num_pos)
|
||||||
|
print(minpos, maxpos)
|
||||||
|
print(int("".join([str(minpos[1]), str(maxpos[1])])))
|
||||||
|
sum += int("".join([str(minpos[1]), str(maxpos[1])]))
|
||||||
print(sum)
|
print(sum)
|
||||||
|
7
2023/d1/test.txt
Normal file
7
2023/d1/test.txt
Normal file
@ -0,0 +1,7 @@
|
|||||||
|
two1nine
|
||||||
|
eightwothree
|
||||||
|
abcone2threexyz
|
||||||
|
xtwone3four
|
||||||
|
4nineeightseven2
|
||||||
|
zoneight234
|
||||||
|
7pqrstsixteen
|
Loading…
Reference in New Issue
Block a user