change directory names

This commit is contained in:
Pim Kunis 2023-12-04 10:25:33 +01:00
parent 3cff0fc5cf
commit 78b8881016
90 changed files with 0 additions and 0 deletions

7
23/day1/example.txt Normal file
View file

@ -0,0 +1,7 @@
two1nine
eightwothree
abcone2threexyz
xtwone3four
4nineeightseven2
zoneight234
7pqrstsixteen

1000
23/day1/input.txt Normal file

File diff suppressed because it is too large Load diff

57
23/day1/main.py Executable file
View file

@ -0,0 +1,57 @@
#!//usr/bin/env python
def get_lines():
lines = list()
with open("input.txt", "r") as f:
for line in f:
lines.append(line.strip())
return lines
total = 0
for line in get_lines():
for char in line:
if char.isdigit():
first = int(char)
break
for char in line[::-1]:
if char.isdigit():
last = int(char)
break
value = first * 10 + last
total += value
print(total)
total = 0
for line in get_lines():
digits = []
for i in range(len(line)):
rest = line[i:]
if rest.startswith("one"):
digits.append(1)
if rest.startswith("two"):
digits.append(2)
if rest.startswith("three"):
digits.append(3)
if rest.startswith("four"):
digits.append(4)
if rest.startswith("five"):
digits.append(5)
if rest.startswith("six"):
digits.append(6)
if rest.startswith("seven"):
digits.append(7)
if rest.startswith("eight"):
digits.append(8)
if rest.startswith("nine"):
digits.append(9)
if rest.startswith("zero"):
digits.append(0)
if rest[0].isdigit():
digits.append(int(rest[0]))
total += digits[0] * 10 + digits[-1]
print(total)