advent_of_code_2024

Module day_9

source
Expand description

This is my solution for Advent of Code - Day 9: Disk Fragmenter

parse_input Marks each of the entries as a FILE or SPACE, along with caching their position on disk, and the id of the files.

calculate_checksum solves the puzzle, delegating to pack_files which calculates the final position of the files. fill_space_with_fragmentation Is the logic for filling in disk space for part 1, fill_space_without_fragmentation for part 2.

StructsΒ§

  • File πŸ”’
    A file on disk
  • Space πŸ”’
    A space on disk

EnumsΒ§

  • DiskUsage πŸ”’
    An enum to union both types of disk usage

FunctionsΒ§

  • Reduces the list of packed files to the puzzle solution
  • Part 1 space filler - split files to fully fill in every hole
  • Part 2 space filler - only move files into spaces they fit
  • pack_files πŸ”’
    The common logic for reading from both ends of the disk usage map, outputting files as their final position becomes known.
  • parse_input πŸ”’
    Turn input into alternating file/space entries. Filtering out any with size 0
  • The entry point for running the solutions with the β€˜real’ puzzle input.

Type AliasesΒ§

  • SpaceFiller πŸ”’
    This represents the difference between the parts.