Răsfoiți Sursa

Less is better

Piotr Czajkowski 3 săptămâni în urmă
părinte
comite
4aecbd23e7
1 a modificat fișierele cu 12 adăugiri și 16 ștergeri
  1. 12 16
      01/code.go

+ 12 - 16
01/code.go

@@ -52,25 +52,21 @@ func parts(rotations []Rotation) (int, int) {
 		changed := rotation.Clicks / 100
 		move := rotation.Clicks % 100
 
-		if rotation.Direction == 'L' {
-			dial -= move
-		} else {
-			dial += move
-		}
-
-		if dial > 100 {
-			passedZeros++
-		}
+		if move > 0 {
+			if rotation.Direction == 'L' {
+				dial -= move
+			} else {
+				dial += move
+			}
 
-		if dial < 0 {
-			if move != abs(dial) {
-				passedZeros++
+			if dial > 100 || dial < 0 && move != abs(dial) {
+				changed++
 			}
-		}
 
-		dial %= 100
-		if dial < 0 {
-			dial += 100
+			dial %= 100
+			if dial < 0 {
+				dial += 100
+			}
 		}
 
 		if dial == 0 {