πŸŽ„ Advent of code 2025 in F# - day 02

In this video, the creator solves Day 2 of Advent of Code 2025 in F# by identifying invalid IDs based on repeated substrings, first handling exact double repeats and then extending to any repeated sequences. They implement and test brute force solutions using string chunking and recursion, acknowledging performance trade-offs while successfully completing both parts of the challenge.

In this video, the creator tackles Day 2 of Advent of Code 2025 using F#. They start by discussing the problem, which involves identifying invalid IDs in given ranges. An invalid ID is defined as one that consists of the same substring repeated twice consecutively. The creator begins by parsing the input data, converting ranges into lists of IDs, and then checking each ID by splitting it into two halves to see if both halves are identical. They implement this initial solution using list comprehensions and string manipulation functions in F#.

After verifying the initial approach works for the example input, the creator moves on to handle the full input data. They note that the brute force method is not the most efficient but is sufficient for the problem at hand. They also add some basic testing to ensure the solution remains correct as they proceed. The creator encounters some minor issues with input formatting and IDE behavior but resolves them quickly and successfully runs the solution for part one, confirming the results are correct.

For part two, the problem becomes more complex: an ID is now invalid if it consists of any sequence of digits repeated at least twice, not just exactly twice. This means IDs like β€œ111” or β€œ999” are also invalid. The creator realizes that their previous approach of splitting the string in half is insufficient. They explore a more exhaustive method that checks for repeated substrings of varying lengths by chunking the string into segments and verifying if all chunks are identical. This involves recursively checking all possible chunk sizes.

The creator implements a new function that chunks the string by different sizes and checks if all chunks are the same, indicating an invalid ID. They test this function with various examples to ensure correctness. They also discuss some performance considerations, such as filtering out strings with odd lengths, but realize this approach is flawed for part two since some invalid IDs have odd lengths. Despite the brute force nature of the solution, the creator accepts the performance trade-off, noting that the solution runs in a reasonable amount of time.

In conclusion, the creator successfully solves both parts of Day 2’s puzzle using F#. They reflect on the brute force approach’s simplicity and effectiveness, even if it is not the most optimized. The video ends with an invitation for viewers to share alternative, more performant solutions in the comments. The creator expresses enthusiasm for continuing the Advent of Code challenge and looks forward to tackling the next day’s puzzle.