Piotr Czajkowski 1 day ago
parent
commit
ad1dd585fa
1 changed files with 8 additions and 6 deletions
  1. 8 6
      20/code.go

+ 8 - 6
20/code.go

@@ -89,16 +89,18 @@ func hike(start *Point, matrix [][]byte, xMax, yMax int, cheat bool, cheats map[
 	for len(moves) > 0 {
 		current := moves[0]
 		moves = moves[1:]
-		if matrix[current.y][current.x] == 'E' && (current.cost <= cost || cheat && current.cost < bestWithoutCheating) {
-			cost = current.cost
-			if cheat {
-				saving := bestWithoutCheating - current.cost
-				savings[saving]++
+		if matrix[current.y][current.x] == 'E' {
+			if current.cost <= cost || cheat && current.cost < bestWithoutCheating {
+				cost = current.cost
+				if cheat && current.cheatedAt != nil {
+					saving := bestWithoutCheating - current.cost
+					savings[saving]++
 
-				if current.cheatedAt != nil {
 					cheats[current.cheatedAt.key()] = true
 				}
 			}
+
+			continue
 		}
 
 		newMoves := getMoves(current, matrix, xMax, yMax, cheat, cheats)