Compare commits

...

5 Commits

  1. 36
      2022/day2/2a.py
  2. 2500
      2022/day2/input.txt
  3. 3
      2022/day2/input.txt.sample
  4. 20
      2023/day1/1a.py
  5. 32
      2023/day1/1b.py
  6. 1000
      2023/day1/input.txt
  7. 7
      2023/day1/input.txt.sample
  8. 5
      README.md

@ -0,0 +1,36 @@
lines = [i for i in open("input.txt", 'r').read().splitlines()]
sum = 0
sum2 = 0
for l in lines:
match(l):
case "A X":
sum += 4
sum2 += 3
case "A Y":
sum += 8
sum2 += 4
case "A Z":
sum += 3
sum2 += 8
case "B X":
sum += 1
sum2 += 1
case "B Y":
sum += 5
sum2 += 5
case "B Z":
sum += 9
sum2 += 9
case "C X":
sum += 7
sum2 += 2
case "C Y":
sum += 2
sum2 += 6
case "C Z":
sum += 6
sum2 += 7
print(sum)
print(sum2)

File diff suppressed because it is too large Load Diff

@ -0,0 +1,20 @@
lines = [i for i in open("input.txt", 'r').read().splitlines()]
sum = 0
for l in lines:
first = ""
firstFound = False
last = ""
lastFound = False
for i in range(len(l)):
if not firstFound and l[i].isnumeric():
first = l[i]
firstFound = True
if not lastFound and l[-i-1].isnumeric():
last = l[-i-1]
lastFound = True
if firstFound and lastFound:
continue
sum += int(first + last)
print(sum)

@ -0,0 +1,32 @@
lines = [i for i in open("input.txt", 'r').read().splitlines()]
sum = 0
words = ["zero", "one", "two", "three", "four", "five", "six", "seven", "eight", "nine"]
for l in lines:
first = ""
firstFound = False
last = ""
lastFound = False
n = len(l)
for i in range(n):
if not firstFound and l[i].isnumeric():
first = l[i]
firstFound = True
if not lastFound and l[-i-1].isnumeric():
last = l[-i-1]
lastFound = True
for j in range(len(words)):
m = len(words[j])
if not firstFound and l[i:i+m] == words[j]:
first = str(j)
firstFound = True
if not lastFound and l[-(i+m):n-i] == words[j]:
last = str(j)
lastFound = True
if firstFound and lastFound:
break
s = first + last
sum += int(s)
print(sum)

File diff suppressed because it is too large Load Diff

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

@ -1,10 +1,11 @@
my solutions for the [Advent of Code](https://adventofcode.com/)
in progress:\
2021 (python)
2021: 12/25\
2022: 1/25\
2023: 1/25
planned:\
2022 (rust)\
2020\
2019\
2018\

Loading…
Cancel
Save