From 0c228d270bdf72544bfc3c0aef79f621436e1910 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Da=CC=81vid=20Ne=CC=81meth=20Cs?= Date: Tue, 10 Dec 2024 09:35:52 +0100 Subject: [PATCH] 2024/10 --- 2024/Day10/Solution.cs | 18 +++++++++--------- 1 file changed, 9 insertions(+), 9 deletions(-) diff --git a/2024/Day10/Solution.cs b/2024/Day10/Solution.cs index 56a9e706..2100528a 100644 --- a/2024/Day10/Solution.cs +++ b/2024/Day10/Solution.cs @@ -16,30 +16,30 @@ class Solution : Solver { Complex Left = -1; Complex Right = 1; - public object PartOne(string input) => GetAllTrails(input).Sum(x => x.Value.Distinct().Count()); - public object PartTwo(string input) => GetAllTrails(input).Sum(x => x.Value.Count()); + public object PartOne(string input) => GetAllTrails(input).Sum(t => t.Value.Distinct().Count()); + public object PartTwo(string input) => GetAllTrails(input).Sum(t => t.Value.Count()); Dictionary> GetAllTrails(string input) { var map = GetMap(input); var trailHeads = map.Keys.Where(k => map[k] == '0'); - return GetTrailHeads(map).ToDictionary(x => x, trailHead => GetTrailsFrom(map, trailHead)); + return GetTrailHeads(map).ToDictionary(t => t, t => GetTrailsFrom(map, t)); } - IEnumerable GetTrailHeads(Map map) => map.Keys.Where(k => map[k] == '0'); + IEnumerable GetTrailHeads(Map map) => map.Keys.Where(pos => map[pos] == '0'); List GetTrailsFrom(Map map, Complex trailHead) { // standard floodfill algorithm using a queue - var points = new Queue(); - points.Enqueue(trailHead); + var positions = new Queue(); + positions.Enqueue(trailHead); var trails = new List(); - while (points.Any()) { - var point = points.Dequeue(); + while (positions.Any()) { + var point = positions.Dequeue(); if (map[point] == '9') { trails.Add(point); } else { foreach (var dir in new[] { Up, Down, Left, Right }) { if (map.GetValueOrDefault(point + dir) == map[point] + 1) { - points.Enqueue(point + dir); + positions.Enqueue(point + dir); } } }