From bf29a239153286ee1bb676a2414facef542f8861 Mon Sep 17 00:00:00 2001 From: Martin Zikmund Date: Sun, 15 Dec 2024 12:15:26 +0100 Subject: [PATCH] Refactor Day 15 Part 2 --- src/AdventOfCode.Puzzles/2024/15/Part2/Part2.cs | 8 ++------ 1 file changed, 2 insertions(+), 6 deletions(-) diff --git a/src/AdventOfCode.Puzzles/2024/15/Part2/Part2.cs b/src/AdventOfCode.Puzzles/2024/15/Part2/Part2.cs index d47c5d9..58d5056 100644 --- a/src/AdventOfCode.Puzzles/2024/15/Part2/Part2.cs +++ b/src/AdventOfCode.Puzzles/2024/15/Part2/Part2.cs @@ -117,7 +117,6 @@ private bool CanMove(Point position, Point direction) { var newPosition = position + direction; var currentTile = _map[position.X, position.Y]; - var newTile = _map[newPosition.X, newPosition.Y]; if (currentTile == '.') { @@ -129,6 +128,8 @@ private bool CanMove(Point position, Point direction) return false; } + var newTile = _map[newPosition.X, newPosition.Y]; + if (currentTile == '[' || currentTile == ']') { if ((currentTile == ']' && direction == (-1, 0)) || @@ -149,11 +150,6 @@ private bool CanMove(Point position, Point direction) return CanMove(newPosition, direction); } - - if (newTile == '.') - { - return true; - } if (currentTile == '@') {