package main import ( "fmt" "strings" "codeflow.dananglin.me.uk/apollo/advent-of-code/internal/common" ) const ( seedToSoilMap = "seed-to-soil map" soilToFertilizerMap = "soil-to-fertilizer map" fertilizerToWaterMap = "fertilizer-to-water map" waterToLightMap = "water-to-light map" lightToTemperatureMap = "light-to-temperature map" temperatureToHumidityMap = "temperature-to-humidity map" humidityToLocationMap = "humidity-to-location map" ) type almanac struct { seeds []int seedToSoil map[int]int soilToFertilizer map[int]int fertilizerToWater map[int]int waterToLight map[int]int lightToTemperature map[int]int temperatureToHumidity map[int]int humidityToLocation map[int]int } func parseAlmanac(contents []string) (almanac, error) { // Assumption: The first line always contains the seed numbers. An error is returned // if this is not the case or if the format is all wrong. seeds, err := parseSeedNums(contents[0]) if err != nil { return almanac{}, fmt.Errorf("unable to parse the seed numbers; %w", err) } // mapLines = []string{} // loop while contents > 0 // if line is blank // if map lines > 0 -> parse map and populate relevant field // mapLines = []string{} // else // if first rune is digit, add line to mapLines: // else get map name output := almanac{ seeds: seeds, } return output, nil } func parseSeedNums(seedStr string) ([]int, error) { expectedPrefix := "seeds:" if !strings.HasPrefix(seedStr, expectedPrefix) { return nil, fmt.Errorf("%q does not begin with %s", seedStr, expectedPrefix) } seedStr = seedStr[strings.Index(seedStr, ":")+1:] seeds, err := common.ParseIntList(seedStr) if err != nil { return nil, fmt.Errorf("unable to parse the seed numbers from %q; %w", seedStr, err) } return seeds, nil } func parseMap(mapLines []string) (map[int]int, error) { //var mapMatrix [][]int return nil, nil }