About Advent of Code
The amazing puzzles put on at Advent of Code are back for 2024, see https://adventofcode.com/2024. The puzzles are hand crafted to have some twists that makes them harder to solve with a simple code generator. Input data is hand crafted with clever details and tie ins between the days.
Return Back Often
Check back on this Substack for more content each day. The goal for writing about each day is to provide enough info about the programming constructs without spoiling the puzzle aspects.
Overview
Day 1 introduces you to the idea of the challenge and focuses on iteration, the definition of math terms, arrays and dictionaries.
Concepts
We can iterate each line in a file and parse out multiple numbers from each line.
Arrays of numbers can be sorted in an arbitrary order such as ascending or descending
The difference of two numbers is positive so we take the absolute value of subtracting one number with another.
This removes the need to do the subtraction is a specific order
We can gather a unique count of each item in a collection using a dictionary
Multiple additions of the same number is equivalent to multiplication
Programming Tasks
Use these generic tasks to translate operations into your language of choice
Read each line in a file
Parse integers separated by a delimiter
Sort an array in ascending order
Iterate over items in an array
Access array elements by index
Count the number of times an item has occurred using a dictionary data structure
Resources
Advent of Code tips and solutions https://github.com/ccozad/advent-of-code
Read lines in a text file (JavaScript) https://nodejs.org/en/learn/manipulating-files/reading-files-with-nodejs
Split a string based on a delimiter (JavaScript) https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/String/split
Parse an integer (JavaScript) https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/parseInt
Calculate the absolute value of a number (JavaScript) https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Math/abs
Sort an array (JavaScript) https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array/sort