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 2 has you checking for outliers in a series. The problem also introduces the idea of simple what if analysis to search for additional solutions.
Concepts
We can end a loop early when a failing condition in encountered
We can make a function that works on any array of numbers
We can alter the items in an array by making a copy and performing splice operations
Programming Tasks
Read each line in a file
Parse integers separated by a delimiter
Check for a change in sign
Check for a difference larger or smaller than a threshold
Break from a loop early
Use a function to repeat the same operations on different data
Copy an array and remove elements to create different variants while preserving the original array
Resources
Advent of Code tips and solutions https://github.com/ccozad/advent-of-code
Break a loop early (JavaScript) https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Statements/break
Declare a function (JavaScript) https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Statements/function
Different ways to copy an array (JavaScript) https://www.freecodecamp.org/news/how-to-clone-an-array-in-javascript-1d3183468f6a/