Expand description

This is my solution for Advent of Code - Day 5: If You Give A Seed A Fertilizer

Given input representing a list of Seed ids and an Almanac of mappings between ids in pairs of Categorys. Transform the Seed ids to Location ids and find the lowest Location id to solve the puzzle.

The parsing starts with parse_input, which delegates to parse_seeds, parse_almanac, parse_header, and parse_range.

The seed ids are interpreted for part one using ids_as_single_seeds, and part two with ids_to_ranges. These seed ranges are turned into the minimum location by find_nearest_location, using progress_id_ranges_to_category and progress_id_range.

Structs

  • A range of ids to modify when applying the mapping for an AlmanacSection
  • A mapping from one category of ids to another. Ranges are stored sorted by starting source id
  • IdRange 🔒
    A range of ids in a category that should be planted

Enums

  • Category 🔒
    The possible categories of id

Functions

  • Apply all almanac mappings, return the start of the lowest resulting range
  • For part one each seed is a single id, which can be represented as a range of length 1
  • For part two each pair of numbers represents a range, in the format start length
  • Each almanac section is a single header line, then one line per id mapping
  • Parse a header in the format seed-to-soil map: into source and destination categories
  • Split and parse the puzzle input into the list of seeds and the almanac specification. The seeds and each section are delimited by blank lines.
  • Parse a range of id mappings, three space-separated numbers in the order destination_start source_start length
  • Parse the list of seeds to numeric ids
  • Take a single range of ids to plant in one category and apply the relevant mapping from the almanac.
  • Recursively advance a list of category ids until a specific category is reached
  • The entry point for running the solutions with the ‘real’ puzzle input.

Type Aliases

  • Almanac 🔒
    A collection of category mappings grouped by source category