From 8ce3db4914352761f41a50cb73e7d2cee68cb648 Mon Sep 17 00:00:00 2001 From: Jake Pullen Date: Sun, 3 Dec 2023 20:09:45 +0000 Subject: [PATCH] Fix special character position calculation --- 2023/day_3/part 1 solution.py | 34 ++++++++++++++++++++++++++++++---- 2023/day_3/puzzle_text.md | 31 ++++++++++++++++++++++++++++++- 2 files changed, 60 insertions(+), 5 deletions(-) diff --git a/2023/day_3/part 1 solution.py b/2023/day_3/part 1 solution.py index 6f21f2f..3c0ecf6 100644 --- a/2023/day_3/part 1 solution.py +++ b/2023/day_3/part 1 solution.py @@ -1,6 +1,32 @@ -import os +# with open(r'advent_of_code\2023\day_3\input.txt', 'r') as file: +# input = file.read() -with open(r'advent_of_code\2023\day_3\input.txt', 'r') as file: - input = file.read() +# print(input) -print(input) +test_input = '''467..114.. +...*...... +..35..633. +......#... +617*...... +.....+.58. +..592..... +......755. +...$.*.... +.664.598..''' + +input = test_input + +# find every special character in the input +# at the special character, look at every space around it (including diagonals) +# if there is a number, add it to the list of numbers +# at the end, add up all the numbers in the list + +# find every special character in the input +special_characters = ['$', '*', '+', '#'] +special_character_positions = [] +for row_index, row in enumerate(input.split('\n')): + for column_index, character in enumerate(row): + if character in special_characters: + special_character_positions.append((row_index, column_index)) + +print(special_character_positions) diff --git a/2023/day_3/puzzle_text.md b/2023/day_3/puzzle_text.md index 945b3ec..30d56df 100644 --- a/2023/day_3/puzzle_text.md +++ b/2023/day_3/puzzle_text.md @@ -1 +1,30 @@ -# Day 3 Puzzle Text. \ No newline at end of file +# Day 3 Puzzle Text. +--- Day 3: Gear Ratios --- +You and the Elf eventually reach a gondola lift station; he says the gondola lift will take you up to the water source, but this is as far as he can bring you. You go inside. + +It doesn't take long to find the gondolas, but there seems to be a problem: they're not moving. + +"Aaah!" + +You turn around to see a slightly-greasy Elf with a wrench and a look of surprise. "Sorry, I wasn't expecting anyone! The gondola lift isn't working right now; it'll still be a while before I can fix it." You offer to help. + +The engineer explains that an engine part seems to be missing from the engine, but nobody can figure out which one. If you can add up all the part numbers in the engine schematic, it should be easy to work out which part is missing. + +The engine schematic (your puzzle input) consists of a visual representation of the engine. There are lots of numbers and symbols you don't really understand, but apparently any number adjacent to a symbol, even diagonally, is a "part number" and should be included in your sum. (Periods (.) do not count as a symbol.) + +Here is an example engine schematic: +``` +467..114.. +...*...... +..35..633. +......#... +617*...... +.....+.58. +..592..... +......755. +...$.*.... +.664.598.. +``` +In this schematic, two numbers are not part numbers because they are not adjacent to a symbol: 114 (top right) and 58 (middle right). Every other number is adjacent to a symbol and so is a part number; their sum is 4361. + +Of course, the actual engine schematic is much larger. What is the sum of all of the part numbers in the engine schematic? \ No newline at end of file