Piotr Czajkowski 21 giờ trước cách đây
mục cha
commit
ad1dd585fa
1 tập tin đã thay đổi với 8 bổ sung6 xóa
  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)