* This blog post is a summary of this video.

Coding Challenge Solution Journey: Fixing Bugs in Advent of Code Day 3

Author: AI Coding AdventuresTime: 2024-01-03 06:25:01

Table of Contents

Introduction to the Advent of Code Day 3 Challenge

The Advent of Code is an annual event where programmers solve various coding puzzles in any programming language of their choice. This year, I have taken on the challenge of solving all 25 days worth of puzzles using only AI assistance, without writing any code myself.

For Day 3, the premise involves fixing a gondola lift which seems to have some issues getting started. We need to inspect the engine schematic diagram to identify any missing or damaged parts so the gondola can start moving properly.

The Gond Lift Puzzle Premise

The puzzle begins with entering a gond lift which is supposed to take us up to a water source. However, the lift does not seem to be moving. The engineer explains that an engine part is missing, but they don't know which one. We are given an engine schematic diagram consisting of various numbers and symbols. Any number adjacent (including diagonally) to a symbol is considered a part number. We need to sum all the part numbers to identify the missing part.

Understanding the Engine Schematic

The schematic contains symbols such as stars and circles with numbers placed around them. A number is considered a part number if it is adjacent (horizontally, vertically, or diagonally) to a symbol. For example, the numbers 4, 6, and 7 adjacent to a star in the diagram would all be part numbers. We need to sum all such part numbers to solve the first part of the puzzle.

Solving Part One of the Challenge

For the first part of the puzzle, I parsed the engine schematic into a matrix in Go code. Then I iterated through it to identify all numbers adjacent to symbols, extracted them, and summed them up.

My first attempt returned a sum that was clearly too small, so I realized my logic for extracting the part numbers was flawed. After fixing that, my code successfully returned the right sum to solve part one.

Tackling Part Two of the Challenge

Part two builds on part one by dealing with gear ratios. We now need to focus only on star symbols adjacent to exactly two numbers. Those two numbers are considered a gear, and their product is the gear ratio.

The objective is to calculate the gear ratio for every qualifying gear (star with exactly two adjacent numbers), and return the sum of all gear ratios.

I updated my code to specifically look for star symbols with two adjacent part numbers, extract them, multiply them to calculate the gear ratio, and sum the ratios up.

Debugging the Code Solution

Reviewing the Logic

When my initial solution for part two also returned an incorrect sum, I reviewed the logic to try and identify issues:

  • My code was correctly identifying stars with exactly 2 adjacent numbers
  • It was properly extracting those numbers
  • Multiplying them to calculate the individual gear ratios
  • And summing up the gear ratios

Trying Different Approaches

I tried a few different approaches to fix the bug:

  • Printed additional debug statements to inspect the output
  • Passed sample test input instead of the actual input
  • Tried different attempts using the AI assistant's code generation capability Unfortunately, none of these approaches resulted in the correct solution. I was unable to successfully solve part two of this puzzle.

Moving on to Day 4

While I could have spent more time trying to fix my solution for part two, the nature of this Advent of Code challenge requires participating programmers to move on to the next day's puzzle each day.

So after a few unsuccessful attempts at debugging the part two solution, I decided to accept the failed submission for Day 3 part two, and proceed onwards to take on the next day's challenge.


Q: What is the Advent of Code challenge?
A: The Advent of Code challenge is an annual coding challenge that presents coding puzzles each day in December. It builds in difficulty from Day 1 to Day 25.

Q: What coding language is used to solve the puzzles?
A: The puzzles are solved programmatically using coding languages like Python, GoLang and JavaScript. On Day 3, GoLang was used.

Q: What was the puzzle for Day 3 about?
A: The Day 3 puzzle involved figuring out a solution to fix a broken gond lift by analyzing a visual engine schematic and calculating part numbers and gear ratios.