From f6f251afc3646e8eaf9b70ab4a61479cd02c3eba Mon Sep 17 00:00:00 2001 From: Olivia Appleton Date: Sun, 11 Aug 2024 17:12:10 -0500 Subject: [PATCH] Fix several wide-to-narrow errors --- java/src/main/java/euler/lib/Mathematics.java | 4 ++-- java/src/main/java/euler/p0004.java | 2 +- java/src/main/java/euler/p0034.java | 4 ++-- java/src/main/java/euler/p0076.java | 8 ++++---- 4 files changed, 9 insertions(+), 9 deletions(-) diff --git a/java/src/main/java/euler/lib/Mathematics.java b/java/src/main/java/euler/lib/Mathematics.java index 876690be..e80538e2 100644 --- a/java/src/main/java/euler/lib/Mathematics.java +++ b/java/src/main/java/euler/lib/Mathematics.java @@ -45,7 +45,7 @@ public static long nChooseR(long n, long r) { while (answer < tmp && j <= n) { while (factors[j] < 0) { tmp /= j; - factors[j] += 1; + factors[j] += (byte) 1; } j += 1; answer = tmp * i; @@ -60,7 +60,7 @@ public static long nChooseR(long n, long r) { while (j <= n) { while (factors[j] < 0) { answer /= j; - factors[j] += 1; + factors[j] += (byte) 1; } j += 1; } diff --git a/java/src/main/java/euler/p0004.java b/java/src/main/java/euler/p0004.java index 41769686..4ace1bb9 100644 --- a/java/src/main/java/euler/p0004.java +++ b/java/src/main/java/euler/p0004.java @@ -18,7 +18,7 @@ public class p0004 implements IEuler { private boolean IsPalindrome(int x) { String rep = Integer.toString(x); int length = rep.length(); - for (int i = 0; i < length; i += 1) { + for (int i = 0; i < length; i++) { if (rep.charAt(i) != rep.charAt(length - i - 1)) return false; } diff --git a/java/src/main/java/euler/p0034.java b/java/src/main/java/euler/p0034.java index e29a727d..3213a1bd 100644 --- a/java/src/main/java/euler/p0034.java +++ b/java/src/main/java/euler/p0034.java @@ -22,10 +22,10 @@ public class p0034 implements IEuler { @Override public Object answer() { int answer = 0; - for (int x = 10; x < 100000; x += 1) { + for (int x = 10; x < 100000; x++) { String xs = Integer.toString(x); int sum = 0; - for (byte i = 0; i < xs.length(); i += 1) + for (byte i = 0; i < xs.length(); i++) sum += (int) Mathematics.factorial(xs.charAt(i) - '0'); if (sum == x) answer += x; diff --git a/java/src/main/java/euler/p0076.java b/java/src/main/java/euler/p0076.java index 8e14dbde..516ed1c0 100644 --- a/java/src/main/java/euler/p0076.java +++ b/java/src/main/java/euler/p0076.java @@ -28,21 +28,21 @@ public Object answer() { byte[] counts = new byte[101]; counts[2] = 100; while (counts[100] == 0) { - counts[2] += 2; + counts[2] += (byte) 2; if (sum >= 100) { answer += (100 + counts[2] - sum) / 2; idx = 2; do { counts[idx] = 0; - idx += 1; + idx++; counts[idx] += idx; sum = 0; - for (byte i = (byte) (idx - 1); i < 101; i += 1) + for (byte i = (byte) (idx - 1); i < 101; i++) sum += counts[i]; } while (sum > 100); } sum = 0; - for (byte i = 0; i < 101; i += 1) + for (byte i = 0; i < 101; i++) sum += counts[i]; } return answer;