added year folder

This commit is contained in:
Jake Pullen
2023-12-01 09:17:58 +00:00
parent 8bdfa1b167
commit 53d5cd8f59
125 changed files with 1 additions and 1 deletions
+1000
View File
File diff suppressed because it is too large Load Diff
+42
View File
@@ -0,0 +1,42 @@
import re
with open('advent_of_code_2023\day_1\input.txt', 'r') as file:
input = file.read()
def grab_first_and_last_digit(line: str) -> (int):
'''Returns the first and last digit of the given line
input: line - string of characters
output: a 2 digit integer
example:
input: 'pqr3stu8vwx'
output: 38
'''
first_digit = re.findall(r'\d', line)[0]
last_digit = re.findall(r'\d', line)[-1]
return int(first_digit + last_digit)
def day_1_solution(input:str) -> int:
'''Returns the sum of the first and last digit of each line
input: input - string of characters
output: an integer
example:
input: '1abc2\npqr3stu8vwx\na1b2c3d4e5f\ntreb7uchet'
output: 48
'''
list = []
for line in input.split('\n'):
list.append(grab_first_and_last_digit(line))
return sum(list)
test_input = '1abc2\npqr3stu8vwx\na1b2c3d4e5f\ntreb7uchet'
day_1_test = day_1_solution(test_input)
print(day_1_test)
assert day_1_test == 142
day_1_answer = day_1_solution(input)
print(day_1_answer)
+70
View File
@@ -0,0 +1,70 @@
import re
with open('advent_of_code_2023\day_1\input.txt', 'r') as file:
input = file.read()
def text_to_num(line: str) -> str:
'''Returns the line with the text numbers replaced with digits
input: line - string of characters
output: a string
example:
input: 'eightwothree'
output: '8wo3'
'''
text_to_num = {
"zero": "0",
"one": "one1one",
"two": "two2two",
"three": "three3three",
"four": "four4four",
"five": "five5five",
"six": "six6six",
"seven": "seven7seven",
"eight": "eight8eight",
"nine": "nine9nine"
}
#replace a text number with a digit surrounded by the same text numberm to resolve overlaps
for key, value in text_to_num.items():
if key in line:
line = line.replace(key, value)
return line
def grab_first_and_last_digit(line: str) -> (int):
'''Returns the first and last digit of the given line
input: line - string of characters
output: a 2 digit integer
example:
input: 'pqr3stu8vwx'
output: 38
'''
first_digit = re.findall(r'\d', line)[0]
last_digit = re.findall(r'\d', line)[-1]
return int(first_digit + last_digit)
def day_1_solution(input:str) -> int:
'''Returns the sum of the first and last digit of each line
input: input - string of characters
output: an integer
example:
input: '1abc2\npqr3stu8vwx\na1b2c3d4e5f\ntreb7uchet'
output: 48
'''
list = []
for line in input.split('\n'):
line = text_to_num(line)
list.append(grab_first_and_last_digit(line))
return sum(list)
test_input = 'two1nine\neightwothree\nabcone2threexyz\nxtwone3four\n4nineeightseven2\nzoneight234\n7pqrstsixteen'
day_1_test = day_1_solution(test_input)
print(day_1_test)
assert day_1_test == 281
day_1_answer = day_1_solution(input)
print(day_1_answer)
+44
View File
@@ -0,0 +1,44 @@
# Day 1 Puzzle Text.
--- Day 1: Trebuchet?! ---
Something is wrong with global snow production, and you've been selected to take a look. The Elves have even given you a map; on it, they've used stars to mark the top fifty locations that are likely to be having problems.
You've been doing this long enough to know that to restore snow operations, you need to check all fifty stars by December 25th.
Collect stars by solving puzzles. Two puzzles will be made available on each day in the Advent calendar; the second puzzle is unlocked when you complete the first. Each puzzle grants one star. Good luck!
You try to ask why they can't just use a weather machine ("not powerful enough") and where they're even sending you ("the sky") and why your map looks mostly blank ("you sure ask a lot of questions") and hang on did you just say the sky ("of course, where do you think snow comes from") when you realize that the Elves are already loading you into a trebuchet ("please hold still, we need to strap you in").
As they're making the final adjustments, they discover that their calibration document (your puzzle input) has been amended by a very young Elf who was apparently just excited to show off her art skills. Consequently, the Elves are having trouble reading the values on the document.
The newly-improved calibration document consists of lines of text; each line originally contained a specific calibration value that the Elves now need to recover. On each line, the calibration value can be found by combining the first digit and the last digit (in that order) to form a single two-digit number.
For example:
```
1abc2
pqr3stu8vwx
a1b2c3d4e5f
treb7uchet
```
In this example, the calibration values of these four lines are 12, 38, 15, and 77. Adding these together produces 142.
Consider your entire calibration document. What is the sum of all of the calibration values?
--- Part Two ---
Your calculation isn't quite right. It looks like some of the digits are actually spelled out with letters: one, two, three, four, five, six, seven, eight, and nine also count as valid "digits".
Equipped with this new information, you now need to find the real first and last digit on each line. For example:
```
two1nine
eightwothree
abcone2threexyz
xtwone3four
4nineeightseven2
zoneight234
7pqrstsixteen
```
In this example, the calibration values are 29, 83, 13, 24, 42, 14, and 76. Adding these together produces 281.
What is the sum of all of the calibration values?
+1
View File
@@ -0,0 +1 @@
Paste any inputs into this file.
+6
View File
@@ -0,0 +1,6 @@
import os
with open('advent_of_code_2023\day_10\input.txt', 'r') as file:
input = file.read()
print(input)
+6
View File
@@ -0,0 +1,6 @@
import os
with open('advent_of_code_2023\day_10\input.txt', 'r') as file:
input = file.read()
print(input)
+1
View File
@@ -0,0 +1 @@
# Day 10 Puzzle Text.
+6
View File
@@ -0,0 +1,6 @@
import os
with open('advent_of_code_2023\day_10\input.txt', 'r') as file:
input = file.read()
print(input)
+1
View File
@@ -0,0 +1 @@
Paste any inputs into this file.
+6
View File
@@ -0,0 +1,6 @@
import os
with open('advent_of_code_2023\day_11\input.txt', 'r') as file:
input = file.read()
print(input)
+6
View File
@@ -0,0 +1,6 @@
import os
with open('advent_of_code_2023\day_11\input.txt', 'r') as file:
input = file.read()
print(input)
+1
View File
@@ -0,0 +1 @@
# Day 11 Puzzle Text.
+6
View File
@@ -0,0 +1,6 @@
import os
with open('advent_of_code_2023\day_11\input.txt', 'r') as file:
input = file.read()
print(input)
+1
View File
@@ -0,0 +1 @@
Paste any inputs into this file.
+6
View File
@@ -0,0 +1,6 @@
import os
with open('advent_of_code_2023\day_12\input.txt', 'r') as file:
input = file.read()
print(input)
+6
View File
@@ -0,0 +1,6 @@
import os
with open('advent_of_code_2023\day_12\input.txt', 'r') as file:
input = file.read()
print(input)
+1
View File
@@ -0,0 +1 @@
# Day 12 Puzzle Text.
+6
View File
@@ -0,0 +1,6 @@
import os
with open('advent_of_code_2023\day_12\input.txt', 'r') as file:
input = file.read()
print(input)
+1
View File
@@ -0,0 +1 @@
Paste any inputs into this file.
+6
View File
@@ -0,0 +1,6 @@
import os
with open('advent_of_code_2023\day_13\input.txt', 'r') as file:
input = file.read()
print(input)
+6
View File
@@ -0,0 +1,6 @@
import os
with open('advent_of_code_2023\day_13\input.txt', 'r') as file:
input = file.read()
print(input)
+1
View File
@@ -0,0 +1 @@
# Day 13 Puzzle Text.
+6
View File
@@ -0,0 +1,6 @@
import os
with open('advent_of_code_2023\day_13\input.txt', 'r') as file:
input = file.read()
print(input)
+1
View File
@@ -0,0 +1 @@
Paste any inputs into this file.
+6
View File
@@ -0,0 +1,6 @@
import os
with open('advent_of_code_2023\day_14\input.txt', 'r') as file:
input = file.read()
print(input)
+6
View File
@@ -0,0 +1,6 @@
import os
with open('advent_of_code_2023\day_14\input.txt', 'r') as file:
input = file.read()
print(input)
+1
View File
@@ -0,0 +1 @@
# Day 14 Puzzle Text.
+6
View File
@@ -0,0 +1,6 @@
import os
with open('advent_of_code_2023\day_14\input.txt', 'r') as file:
input = file.read()
print(input)
+1
View File
@@ -0,0 +1 @@
Paste any inputs into this file.
+6
View File
@@ -0,0 +1,6 @@
import os
with open('advent_of_code_2023\day_15\input.txt', 'r') as file:
input = file.read()
print(input)
+6
View File
@@ -0,0 +1,6 @@
import os
with open('advent_of_code_2023\day_15\input.txt', 'r') as file:
input = file.read()
print(input)
+1
View File
@@ -0,0 +1 @@
# Day 15 Puzzle Text.
+6
View File
@@ -0,0 +1,6 @@
import os
with open('advent_of_code_2023\day_15\input.txt', 'r') as file:
input = file.read()
print(input)
+1
View File
@@ -0,0 +1 @@
Paste any inputs into this file.
+6
View File
@@ -0,0 +1,6 @@
import os
with open('advent_of_code_2023\day_16\input.txt', 'r') as file:
input = file.read()
print(input)
+6
View File
@@ -0,0 +1,6 @@
import os
with open('advent_of_code_2023\day_16\input.txt', 'r') as file:
input = file.read()
print(input)
+1
View File
@@ -0,0 +1 @@
# Day 16 Puzzle Text.
+6
View File
@@ -0,0 +1,6 @@
import os
with open('advent_of_code_2023\day_16\input.txt', 'r') as file:
input = file.read()
print(input)
+1
View File
@@ -0,0 +1 @@
Paste any inputs into this file.
+6
View File
@@ -0,0 +1,6 @@
import os
with open('advent_of_code_2023\day_17\input.txt', 'r') as file:
input = file.read()
print(input)
+6
View File
@@ -0,0 +1,6 @@
import os
with open('advent_of_code_2023\day_17\input.txt', 'r') as file:
input = file.read()
print(input)
+1
View File
@@ -0,0 +1 @@
# Day 17 Puzzle Text.
+6
View File
@@ -0,0 +1,6 @@
import os
with open('advent_of_code_2023\day_17\input.txt', 'r') as file:
input = file.read()
print(input)
+1
View File
@@ -0,0 +1 @@
Paste any inputs into this file.
+6
View File
@@ -0,0 +1,6 @@
import os
with open('advent_of_code_2023\day_18\input.txt', 'r') as file:
input = file.read()
print(input)
+6
View File
@@ -0,0 +1,6 @@
import os
with open('advent_of_code_2023\day_18\input.txt', 'r') as file:
input = file.read()
print(input)
+1
View File
@@ -0,0 +1 @@
# Day 18 Puzzle Text.
+6
View File
@@ -0,0 +1,6 @@
import os
with open('advent_of_code_2023\day_18\input.txt', 'r') as file:
input = file.read()
print(input)
+1
View File
@@ -0,0 +1 @@
Paste any inputs into this file.
+6
View File
@@ -0,0 +1,6 @@
import os
with open('advent_of_code_2023\day_19\input.txt', 'r') as file:
input = file.read()
print(input)
+6
View File
@@ -0,0 +1,6 @@
import os
with open('advent_of_code_2023\day_19\input.txt', 'r') as file:
input = file.read()
print(input)
+1
View File
@@ -0,0 +1 @@
# Day 19 Puzzle Text.
+6
View File
@@ -0,0 +1,6 @@
import os
with open('advent_of_code_2023\day_19\input.txt', 'r') as file:
input = file.read()
print(input)
+1
View File
@@ -0,0 +1 @@
Paste any inputs into this file.
+6
View File
@@ -0,0 +1,6 @@
import os
with open('advent_of_code_2023\day_2\input.txt', 'r') as file:
input = file.read()
print(input)
+6
View File
@@ -0,0 +1,6 @@
import os
with open('advent_of_code_2023\day_2\input.txt', 'r') as file:
input = file.read()
print(input)
+1
View File
@@ -0,0 +1 @@
# Day 2 Puzzle Text.
+6
View File
@@ -0,0 +1,6 @@
import os
with open('advent_of_code_2023\day_2\input.txt', 'r') as file:
input = file.read()
print(input)
+1
View File
@@ -0,0 +1 @@
Paste any inputs into this file.
+6
View File
@@ -0,0 +1,6 @@
import os
with open('advent_of_code_2023\day_20\input.txt', 'r') as file:
input = file.read()
print(input)
+6
View File
@@ -0,0 +1,6 @@
import os
with open('advent_of_code_2023\day_20\input.txt', 'r') as file:
input = file.read()
print(input)
+1
View File
@@ -0,0 +1 @@
# Day 20 Puzzle Text.
+6
View File
@@ -0,0 +1,6 @@
import os
with open('advent_of_code_2023\day_20\input.txt', 'r') as file:
input = file.read()
print(input)
+1
View File
@@ -0,0 +1 @@
Paste any inputs into this file.
+6
View File
@@ -0,0 +1,6 @@
import os
with open('advent_of_code_2023\day_21\input.txt', 'r') as file:
input = file.read()
print(input)
+6
View File
@@ -0,0 +1,6 @@
import os
with open('advent_of_code_2023\day_21\input.txt', 'r') as file:
input = file.read()
print(input)
+1
View File
@@ -0,0 +1 @@
# Day 21 Puzzle Text.
+6
View File
@@ -0,0 +1,6 @@
import os
with open('advent_of_code_2023\day_21\input.txt', 'r') as file:
input = file.read()
print(input)
+1
View File
@@ -0,0 +1 @@
Paste any inputs into this file.
+6
View File
@@ -0,0 +1,6 @@
import os
with open('advent_of_code_2023\day_22\input.txt', 'r') as file:
input = file.read()
print(input)
+6
View File
@@ -0,0 +1,6 @@
import os
with open('advent_of_code_2023\day_22\input.txt', 'r') as file:
input = file.read()
print(input)
+1
View File
@@ -0,0 +1 @@
# Day 22 Puzzle Text.
+6
View File
@@ -0,0 +1,6 @@
import os
with open('advent_of_code_2023\day_22\input.txt', 'r') as file:
input = file.read()
print(input)
+1
View File
@@ -0,0 +1 @@
Paste any inputs into this file.
+6
View File
@@ -0,0 +1,6 @@
import os
with open('advent_of_code_2023\day_23\input.txt', 'r') as file:
input = file.read()
print(input)
+6
View File
@@ -0,0 +1,6 @@
import os
with open('advent_of_code_2023\day_23\input.txt', 'r') as file:
input = file.read()
print(input)
+1
View File
@@ -0,0 +1 @@
# Day 23 Puzzle Text.
+6
View File
@@ -0,0 +1,6 @@
import os
with open('advent_of_code_2023\day_23\input.txt', 'r') as file:
input = file.read()
print(input)
+1
View File
@@ -0,0 +1 @@
Paste any inputs into this file.
+6
View File
@@ -0,0 +1,6 @@
import os
with open('advent_of_code_2023\day_24\input.txt', 'r') as file:
input = file.read()
print(input)
+6
View File
@@ -0,0 +1,6 @@
import os
with open('advent_of_code_2023\day_24\input.txt', 'r') as file:
input = file.read()
print(input)
+1
View File
@@ -0,0 +1 @@
# Day 24 Puzzle Text.
+6
View File
@@ -0,0 +1,6 @@
import os
with open('advent_of_code_2023\day_24\input.txt', 'r') as file:
input = file.read()
print(input)
+1
View File
@@ -0,0 +1 @@
Paste any inputs into this file.
+6
View File
@@ -0,0 +1,6 @@
import os
with open('advent_of_code_2023\day_25\input.txt', 'r') as file:
input = file.read()
print(input)
+6
View File
@@ -0,0 +1,6 @@
import os
with open('advent_of_code_2023\day_25\input.txt', 'r') as file:
input = file.read()
print(input)
+1
View File
@@ -0,0 +1 @@
# Day 25 Puzzle Text.
+6
View File
@@ -0,0 +1,6 @@
import os
with open('advent_of_code_2023\day_25\input.txt', 'r') as file:
input = file.read()
print(input)
+1
View File
@@ -0,0 +1 @@
Paste any inputs into this file.
+6
View File
@@ -0,0 +1,6 @@
import os
with open('advent_of_code_2023\day_3\input.txt', 'r') as file:
input = file.read()
print(input)
+6
View File
@@ -0,0 +1,6 @@
import os
with open('advent_of_code_2023\day_3\input.txt', 'r') as file:
input = file.read()
print(input)
+1
View File
@@ -0,0 +1 @@
# Day 3 Puzzle Text.
+6
View File
@@ -0,0 +1,6 @@
import os
with open('advent_of_code_2023\day_3\input.txt', 'r') as file:
input = file.read()
print(input)
+1
View File
@@ -0,0 +1 @@
Paste any inputs into this file.
+6
View File
@@ -0,0 +1,6 @@
import os
with open('advent_of_code_2023\day_4\input.txt', 'r') as file:
input = file.read()
print(input)
+6
View File
@@ -0,0 +1,6 @@
import os
with open('advent_of_code_2023\day_4\input.txt', 'r') as file:
input = file.read()
print(input)
+1
View File
@@ -0,0 +1 @@
# Day 4 Puzzle Text.
+6
View File
@@ -0,0 +1,6 @@
import os
with open('advent_of_code_2023\day_4\input.txt', 'r') as file:
input = file.read()
print(input)
+1
View File
@@ -0,0 +1 @@
Paste any inputs into this file.

Some files were not shown because too many files have changed in this diff Show More