Quellcode durchsuchen

Simpler, still wrong for part2

Piotr Czajkowski vor 2 Wochen
Ursprung
Commit
1958cb3979
1 geänderte Dateien mit 12 neuen und 14 gelöschten Zeilen
  1. 12 14
      01/code.go

+ 12 - 14
01/code.go

@@ -49,31 +49,23 @@ func parts(rotations []Rotation) (int, int) {
 	dial := 50
 
 	for _, rotation := range rotations {
+		changed := rotation.Clicks / 100
+		left := rotation.Clicks % 100
+
 		if rotation.Direction == 'L' {
-			dial -= rotation.Clicks
+			dial -= left
 		} else {
-			dial += rotation.Clicks
+			dial += left
 		}
 
 		if dial > 100 {
-			passedZeros += dial / 100
-			if dial%100 == 0 {
-				passedZeros--
-			}
+			passedZeros++
 		}
 
 		if dial < 0 {
-			if abs(dial) > 100 {
-				passedZeros += abs(dial) / 100
-			}
-
 			if rotation.Clicks != abs(dial) {
 				passedZeros++
 			}
-
-			if dial%100 == 0 {
-				passedZeros--
-			}
 		}
 
 		dial %= 100
@@ -82,8 +74,14 @@ func parts(rotations []Rotation) (int, int) {
 		}
 
 		if dial == 0 {
+			if changed > 0 {
+				changed -= 1
+			}
+
 			zeros++
 		}
+
+		passedZeros += changed
 	}
 
 	return zeros, passedZeros