poker game straight in java - java

my problem is that this is sound logic but the execution is incorrect (the submit server won't take it). So I'm trying to check if my hand of 5 cards has a straight (that's 2, 3, 4, ,5 6, etc. numbers in consecutive order) and then if the fifth card is an ace i want it to evaluate as the value 10 so it'd be like 6 7 8 9 A(A has a card value of 1) and this is my current code
public static boolean hasStraight(Card [] cards) {
boolean isTrue = false;
for(int atPos =0; atPos<cards.length-1; atPos++){
Card ogCard = cards[atPos];
Card notOgCard = cards[atPos+1];
if (ogCard.getValue() == (notOgCard.getValue()-1)){
if ((cards[3]).getValue()==9){
if (cards[4].getValue() ==1);
isTrue = true; //accounting for ace in last position
}
else if(ogCard.getValue() == (notOgCard.getValue()-1)){
isTrue = true; //accounting for ace not in first position
}
}
}
return isTrue;
}
this is what I have so far not sure what's next.

Your code seems to be going the wrong way.
First you set isTrue to false, but then set it to true any time the array is in strictly increasing order. Thus, it will resolve as true if just the first two are 1,2.
I would set it to true in the beginning, then make it false if they array is ever not in increasing order.
Your constructions of ifs and else ifs are also...interesting.
The if ((cards[3]).getValue()==9){ line will most likely never run as you want it to, as ogCard.getValue() == (notOgCard.getValue()-1) will not be true (and thus the second if statement will never run) when the ace is in the last position. I would just remove the wrapping if statement, as it doesn't really test anything useful.
Your described method also doesn't handle valid aces not in the last position.
My recommendation would look something like this:
public static boolean hasStraight(Card [] cards) {
boolean isTrue = true;
for(int atPos =0; atPos<cards.length-1; atPos++){
Card ogCard = cards[atPos];
Card notOgCard = cards[atPos+1];
if (! (ogCard.getValue() == (notOgCard.getValue()-1) || (ogCard.getValue()==9&&notOgCard.getValue()==1) ) ) {
isTrue=false;
}
}
return isTrue;
}

Related

Troubles with variable scope outside the for loop

So, there is a class Hotel, that contains 20 Rooms in form of a matrix 4x5 (4 floors, 5 rooms on every floor). The class Room has the properties:
floorNumber(int),
roomNumber(int),
numberOfBeds(int),
occupation(boolean)
etc.
For occupation, true means busy, and false means free.
One of methods I have to implement in Hotel is the one that reserves a room
reserve(int floorNumber, int roomNumber)
This method should check if occupation is true or false.
If it is true, then reservation fails, and if it is false, I should set occupation to true, with method
setOccupation(boolean t).
Also, method reserve return boolean (true or false), depending on whether reservation succeeded or not.
In that method, you guess, is problem with scope of one variable.
So there it is:
public boolean reserve(int floorNumber, int roomNumber){
boolean flag = false;
for ( int i = 0; i < 5; i++){
if(rooms[floorNumber][i].getRoomNumber() == roomNumber){//every element in matrix rooms has this property: rooms[floorNumber][some_number_from_1_to_5]
if (rooms[floorNumber][i].getOccupancy() == false){
rooms[floorNumber][i].setOccupancy(true);
flag = true;
}
else
flag = false;
}
}
return flag;
}
The problem is, when I set (in first line) flag to true, function returns true, and when I set flag to false, function returns false.
The reason I have to assign some value to flag in first line is because compiler shows:
Error: variable flag might not have been initialized
So, the problem is that it seems like method never executes code with for loop.
I know that variables defined in loop don't exist outside loop, but those defined outside should change their values in loop.
Like in this question here:
Java - Access variable inside and outside of for-loop
There is a simpler way to accomplish what you want to do. You don't need a boolean flag at all; you can just return true immediately on success or return false if the entire loop executed without finding a room.
public boolean reserve(int floorNumber, int roomNumber){
for (int i = 0; i < 5; i++) {
//every element in matrix rooms has this property:
//rooms[floorNumber][some_number_from_1_to_5]
if (rooms[floorNumber][i].getRoomNumber() == roomNumber){
if (rooms[floorNumber][i].getOccupancy() == false){
rooms[floorNumber][i].setOccupancy(true);
return true;
}
}
}
return false;
}
But if you insist on applying your original approach that uses a flag, then: First give it a value of false (in case no room succeeded). When we find an unoccupied room (successful), set it to true. If we find an occupied room, don't touch the flag value.
public boolean reserve(int floorNumber, int roomNumber){
boolean flag = false;
for (int i = 0; i < 5; i++) {
//every element in matrix rooms has this property:
//rooms[floorNumber][some_number_from_1_to_5]
if (rooms[floorNumber][i].getRoomNumber() == roomNumber){
if (rooms[floorNumber][i].getOccupancy() == false){
rooms[floorNumber][i].setOccupancy(true);
flag = true;
} // else DO NOTHING
}
}
return flag;
}
I found what the problem was.
It was actually index floorNumber in matrix rooms[floorNumber][] that goes from 0 to 3 (there are 4 floors), of course.
But in real life, floor numbers go from 1, and I passed argument to
reserve(int floorNumber,int roomNumber)
without considering that.
So, I just decremented floorNumber by 1 in body of method, and it works now.

Android compare booleans

I am making a simple app where you have to toggle buttons/booleans trying to guess the correct combination. I was wondering the simplest way to compare the toggles booleans against the "right" combination. For example if user has:
boolean 1: true
boolean 2: false
Boolean 3: true
but the correct combination is:
boolean 1: true
boolean 2: true
Boolean 3: true
I want the user to see a message that says you have 2 out of 3 correct. I have
public void go(View view){
if (bool1 == true && boo12 == true && bool3 == true) {
// do this
} else {
// display the correct amount of booleans the user has correct.
}
}
Create a BitSet for the correct combination (set the bits that correspond to "true", clear the bits that correspond to "false").
When you want to check the user's input, create a BitSet from the buttons that are pressed (set "true", clear "false").
Correctness can be checked with correctValue.equals(usersAttempt).
A count can be obtained by doing usersAttempt.xor(correctValue) then usersAttempt.cardinality() will return the number of incorrect values.
This requires a bare minimal amount of coding. For your example:
// Correct: [true,true,true]
BitSet correct = new BitSet(3);
correct.set(0); // <= true
correct.set(1); // <= true
correct.set(2); // <= true
// User's attempt (buttonN.isChecked() is just placeholder, drop in whatever
// code you actually use to get the state of your buttons):
BitSet attempt = new BitSet(3);
attempt.set(0, button0.isChecked()); // <= true in your example
attempt.set(1, button1.isChecked()); // <= false in your example
attempt.set(2, button2.isChecked()); // <= true in your example
// Check answer (produces false in your example):
boolean matchIsPerfect = attempt.equals(correct);
// Get the count (produces 1 in your example):
attempt.xor(correct);
int incorrectCount = attempt.cardinality();
// To get the correct count just subtract 'incorrectCount' from total.
// Another way to check if attempt is correct is 'if (incorrectCount == 0)'.
// Note that the remaining bits set in 'attempt' after the above xor()
// will correspond to the individual inputs that weren't correct.
This will let you support any size, the code is clear and you don't need to do any of the logic on your own. Note that you can simplify the button -> user's attempt setup if you have an array of buttons or can access user input given an index.
If the conditions are not always to be true, say bool3 needs to be false, you can use something like this maybe. Otherwise, as the other answers mentioned, an array would work best probably.
int correctCount = 0;
if (bool1) correctCount++;
if (bool2) correctCount++;
if (!bool3) correctCount++;
if (correctCount == 3) {
// do this
} else {
Toast.makeText(context, String.valueOf(correctCount) + " out of 3 correct", Toast.LENGTH_LONG).show();
}
Assuming that your "right" combination will include both true and false values, the following method will return the number of matches, or -1 if the array lengths don't match:
private int getMatches(boolean[] toggleValues, boolean[] matchPattern)
{
if(toggleValues.length != matchPattern.length)
return -1;
int matches = 0;
for (int j = 0; j < toggleValues.length; j++)
{
if(toggleValues[j] == matchPattern[j])
{
matches++;
}
}
return matches;
}
As an example, if you have 3 ToggleButtons, tb1, tb2, and tb3, the following will return 2:
tb1.setChecked(true);
tb2.setChecked(false);
tb3.setChecked(false);
final boolean[] matchPattern = {true, false, true};
final boolean[] toggleValues = {tb1.isChecked(), tb2.isChecked(), tb3.isChecked()};
int matches = getMatches(toggleValues, matchPattern);
This method will allow you to easily change the matching pattern without changing code, e.g by reading stored values into the matchPattern array from a file or SharedPreferences.
you can do it, as the number of boolean values can be more than 3. you may want to use for loop (easy way) and iterate it for the end of the value and return the number of counts to the value k. here k-> number of true boolean values and b is an array containing the array of boolean values.
public void go(View view){
boolean b[]={bool1,bool2,bool3,bool4,bool5,bool6,bool7,bool8,bool9,bool10};
int k=0;
for(int i=0;i<b.length;i++)
{
if(b[i]==true)
{
k++;
}
}
if(k==b.length)
{
do task
}
else
{
Toast.makeText(getApplicationContext(), k+ "out of "+b.length+ "correct",Toast.LENGTH_LONG).show();
}
}

Need some help with isFlush and isThreeKind methods, poker-type program

This isn't the complete code, but it's the parts that are causing problems. I've written both isFlush and isThreeKind, but for some reason they seem to always return true, except when the first return statement is changed to "return false", in which case they always return false. This leads to the interesting problem of the code declaring that 3000/3000 hands are flushes and contain three of a kind, something I'm fairly certain is impossible.
Edit: Yes I am a moron, I forgot to link to a pastebin of the code.
http://pastebin.com/bahwrm7Y
Now that you've added code, it appears you're passing in the entire deck each time. If that's the case, by your logic you will always have 3 of a kind (as there are 4 of each suit in the deck) and a flush (as your logic is >= 5). I suspect that if you change your logic in flush to == 5 instead, it will always return false.
Perhaps your deck needs a Card[] randomHand(int handSize) method that gives you a random hand of cards, and test against that? It could even be a Deck object with a smaller size.
Original answer below:
Here's my quick and dirty (and possibly inefficient) versions of those... Without seeing what you have it's going to be difficult to help debug it!
boolean isFlush(Card[] cards) {
for(Card c : cards) {
if(c.suit != cards[0].suit) return false;
}
return true;
}
/**
* returns the value of the set, or 0 if no three-set exists
*/
int isThreeKind(Card[] cards) {
for(int i = 0; i < cards.length - 2; i++) {
if(sumOfType(i.value,cards) >= 3) return i.value; // return the value of the card
}
return 0; // 0 indicates no value
}
int sumOfType(int value, Card[] cards) {
int sum = 0;
for(Card c : cards) if(value == c.value) sum++;
return sum;
}

Array Recursion

I've got an assignment I can't figure out, any pointers will be much appreciated, it goes like so:
There's a series of light bulbs represented as an array of true/false, there's a switch for every light bulb, by clicking it for any light bulb, you toggle it as well as 2 adjacent ones (1 from left & another 1 from right; if clicked switch's bulb on edge -- only 1 adjacent toggled of course).
What is needed to accomplish is a method that accepts an array of a series of turned on/off light bulbs and another one representing another state of supposedly the 1st array after some switches have been clicked..!
So recursion must be used to find out whether there's a combination of switch clicks that will transform array 1 to array 2.
Here's the signature of the method:
public static boolean disco(boolean[] init, boolean[] target)
Will return true if array init can be transformed to target, false otherwise.
Method must be static and not use loops & any other static and global variables, only local.
Example:
boolean[] init = {true, false, true, false, true, false};
boolean[] target = {false, true, false, true, false, true};
For above 2 arrays, disco(init, target) will return true because toggling the 1st and 4th bulbs would yield the target state (remember adjacent bulbs being toggled as well).
new version
public static boolean disco(boolean[] init, boolean[] target)
{
return recurse(init,boolean,0);
}
public static boolean recurse(boolean[] init, boolean[] target, int min)
{
if (min == init.length)
if (init == target)
return true;
else
return false;
boolean[] temp = "init with a change at min";
boolean a = recurse(init, target, min+1);
boolean b = recurse(temp, target, min+1);
return a||b;
}
new new version
I've broken it down to three cases:
Case 1: length %3 = 0
By changing the first bulb and the second bulb, you can affect a change on only the 3rd.
Then a change to 4 and 5 will make the 6th the only one changed. We see that we can change every bulb with index divisible by 3.
Working backwards (starting at the end) we can do the same but this time it shows us we can change bulbs with indices (i+1) divisible by 3.
Combining the two, we see that if we want to change an index 0,1 mod 3 we can. But then to change a 2, we simply have to change a neighboring 0,1 pair and then do a change on the middle one. So in all cases these are solvable.
Case 2: length %3 = 1
Just like the first case, but we can affect single changes at 0,2 mod 3, and thus squeeze the 1 mod 3 cases.
Case 3: length %3 = 2
Working forward and backwards only yields cases 0 mod 3. The only remaining moves we have make two changes to the bulbs (since we can ignore any changes to positions 0). Changing a 1 or 2 will reverse the position surrounded by two 0's whereas changing a 0 will swap the parity in adjacent blocks of 1,2 which have a 0 between them (it's easier if you draw it). But what I've shown so far is that the 0's can all be corrected and in any adjacent 1,2 you can fix both if they are wrong without changing anything else. If one is wrong then you propagate a change to an adjacent pair of 1,2. This change can be moved if necessary. What this means is that any even number of errors in 1,2 positions can be fixed, but an odd number cannot. All errors at position 0's can be fixed.
public static boolean disco(boolean[] init, boolean[] target)
{
if (init.length%3 == 0 || init.length%3 == 1)
return true;
return recurse(init,target,0, true);
}
public static boolean recurse(boolean[] init, boolean[] target, int index, boolean even)
{
if (index = init.length)
return even;
if (init[index] != target[index] && index%3 != 0)
even = !even;
return recurse(init, target, index+1, even);
}
So here's in words how I would do it:
If there are just less than or equal 3 bulbs left, it's quite easy to check wether they can be switched so that it's correct.
If there are more than three bulbs, do the following:
Check, if the first bulb is correct. If so, go on recursively with the subarray beginning at the second bulb.
If the first bulb is not correct, switch the second bulb (switching the first bulb won't work because previous bulbs are switched back then). Now, the first bulb is correct. Go on with the subarray beginning at the second bulb.
Hint: Let a1, a2, ..., ak, ..., an be the input and b1, b2, ..., bk, ..., bn be the desired output.
You can recursively test the left and right sides and then combine the result. The tricky part is combining the result.
Start with the left side.
Test a1, a2, ..., ak, true to b1, b2, ..., bk, true.
if true, then test a1, a2, ..., ak to b1, b2, ..., bk.
if true then the solution from a1, a2, ..., ak to b1, b2, ..., bk can not include toggling the kth switch
if false then the solution from a1, a2, ..., ak to b1, b2, ..., !bk must include toggling the kth switch
if false, then test a1, a2,...,ak to b1, b2,...,bk
if true then the solution from a1,a2, ..., ak to b1, b2 ,.., bk must include toggling the kth switch
if false, then the soluation from a1,a2,...,ak to b1, b2,...,!bk can not include toggling the kth switch
After two tests on the left side, you can perform similar tests on the right side. You will be able to combine the values of the test, because you will know whether the kth switch was toggled or not.
Thanks all for your help, this is what I came up with:
public static boolean disco(boolean[] init, boolean[] target)
{
if (java.util.Arrays.equals(init, target)) {
return true;
} else {
return disco(init, target, 0);
}
}
private static boolean disco(boolean[] init, boolean[] target, int i)
{
if (i > init.length-1) {
return false;
}
disco(init, target, i+1);
boolean t = false;
if (init[i] != target[i]) {
switchBulb(init, target, i);
}
if (java.util.Arrays.equals(init, target)) {
t = true;
}
return t;
}
private static void switchBulb(boolean[] init, boolean[] target, int i)
{
if ( (i > 1) && (init[i-1] != target[i-1]) && (init[i-2] != target[i-2]) ) {
// If there's a series of 3 opposite-to-target bulbs, switch the middle one & from both sides
init[i-1] = !init[i-1];
init[i] = !init[i];
init[i-2] = !init[i-2];
} else if (i > 0 && i < init.length-1) {
// There's only 1 bulb or 2 adjacent bulbs that are opposite of target.
if (i == 1 && (init[0] != target[0]) ) {
// First 2 bulbs are opposite of target's, so switch the 1st one.
init[i-1] = !init[i-1];
init[i] = !init[i];
} else if ( (i == init.length-2) && (init[i+1] != target[i+1]) ) {
init[i+1] = !init[i+1];
init[i] = !init[i];
} else {
init[i] = !init[i];
init[i-1] = !init[i-1];
init[i+1] = !init[i+1];
}
} else {
// First bulb or last bulb.
init[i] = !init[i];
if (i == 0) {
init[i+1] = !init[i+1];
} else {
init[i-1] = !init[i-1];
}
}
}
I feel my use of recursion here is minimal, could be much cleaner if recursion was used properly. Any thoughts?
I'm talking about the switchBulb function, it could be swapped with a little bit more sophisticated recursion logic, or am I wrong?
As in, if you simply iterate over the bulbs one by one and compare to the target array, you won't necessary get it right for ALL combinations of bulbs (see example), so how do you mimic random bulb switching with recursion? Or is there a pattern? There must be, if not, how would it know when to stop?
I think I got the solution, will post later if anyone's interested...

Whats wrong with my syntax and am i doing this efficiently?

I'm trying to make a method that will tell me weather or not it is true or false that a number is prime. here's the code:
class prime
{
public static boolean prime (int a, int b)
{
if (a == 0)
{
return false;
}
else if (a%(b-1) == 0)
{
return false;
}
else if (b>1)
{
prime (a, b-1) ;
}
else
{
return true;
}
}
public static void main (String[] arg)
{
System.out.println (prime (45, 45)) ;
}
}
when i try to compile this i get this error message:
prime.java:23: missing return statement
}
^
1 error
I could be misinterpreting what the error message is saying but it seems to me that there isn't a missing return statement since i have a return statement for every possible set of conditions. if a is 0 then it returns false, if it isn't then it checks to see if a is dividable by b if it is then it returns if not then if b is greater than 1 it starts over again. if b isn't greater than 1 it also returns.
Also it seems a bit messy to have to
make this method take two ints that
are the same int.
What is wrong with my syntax/ why am i getting the error message? Is there a way to make it so that the method that i use in main only has to take one int (perhaps another method splits that int into two clones that are then passed to public static boolean primeproper?
or is there a more effective way of
going about this that i'm missing
entirely?
In your prime function, there are four possible code paths, one of which doesn't return anything. That is what the error message is complaining about. You need to replace:
prime (a, b-1) ;
with:
return prime (a, b-1) ;
in the else if (b>1) case.
Having said that, this is actually not a good way to calculate if a number is prime. The problem is that every recursive call allocates a stack frame and you'll get into serious stack overflow problems if you're trying to work out whether 99,999,999 is a prime number?
Recursion is a very nice tool for a certain subset of problems but you need to be aware of the stack depth. As to more efficient solutions, the are many tests you can carry out to determine a number is not prime, then only check the others with a brute force test.
One thing you should be aware of is to check divisibility against smaller numbers first since this will reduce your search scope quicker. And don't use divide where multiply will do, multiplication is typically faster (though not always).
And some possibly sneaky tricks along the lines of:
every number other than 2 that ends in 2, 4, 6, 8 or 0 is non-prime.
every number other than 5 that ends in 5 is non-prime.
Those two rules alone will reduce your search space by 60%. Assuming you get your test number as a string, it's a simple matter to test the last digit of that string even before converting to an integral type.
There are some more complex rules for divisibility checks. If you take a multiple of 9 and sum all the digits to get a new number, then do it again to that number, then keep going until you have a single digit, you'll find that it's always 9.
That will give you another 10% reduction in search space albeit with a more time-expensive check. Keep in mind that these checks are only advantageous for really large numbers. The advantages are not so great for, say, 32-bit integers since a pre-calculated bitmap would be much more efficient there (see below).
For a simplistic start, I would use the following iterative solution:
public static boolean prime (int num) {
int t = 2;
while (t * t <= num) {
if ((num % t) == 0) {
return false;
}
t++;
}
return true;
}
If you want real speed in your code, don't calculate it each time at all. Calculate it once to create a bit array (one of the sieve methods will do it) of all primes across the range you're interested in, then simply check your values against that bit array.
If you don't even want the cost of calculating the array every time your program starts, do it once and save the bit array to a disk file, loading it as your program starts.
I actually have a list of the first 100 million primes in a file and it's easier and faster for me to use grep to find if a number is prime, than to run some code to calculate it :-)
As to why your algorithm (fixed with a return statement) insists that 7 is not prime, it will insist that every number is non-prime (haven't checked with negative numbers, I'm pretty sure they would cause some serious problems - your first check should probably be if (a < 1) ...).
Let's examine what happens when you call prime(3,3).
First time through, it hits the third condition so calls prime(3,2).
Then it hits the second condition since 3 % (2-1) == 0 is true (N % 1 is always 0).
So it returns false. This could probably be fixed by changing the third condition to else if (b>2) although I haven't tested that thoroughly since I don't think a recursive solution is a good idea anyway.
The following complete code snippet will do what you need although I appreciate your curiosity in wanting to know what you did wrong. That's the mark of someone who's actually going to end up a good code cutter.
public class prime
{
public static boolean isPrime (int num) {
int t = 2;
while (t * t <= num) {
if ((num % t) == 0) {
return false;
}
t++;
}
return true;
}
public static void main (String[] arg)
{
System.out.println (isPrime (7)) ;
}
}
You seem to be under the impression that because the recursion will eventually find a base-case which will hit a return statement, then that return will bubble up through all of the recursive calls. That's not true. Each recursive call must pass out the result like this:
return prime(a, b - 1);
If b is larger than 1, your function won't return anything.
May it be return prime (a, b-1) ; ?
To improve efficiency, think more about your conditions. Do you really need test every factor from 2 to N? Is there a different stopping point that will help tests of prime numbers complete more quickly?
To make a better API, consider making the recursive method private, with a public entry point that helps bootstrap the process. For example:
public static boolean prime(int n) {
return recurse(n, n);
}
private static boolean recurse(int a, int b) {
...
}
Making a method private means that it can't be called from another class. It's effectively invisible to users of the class. The intent here is to hide the "ugly" extra parameter by providing a public helper method.
Think about the factors of some composite numbers. 10 factors to 5×2. 12 factors to 6×2. 14 factors to 7×2. Now think about 25. 25 factors to 5×5. What about 9? Do you see a pattern? By the way, if this isn't homework, please let me know. Being this didactic is hard on me.
In answer to why 7 isn't working, pretend you're the computer and work through your logic. Here's what you wrote.
class prime
{
public static boolean prime (int a, int b)
{
if (a == 0)
{
return false;
}
else if (a%(b-1) == 0)
{
return false;
}
else if (b>1)
{
// Have to add the return statement
// here as others have pointed out!
return prime(a, b-1);
}
else
{
return true;
}
}
public static void main (String[] arg)
{
System.out.println (prime (45, 45)) ;
}
}
So let's start with 7.
if(7 == 0) // not true, don't enter this block
else if(7 % 6 == 0) // not true
else if(7 > 1) // true, call prime(7, 6)
if(7 == 0) // not true, don't enter this block
else if(7 % 5 == 0) // not true
else if(6 > 1) // true, call prime(7, 5)
if(7 == 0) // not true, don't enter this block
else if(7 % 4 == 0) // not true
else if(5 > 1) // true, call prime(7, 4)
... keep going down to calling prime(7, 2)
if(7 == 0) // not true, don't enter this block
else if(7 % 1 == 0) true, return false
When you get down to calling prime(n, 2), it will always return false because you have a logic error.
Your recursive method must return a value so it can unroll.
public static boolean prime (int a, int b)
{
if (a == 0)
{
return false;
}
else if (a%(b-1) == 0)
{
return false;
}
else if (b>1)
{
return prime (a, b-1) ;
}
else
{
return true;
}
}
I might write it a different way, but that is the reason that you are not able to compile the code.
I think the original question was answered already - you need to insert return in the body of else if (b>1) - I just wanted to point out that your code still will crash when given 1 as the value for b, throwing an ArithmeticException since a%(b-1) will be evaluated to a%0, causing a division by zero.
You can avoid this by making the first if-statement if (a == 0 || b == 1) {}
This won't improve the way the program finds primes, it just makes sure there is one less way to crash it.
Similar to #paxdiblo's answer, but slightly more efficient.
public static boolean isPrime(int num) {
if (num <= 1 || (num & 1) == 0) return false;
for (int t = 3; t * t <= num; t += 2)
if (num % t == 0)
return false;
return true;
}
Once it is determined that the number is not even, all the even numbers can be skipped. This will halve the numbers which need to be checked.

Categories