Fixed some typos

This commit is contained in:
2020-06-15 14:17:37 -04:00
parent dc510c2bc7
commit 7921241b1b
2 changed files with 12 additions and 12 deletions

View File

@@ -1,7 +1,7 @@
//src/main/java/mattrixwv/Algorithms.java //src/main/java/mattrixwv/Algorithms.java
//Matthew Ellison //Matthew Ellison
// Created: 03-02-19 // Created: 03-02-19
//Modified: 06-07-20 //Modified: 06-15-20
//This class holds many algorithms that I have found it useful to keep around //This class holds many algorithms that I have found it useful to keep around
//As such all of the functions in here are static and meant to be used as stand alone functions //As such all of the functions in here are static and meant to be used as stand alone functions
/* /*
@@ -173,7 +173,7 @@ public class Algorithms{
ArrayList<Integer> primes = new ArrayList<Integer>(); //Holds the prime numbers ArrayList<Integer> primes = new ArrayList<Integer>(); //Holds the prime numbers
boolean foundFactor = false; //A flag for whether a factor of the current number has been found boolean foundFactor = false; //A flag for whether a factor of the current number has been found
//If the numebr is 0 or negative return an empty list //If the number is 0 or negative return an empty list
if(numberOfPrimes <= 1){ if(numberOfPrimes <= 1){
return primes; return primes;
} }
@@ -182,7 +182,7 @@ public class Algorithms{
primes.add(2); primes.add(2);
} }
//We cna now start at 3 and skipp all even numbers, because they cannot be prime //We can now start at 3 and skip all even numbers, because they cannot be prime
for(int possiblePrime = 3;primes.size() < numberOfPrimes;possiblePrime += 2){ for(int possiblePrime = 3;primes.size() < numberOfPrimes;possiblePrime += 2){
//Check all current primes, up to sqrt(possiblePrime), to see if there is a divisor //Check all current primes, up to sqrt(possiblePrime), to see if there is a divisor
Double topPossibleFactor = Math.ceil(Math.sqrt(possiblePrime)); Double topPossibleFactor = Math.ceil(Math.sqrt(possiblePrime));
@@ -195,7 +195,7 @@ public class Algorithms{
else{ else{
++primesCnt; ++primesCnt;
} }
//Check if the index has gone out of range //Check if the index has gone out of bounds
if(primesCnt >= primes.size()){ if(primesCnt >= primes.size()){
break; break;
} }
@@ -218,7 +218,7 @@ public class Algorithms{
ArrayList<Long> primes = new ArrayList<Long>(); //Holds the prime numbers ArrayList<Long> primes = new ArrayList<Long>(); //Holds the prime numbers
boolean foundFactor = false; //A flag for whether a factor of the current number has been found boolean foundFactor = false; //A flag for whether a factor of the current number has been found
//If the numebr is 0 or negative return an empty list //If the number is 0 or negative return an empty list
if(numberOfPrimes <= 1){ if(numberOfPrimes <= 1){
return primes; return primes;
} }
@@ -227,7 +227,7 @@ public class Algorithms{
primes.add(2L); primes.add(2L);
} }
//We cna now start at 3 and skipp all even numbers, because they cannot be prime //We can now start at 3 and skip all even numbers, because they cannot be prime
for(long possiblePrime = 3L;primes.size() < numberOfPrimes;possiblePrime += 2L){ for(long possiblePrime = 3L;primes.size() < numberOfPrimes;possiblePrime += 2L){
//Check all current primes, up to sqrt(possiblePrime), to see if there is a divisor //Check all current primes, up to sqrt(possiblePrime), to see if there is a divisor
Double topPossibleFactor = Math.ceil(Math.sqrt(possiblePrime)); Double topPossibleFactor = Math.ceil(Math.sqrt(possiblePrime));
@@ -240,7 +240,7 @@ public class Algorithms{
else{ else{
++primesCnt; ++primesCnt;
} }
//Check if the index has gone out of range //Check if the index has gone out of bounds
if(primesCnt >= primes.size()){ if(primesCnt >= primes.size()){
break; break;
} }
@@ -263,7 +263,7 @@ public class Algorithms{
ArrayList<BigInteger> primes = new ArrayList<BigInteger>(); //Holds the prime numbers ArrayList<BigInteger> primes = new ArrayList<BigInteger>(); //Holds the prime numbers
boolean foundFactor = false; //A flag for whether a factor of the current number has been found boolean foundFactor = false; //A flag for whether a factor of the current number has been found
//If the numebr is 0 or negative return an empty list //If the number is 0 or negative return an empty list
if(numberOfPrimes.compareTo(BigInteger.valueOf(1)) <= 0){ if(numberOfPrimes.compareTo(BigInteger.valueOf(1)) <= 0){
return primes; return primes;
} }
@@ -272,7 +272,7 @@ public class Algorithms{
primes.add(BigInteger.valueOf(2)); primes.add(BigInteger.valueOf(2));
} }
//We cna now start at 3 and skipp all even numbers, because they cannot be prime //We can now start at 3 and skip all even numbers, because they cannot be prime
for(BigInteger possiblePrime = BigInteger.valueOf(3);numberOfPrimes.compareTo((BigInteger.valueOf(primes.size()))) > 0;possiblePrime = possiblePrime.add(BigInteger.valueOf(2))){ for(BigInteger possiblePrime = BigInteger.valueOf(3);numberOfPrimes.compareTo((BigInteger.valueOf(primes.size()))) > 0;possiblePrime = possiblePrime.add(BigInteger.valueOf(2))){
//Check all current primes, up to sqrt(possiblePrime), to see if there is a divisor //Check all current primes, up to sqrt(possiblePrime), to see if there is a divisor
BigInteger topPossibleFactor = possiblePrime.sqrt().add(BigInteger.valueOf(1)); BigInteger topPossibleFactor = possiblePrime.sqrt().add(BigInteger.valueOf(1));
@@ -285,7 +285,7 @@ public class Algorithms{
else{ else{
++primesCnt; ++primesCnt;
} }
//Check if the index has gone out of range //Check if the index has gone out of bounds
if(primesCnt >= primes.size()){ if(primesCnt >= primes.size()){
break; break;
} }

View File

@@ -70,8 +70,8 @@ public class TestAlgorithms{
//Test 3 //Test 3
ArrayList<BigInteger> bigCorrectAnswer = new ArrayList<BigInteger>(Arrays.asList(BigInteger.valueOf(2), BigInteger.valueOf(3), BigInteger.valueOf(5), BigInteger.valueOf(7), BigInteger.valueOf(11), BigInteger.valueOf(13), BigInteger.valueOf(17), BigInteger.valueOf(19), BigInteger.valueOf(23), BigInteger.valueOf(29), BigInteger.valueOf(31), BigInteger.valueOf(37), BigInteger.valueOf(41), BigInteger.valueOf(43), BigInteger.valueOf(47), BigInteger.valueOf(53), BigInteger.valueOf(59), BigInteger.valueOf(61), BigInteger.valueOf(67), BigInteger.valueOf(71), BigInteger.valueOf(73), BigInteger.valueOf(79), BigInteger.valueOf(83), BigInteger.valueOf(89), BigInteger.valueOf(97))); ArrayList<BigInteger> bigCorrectAnswer = new ArrayList<BigInteger>(Arrays.asList(BigInteger.valueOf(2), BigInteger.valueOf(3), BigInteger.valueOf(5), BigInteger.valueOf(7), BigInteger.valueOf(11), BigInteger.valueOf(13), BigInteger.valueOf(17), BigInteger.valueOf(19), BigInteger.valueOf(23), BigInteger.valueOf(29), BigInteger.valueOf(31), BigInteger.valueOf(37), BigInteger.valueOf(41), BigInteger.valueOf(43), BigInteger.valueOf(47), BigInteger.valueOf(53), BigInteger.valueOf(59), BigInteger.valueOf(61), BigInteger.valueOf(67), BigInteger.valueOf(71), BigInteger.valueOf(73), BigInteger.valueOf(79), BigInteger.valueOf(83), BigInteger.valueOf(89), BigInteger.valueOf(97)));
BigInteger bigTopNum = BigInteger.valueOf(25); BigInteger bigNumPrimes = BigInteger.valueOf(25);
ArrayList<BigInteger> bigAnswer = Algorithms.getNumPrimes(bigTopNum); ArrayList<BigInteger> bigAnswer = Algorithms.getNumPrimes(bigNumPrimes);
assertEquals("getNumPrimes BigInteger failed", bigCorrectAnswer, bigAnswer); assertEquals("getNumPrimes BigInteger failed", bigCorrectAnswer, bigAnswer);
} }
@Test @Test