diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..7e99e36 --- /dev/null +++ b/.gitignore @@ -0,0 +1 @@ +*.pyc \ No newline at end of file diff --git a/Questions/Day 1.py b/Questions/Day 1.py index 329f88c..39985fa 100644 --- a/Questions/Day 1.py +++ b/Questions/Day 1.py @@ -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() \ No newline at end of file + filepath = "Data/Day1.txt" + data = load_data(filepath) + # question_1(data) + question_2(data) \ No newline at end of file