using System.Collections.Generic; namespace Day5; public class Almanac { public IList Seeds { get; } = new List(); public IList<(string Source, string Destination)> Mappings { get; } = new List<(string Source, string Destination)>(); public Dictionary> MappingData { get; } = new Dictionary>(); public IList Map(IList start, string source, string destination) { var result = start; var current = source; while (current != destination) { result = MapSingle(result, current); current = Mappings.First(m => m.Source == current).Destination; } return result; } private IList MapSingle(IList start, string source) { return start .Select(num => MappingData[source].FirstOrDefault(x => x.IsMatch(num), Range.Identity).Transform(num)) .ToList(); } }