From a8fe06b3e4bc338242810b381f123f0d970e4e68 Mon Sep 17 00:00:00 2001 From: Mattrixwv Date: Wed, 17 Jun 2020 12:33:25 -0400 Subject: [PATCH] Updated for performance --- .../mattrixwv/ProjectEuler/Problems/Problem21.java | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/src/main/java/mattrixwv/ProjectEuler/Problems/Problem21.java b/src/main/java/mattrixwv/ProjectEuler/Problems/Problem21.java index 66f8be3..136c71b 100644 --- a/src/main/java/mattrixwv/ProjectEuler/Problems/Problem21.java +++ b/src/main/java/mattrixwv/ProjectEuler/Problems/Problem21.java @@ -31,7 +31,7 @@ import java.util.Collections; public class Problem21 extends Problem{ //The number that is > the largest number to be checked - private static final Integer LIMIT = 10000; + private static final int LIMIT = 10000; public Problem21(){ super("Evaluate the sum of all the amicable numbers under 10000"); @@ -58,8 +58,8 @@ public class Problem21 extends Problem{ } //Check every sum of divisors in the list for a matching sum ArrayList amicable = new ArrayList(); - for(Integer cnt = 1;cnt < divisorSum.size();++cnt){ - Integer sum = divisorSum.get(cnt); + for(int cnt = 1;cnt < divisorSum.size();++cnt){ + int sum = divisorSum.get(cnt); //If the sum is greater than the number of divisors then it is impossible to be amicable. Skip the number and continue if(sum >= divisorSum.size()){ continue; @@ -67,7 +67,7 @@ public class Problem21 extends Problem{ //We know that divisorSum.at(cnt) == sum, so if divisorSum.at(sum) == cnt we found an amicable number if(divisorSum.get(sum).compareTo(cnt) == 0){ //A number can't be amicable with itself - if(sum.compareTo(cnt) == 0){ + if(sum == cnt){ continue; } //Add it to the arraylist of amicable numbers @@ -103,5 +103,5 @@ All amicable numbers less than 10000 are 6232 6368 The sum of all of these amicable numbers is 31626 -It took 23.551 milliseconds to solve this problem. +It took 8.616 milliseconds to solve this problem. */