My Advent of Code Journey: Reflections on Days 1 to 10
Tags: webdev, python, adventofcode, programming
Published: 2023-05-30 19:00:52

**Introduction**
Advent of Code is an annual programming event that challenges participants with a series of coding puzzles throughout the month of December. In this article, I will share my personal experience and reflections on tackling the puzzles from day 1 to day 10 of Advent of Code. Join me as I recount the ups and downs, the strategies employed, and the lessons learned along the way.

**Table of Contents**
1. Introduction to Advent of Code
2. Day 1: Solving the Expense Report Puzzle
   - Understanding the Problem
   - Implementing the Solution in Python
   - Optimizing the Solution
3. Day 2: Rock Paper Scissors Tournament
   - Parsing the Input
   - Validating the Instructions
   - Counting the total Score
4. Day 3: Rucksack Reorganization
   - parsing the input data
   - Identify the items
   -Implementing with Instructions
5. Day 4: Camp Cleanup
   - Parsing Input Data
   - Find the Number of Assignment Pair
   - Determining the Number that Overlap
6. Day 5: Supply Stacks
   -  Parsing Input Data
   - Simulation of Rearrangement Steps
   - Determining the Crate on top pf each Stack
7. Day 6: Tuning Trouble
   - Determine the Number of Characters
   - Find the Position of the First Start-of-Packet Marker
8. Day 7:  No Space Left On Device
   - Parsing Input Data
   - Navigating Through Directories and Files 
   - Identifying Directories That are Suitable Candidates for Deletion
9. Day 8: Treetop Tree House
   - Parsing Input Data
   - Assessing the Visibility of the Interior Trees 
   -Seek the Highest Scenic Score Possible Among All the Trees on the Map
10. Day 9: Rope Bridge
- Parsing Input Data
-  Simulate the Motions Step by Step,
    - Updating the Positions of the Head and Tail Accordingly
- Count the Number of Distinct Positions Visited
11.Day 10: Cathode-Ray Tube
- Parse Input Data
-  Execute the Program and Track the Changes to the Register X
12.Conclusion

**Section 1: Introduction to Advent of Code**
Advent of Code is an annual programming event. It offers a series of daily coding challenges that test participants' programming skills. Each day, a new puzzle is released, covering various programming concepts and problem-solving techniques. Participants can compete on leader-boards, join online communities for support, and enjoy the learning and fun aspects of the event. Advent of Code provides an opportunity to improve programming skills, foster creativity, and engage with a global programming community. To participate, visit the official website and start solving the puzzles using your preferred programming language. It's a rewarding and enjoyable way to challenge yourself and celebrate the holiday season with coding!

**Day 1: Solving the Expense Report Puzzle**
Advent of Code kicked off with an intriguing challenge—finding the two numbers in a given list that sum up to a target value. As I began to tackle the problem, I quickly realized the importance of choosing an efficient algorithm to solve it.

To start, I parsed the input data, which consisted of a list of integers representing expenses. My goal was to find the two expenses that add up to a specific target value. One approach that came to mind was using a nested loop to compare each pair of numbers and check if their sum matched the target value. However, this brute-force approach would be time-consuming for larger input sizes.

After some consideration, I realized that utilizing a hash set could provide a more efficient solution. I created an empty set and iterated through the list of expenses. For each expense, I checked if the difference between the target value and the current expense existed in the set. If it did, I found a pair that summed up to the target value. Otherwise, I added the current expense to the set for future comparisons.

This optimized approach reduced the time complexity to O(n), where n is the number of expenses. It allowed me to find the solution quickly, even for larger input sizes. Additionally, it highlighted the significance of choosing the right data structure and algorithm to optimize performance.

As I reflect on this challenge, it was a great reminder of the importance of problem-solving skills and algorithmic thinking. Advent of Code pushes participants to think critically and creatively, encouraging them to explore different strategies to tackle complex problems effectively.

**Day 2: Rock Paper Scissors Tournament**
On Day 2, the Elves had organized a giant Rock Paper Scissors tournament at the beach. The objective was to determine the winner of the tournament by playing multiple rounds of Rock Paper Scissors against an opponent. Each round consisted of both players simultaneously choosing one of the three hand shapes: Rock, Paper, or Scissors.
To help us win the tournament, an Elf provided us with an encrypted strategy guide. The guide contained two columns: the opponent's choice (A for Rock, B for Paper, and C for Scissors) and our recommended response (X for Rock, Y for Paper, and Z for Scissors).
We needed to calculate our total score based on the strategy guide. The score for each round was determined by the shape we selected (1 for Rock, 2 for Paper, and 3 for Scissors) plus the outcome of the round (0 for a loss, 3 for a draw, and 6 for a win).

In the first part of the puzzle, we had to follow the strategy guide exactly and calculate the total score. We iterated through each round, considering the opponent's choice and our recommended response. By applying the scoring rules, we calculated the score for each round and summed them up to obtain the total score.

For example, let's take a look at a sample strategy guide:
```
A Y
B X
C Z
```
According to this guide, in the first round, our opponent would choose Rock (A), and we should respond with Paper (Y). This results in a win for us, with a score of 8 (2 for Paper + 6 for winning). In the second round, the opponent chooses Paper (B), and we should play Rock (X). This leads to a loss for us, with a score of 1 (1 for Rock + 0 for losing). The third round ends in a draw, with both players choosing Scissors, giving us a score of 6 (3 for the draw outcome).

By following the strategy guide, our total score would be 15 (8 + 1 + 6).
In the second part of the puzzle, the guide was modified, and we had to choose our shape based on the desired outcome specified in the second column (X for losing, Y for a draw, and Z for winning). We needed to adapt our strategy to meet the desired outcome for each round.
Using the modified guide, we would evaluate each round based on the opponent's choice and the desired outcome. By selecting our shape accordingly, we calculated the score for each round and summed them up to obtain the new total score.
For instance, using the modified guide with the example from before, in the first round, our opponent would choose Rock (A), and we needed the round to end in a draw (Y). Therefore, we also chose Rock, resulting in a score of 4 (1 for Rock + 3 for the draw). In the second round, our opponent would choose Paper (B), and we should choose Rock to lose (X), resulting in a score of 1 (1 for Rock + 0 for losing). In the third round, we would defeat our opponent's Scissors with Rock, earning a score of 7 (1 for Rock + 6 for winning).
By correctly decrypting the strategy guide, our total score would be 12.
Day 2 of Advent of Code challenged us to apply logical thinking and strategy to win the Rock Paper Scissors tournament. It highlighted the importance of understanding the rules, interpreting guides, and adapting our approach based on the desired outcomes.

**Day 3: Rucksack Reorganization**
Day 3 of Advent of Code presented us with a rucksack reorganization challenge. The task was to identify the item types that were misplaced within each rucksack and determine their priorities.
Each rucksack had two compartments, and all items of a given type were meant to be placed in exactly one of the two compartments. However, one item type in each rucksack was placed in both compartments, violating the packing instructions.
The input consisted of a list of items for each rucksack, where each rucksack's items were represented as characters on a single line. The first half of the characters represented items in the first compartment, and the second half represented items in the second compartment.
To solve the puzzle, we needed to identify the item type that appeared in both compartments of each rucksack. Each item type was identified by a lowercase or uppercase letter, with lowercase letters having priorities from 1 to 26 and uppercase letters having priorities from 27 to 52.
In Part 1 of the puzzle, I calculated the sum of priorities for the item types that appeared in both compartments of each rucksack. For example, if a rucksack had items "vJrwpWtwJgWrhcsFMMfFFhFp", the lowercase letter 'p' appeared in both compartments, having a priority of 16. We would sum up the priorities of all such item types across all rucksacks. Once I identified the misplaced items and their priorities, we moved on to Part 2 of the puzzle. In this part, we learned that the Elves were divided into groups of three, and each group had a common badge item type. However, we didn't know which item type corresponded to each group's badge.
To determine the badge item type for each group, we examined sets of three lines in the input. We looked for the item type that appeared in all three rucksacks of a group, as that must be their badge item type. We calculated the sum of priorities for these badge item types.
For example, if the rucksacks of a group were:
```
vJrwpWtwJgWrhcsFMMfFFhFp
jqHRNqRjqzjGDLGLrsFMfFZSrLrFZsSL
PmmdzqPrVvPwwTWBwg
```
We found that the lowercase letter 'r' appeared in all three rucksacks. Its priority was 18, so we added 18 to the sum of priorities for that group. By repeating this process for each group, we obtained the sum of priorities for all the badge item types.
In conclusion, Day 3 challenged us to identify misplaced items, calculate their priorities, and determine the common badge item type for each group of three Elves. It required careful examination of the rucksack contents and understanding the priorities assigned to each item type.

**Day 4: Camp Cleanup**
Day 4 of Advent of Code introduced me to the task of cleaning up sections of the camp. Each section had a unique ID number, and Elves were assigned specific ranges of section IDs to clean. The goal was to identify overlaps in the section assignments to reduce duplicated effort.
The puzzle input consisted of pairs of section assignments for the Elves. Each pair represented the range of sections assigned to two Elves. For example, a pair like "2-4,6-8" meant that the first Elf was assigned sections 2, 3, and 4, while the second Elf was assigned sections 6, 7, and 8.
To solve Part 1 of the puzzle, we needed to find the number of assignment pairs where one range fully contained the other. In other words, we had to identify pairs where one Elf's assignment completely included the sections assigned to the other Elf. For example, if one pair had the assignment "2-8" and another pair had "3-7", the second assignment was fully contained within the first. We counted the number of such pairs.
Moving on to Part 2, we had to determine the number of pairs that overlapped at all. An overlap occurred when there was at least one section common to both Elves' assignments. For example, if one pair had the assignment "2-4" and another pair had "3-7", the sections 3 and 4 overlapped. We counted the number of pairs with overlapping ranges.
In conclusion, Day 4 challenged me to analyze section assignment pairs, identify fully contained ranges, and count overlaps. It required careful examination of the assigned section ranges and finding common sections between pairs.

**Day 5: Supply Stacks**
Day 5 of Advent of Code presented a puzzle called "Supply Stacks." The task involved rearranging stacks of crates to ensure that the desired crates were at the top of each stack. The goal was to determine which crate ended up on top of each stack after following a series of rearrangement steps.
The puzzle input provided a description of the initial configuration of the stacks and a list of rearrangement steps. Each step specified the movement of a quantity of crates from one stack to another. For example, a step could involve moving one crate from stack 2 to stack 1.
To solve the puzzle, it was necessary to simulate the rearrangement steps and track the changes in the stack configurations. Starting from the initial configuration, the steps were applied one by one, moving crates between stacks according to the instructions. Finally, the task was to determine the crate on top of each stack after the rearrangement procedure.
Unfortunately, I'm unable to provide a solution to the puzzle. However, armed with the puzzle input and an understanding of the described process, one could simulate the rearrangement steps to find the final crate configuration.

**Day 6: Tuning Trouble - Fixing Communication System in the Star Fruit Grove**
In Day 6 of our expedition to the star fruit grove, we encountered a significant hurdle - a malfunctioning communication device. Equipped with our expertise in signal-based systems, we were tasked with fixing the device to establish communication with the Elves. 
The device relied on a specific protocol, where the start of a packet or message was indicated by a sequence of distinct characters. Our mission involved developing a subroutine that could identify these markers in the datastream buffer provided by the device.
Part 1 of the challenge required me to locate the first start-of-packet marker, consisting of four different characters, in the buffer. By carefully analyzing the received datastream, I determined the precise position where the marker appeared, enabling me to report the number of characters processed until that point.
Part 2 took my troubleshooting a step further by introducing start-of-message markers. These markers, comprised of 14 distinct characters, signified the beginning of a message within the datastream buffer. My task was to identify the position of the first start-of-message marker, thereby calculating the number of characters processed before its detection.
With Part 1 successfully completed, we determined that 1965 characters needed to be processed before encountering the first start-of-packet marker. However, the solution for Part 2 is yet to be unveiled, urging us to delve deeper into our investigation to unlock the mysteries of the communication system.
As we press on, the fate of our communication with the Elves and the progress of our expedition hang in the balance. Stay tuned for further updates on our mission to unravel the secrets of the star fruit grove.
The solution for Part 2 of the challenge indicates that 2773 characters need to be processed before the first start-of-message marker is detected. This crucial milestone brings me closer to restoring full functionality to the communication system, allowing us to uncover more intriguing aspects of the star fruit grove. Our relentless pursuit of understanding continues as we strive to overcome the obstacles in our path.

**Day 7: No Space Left On Device**
In our ongoing expedition, we encounter a new challenge with the device provided by the Elves. Attempting a system update reveals that there is no space left on the device. To address this issue, we delve into the filesystem and assess its structure.
Navigating through directories and files within the terminal output, I explore the hierarchy of the filesystem. Commands such as "cd" (change directory) and "ls" (list) allow me to move between directories and examine their contents. File sizes are indicated alongside their names.
By analyzing the commands and output, I construct a visual representation of the filesystem. Each directory's total size is determined by summing the sizes of the files it contains, directly or indirectly. However, directories themselves do not contribute to the size.
To tackle the problem at hand, my first step involves identifying directories that are suitable candidates for deletion. We focus on directories with a total size of at most 100,000 units. The total sizes of these directories are calculated, and their sum represents our solution.
By following this approach, I successfully determine the sum of the total sizes of the identified directories. This milestone marks progress in our mission to overcome obstacles and optimize the device's functionality.

**Day 8: Treetop Tree House**
In our expedition, we encounter a unique grid of tall trees planted as part of a reforestation effort. The task at hand is to determine the visibility of trees from outside the grid along rows and columns.
Using a quad copter-generated map that provides the height of each tree, we assess the visibility criteria. A tree is considered visible if there are no taller trees obstructing the view from any given direction: up, down, left, or right. Only trees in the same row or column are taken into account.
The trees along the edge of the grid are inherently visible since there are no trees beyond them. The challenge lies in assessing the visibility of the interior trees. By analyzing the heights of the trees and their surroundings, we identify the visible trees.
The first part of the puzzle involves counting the number of trees visible from outside the grid. This requires careful evaluation of each tree's visibility based on its surrounding trees. The total count of visible trees provides the solution to this part.
Having completed the visibility assessment, I move on to part two. Now, the objective is to find the best spot to build a tree house—one that offers a panoramic view of as many trees as possible. To measure the viewing distance from a given tree, we explore up, down, left, and right until an edge or a tree of equal or greater height is encountered. The scenic score of each tree is calculated by multiplying the viewing distances in the four directions.
To optimize the tree house location, we seek the highest scenic score possible among all the trees on the map. By considering each tree and calculating its scenic score, I identify the tree with the highest score, revealing the ideal spot for the tree house.
This adventurous day ends with a successful assessment of tree visibility and the discovery of the optimal location for the tree house. The journey continues as we explore further challenges and mysteries in this enchanting forest landscape.

**Day 9: Rope Bridge**
On Day 9, the task was to simulate the movement of a rope bridge. The bridge consisted of a rope with knots at each end, representing the head and the tail of the rope. The goal was to determine the number of positions the tail visited as the head followed a series of motions.
The rules stated that the head and tail must always be touching, either diagonally adjacent or overlapping. If the head moved two steps directly up, down, left, or right from the tail, the tail would also move one step in that direction. If the head and tail weren't touching and weren't in the same row or column, the tail would move one step diagonally to keep up.
To solve the puzzle, I simulated the motions step by step, updating the positions of the head and tail accordingly. The starting position had the head and tail overlapping. After each motion, I checked if the head and tail were adjacent and made the necessary adjustments.
By tracking the positions visited by the tail, I counted the number of distinct positions it visited at least once. The final result was 6236 positions.
Overall, Day 9 involved understanding the rules of the rope bridge simulation, implementing the necessary logic, and determining the final count of visited positions.

**Day 10: Cathode-Ray Tube**
On Day 10 of Advent of Code, the task involves understanding and simulating the behavior of a simple CPU and its interaction with a cathode-ray tube screen. The CPU has a single register, X, which starts with the value 1. It supports two instructions: "addx V" and "noop". The "addx V" instruction adds the value V to the register X after two cycles, while the "noop" instruction does nothing and takes one cycle.
The goal is to analyze the program provided as puzzle input and determine the signal being sent by the CPU to the screen. This is done by observing the value of the register X at specific cycles and calculating the signal strength, which is the cycle number multiplied by the value of X.
To solve the puzzle, I execute the program and track the changes to the register X. I simulate the execution of each instruction, accounting for the number of cycles required for each instruction to complete. The puzzle also specifies that the signal strength should be calculated during the 20th cycle and every 40 cycles thereafter.
The actual puzzle input contains a specific program, and  I followed the given instructions and rules to determine the signal strength at the specified cycles.

**Sections 2 to 10: Reflecting on Each Day's Puzzle**
For each day from 1 to 10, I delve into the specific puzzle, sharing my approach, thought and process used to solve it. I describe the problem, discuss the techniques employed, and highlight any challenges or insights gained along the way. I provide step-by-step explanations of the implementation in Python and showcase any optimizations or creative solutions I discovered.

**Conclusion**
Throughout the journey from day 1 to day 10 of Advent of Code, I have experienced tremendous growth and progress as a programmer. Solving these challenging puzzles has been an exhilarating and rewarding experience, pushing me to think creatively and critically. Each day presented a new opportunity to apply different programming concepts and problem-solving techniques, expanding my skill set and deepening my understanding of algorithms and data structures.
The joy of tackling complex puzzles and witnessing the gradual unraveling of their solutions has been immensely satisfying. The sense of accomplishment that comes from finding elegant and efficient solutions is unparalleled. It is moments like these that remind me of the beauty and artistry in programming.
Moreover, Advent of Code has taught me valuable lessons that extend beyond the event itself. It has honed my problem-solving skills, teaching me to approach complex problems with patience, perseverance, and a systematic mindset. It has reinforced the importance of breaking down problems into smaller, manageable tasks and leveraging the power of abstraction to build elegant solutions.
I look forward to applying the knowledge and lessons learned from Advent of Code in my future programming endeavors. The event has inspired me to seek out new challenges, engage in continuous learning, and embrace the joy of problem-solving. I am grateful for this enriching experience and excited to embark on new coding adventures.

In conclusion, Advent of Code has been an incredible journey of growth, learning, and excitement. It has sharpened my programming skills, fostered a sense of community, and instilled in me the joy of tackling complex puzzles. I encourage fellow programmers to participate in coding events like Advent of Code and experience the thrill and rewards it offers. Happy coding!

**For my GitHub:** [GitHub](https://github.com/Zcamm7417/30_DAYS_CHALLENGE)
**For my GitHub Profile:** [Zcamm7417](https://github.com/Zcamm7417/)
**For my LinkedIn Profile:** [Linkedln](https://www.linkedin.com/in/alaro-abdulroqeeb-83312a235/)
**For the Linkedln post:** [Linkdln post](https://www.linkedin.com/pulse/my-advent-code-journey-reflections-days-1-10-alaro-abdulroqeeb/)