2009-01-12, 04:19 PM
KajitiSouls Wrote:That's a pattern that's been eluding me all this time xD Your parenthetical statement seems to be in conflict though...
Having seen that, I'm smacking myself in the head for such a stupid oversight. I've come to the conclusion that I should only check for input % n, where n is a prime number. I'm not familiar with the code (n & 1), but I understand what you mean.
Oyas! That's why I use the debugger (whatever works) and check each section of code that I write in a progressive sequence, and I ask the computer for an appropriate output to make sure that my code works before moving on. Personally my worst enemies are recursions methods.
One genius thing you did here. Colourizing. Too bad I'm not going to bother to do the same, sorry

Sorry, I've been using lisp too much, that may be why there are too many parentheses.
I've been somewhat unfamiliar with how Java works, but I'm quite sure it can be written as (n & 1 == 1).
With that being said, I'll try to explain it quite short. For a human being, to calculate this, we would have to convert n and 1 into bitcode. Let's say n equals 23:
| Base 10 | Base 2 |
| 1 | 00001 |
| 23 | 10111 |
Now, let's see how & reacts
| 00001 | |
| & | 10111 |
| = | 00001 |
Though it may look completely in-understandable, it's the bitwise &-operator. If two bits at same position equals 1, then the bit at that position is set as 1. Else, it is set as 0. Another example:
| 1011010101110001001 | |
| & | 0010111101010111010 |
| = | 0010010101010001000 |
It can be proven that any given number n is a number divisible by 2 if (n & 1 == 0).
Compared to base 10, it's like saying that any number n is divisible by 10 if the last digit in the number is 0.

