Day 1 finish + gitignore
This commit is contained in:
parent
a80d47e30a
commit
421132d482
|
@ -0,0 +1 @@
|
|||
*.pyc
|
|
@ -1,19 +1,49 @@
|
|||
from utils import load_data
|
||||
|
||||
def question_1():
|
||||
filepath = "Data/Day1.txt"
|
||||
data = load_data(filepath)
|
||||
|
||||
def question_1(data):
|
||||
sum = 0
|
||||
for line in data:
|
||||
line = "".join(filter(str.isdigit, line))
|
||||
sum += int(line[0]+line[-1])
|
||||
print(f"Answer to question 1 is: {sum}")
|
||||
|
||||
def question_2():
|
||||
def question_2(data: list[str]):
|
||||
|
||||
print(f"Answer to question 2 is: {}")
|
||||
numbers = {"one": 1,
|
||||
"two": 2,
|
||||
"three": 3,
|
||||
"four": 4,
|
||||
"five": 5,
|
||||
"six": 6,
|
||||
"seven": 7,
|
||||
"eight": 8,
|
||||
"nine": 9}
|
||||
|
||||
sum = 0
|
||||
for line in data:
|
||||
|
||||
new_word = ""
|
||||
current_word = ""
|
||||
for character in line:
|
||||
if character.isdigit():
|
||||
new_word += character
|
||||
current_word = ""
|
||||
|
||||
else:
|
||||
current_word += character
|
||||
|
||||
for number in numbers:
|
||||
if number in current_word:
|
||||
new_word += str(numbers[number])
|
||||
current_word = current_word[-1:]
|
||||
|
||||
sum += int(new_word[0] + new_word[-1])
|
||||
|
||||
|
||||
print(f"Answer to question 2 is: {sum}")
|
||||
|
||||
if __name__ == "__main__":
|
||||
# question_1()
|
||||
question_2()
|
||||
filepath = "Data/Day1.txt"
|
||||
data = load_data(filepath)
|
||||
# question_1(data)
|
||||
question_2(data)
|
Loading…
Reference in New Issue