1 2 Previous Next 24 Replies Latest reply: Aug 29, 2008 5:26 PM by 843785

# boolean problems?? maths-header in need

hy all, is der anyone can help me wit this??

{color:#ff0000}56 {color}57 {color:#ff0000}58{color} 59 {color:#ff0000}60 {color}61 {color:#ff0000}62{color} 63
48 {color:#ff0000}49{color} 50 {color:#ff0000}51{color} 52 {color:#ff0000}53{color} 54 {color:#ff0000}55{color}
{color:#ff0000}40{color} 41 {color:#ff0000}42{color} 43 {color:#ff0000}44{color} 45 {color:#ff0000}46{color} 47
32 {color:#ff0000}33{color} 34 {color:#ff0000}35{color} 36 {color:#ff0000}37{color} 38 {color:#ff0000}39
{color}{color:#ff0000}24{color} 25 {color:#ff0000}26{color} 27 {color:#ff0000}28{color} 29 {color:#ff0000}30{color} 31
16 {color:#ff0000}17{color} 18 {color:#ff0000}19{color} 20 {color:#ff0000}21{color} 22 {color:#ff0000}23{color}
{color:#ff0000}8 {color}9 {color:#ff0000}10 {color}11 {color:#ff0000}12 {color}13 {color:#ff0000}14{color} 15
0 {color:#ff0000}1{color} 2 {color:#ff0000}3 {color}4 {color:#ff0000}5{color} 6 {color:#ff0000}7
{color}
imagine the above number is in chess board pattern
how to get the red colored numbers?? using the boolean code expression, without using the if -else or without any loops expression??
eg : if i enter number (1), it will excute TRUE and if i enter (11) then it will execute FALSE (as it is not a red-colored number). I try to use the even and odd parity concept but how?? listing out the each possible 32 numbers won't be a good solution right??

thnks.
• ###### 1. Re: boolean problems?? maths-header in need
Each cell can be described by its row and column number. I suggest that you have a look at these row and column numbers and look for a pattern. One will become evident before too long.
• ###### 2. Re: boolean problems?? maths-header in need
example if i want to get the 4 edges number which are 0-7, 56-63, 0 8 16...56 and 7 15 23...63, i would probably return the method to this boolean expression
``return (number<=7 || number >=56 || number%8==0 || (number+1)%8==0);``
any number which satisfying the boolean expresion would execute as TRUE, else FALSE.
• ###### 3. Re: boolean problems?? maths-header in need
pinez_cute wrote:
example if i want to get the 4 edges number which are 0-7, 56-63, 0 8 16...56 and 7 15 23...63, i would probably return the method to this boolean expression
``return (number<=7 || number >=56 || number%8==0 || (number+1)%8==0);``
any number which satisfying the boolean expresion would execute as TRUE, else FALSE.
This way more complicated than you need. Again, look at your and [j] numbers, see what they are for red squares vs black squares. A very simple pattern is there.
• ###### 4. Re: boolean problems?? maths-header in need
errrrrr....
• ###### 5. Re: boolean problems?? maths-header in need
Uh...huh?
``````num % 2 == 0 // black
num % 2 == 1 // red``````
• ###### 6. Re: boolean problems?? maths-header in need
-Kayaman- wrote:
Uh...huh?
``````num % 2 == 0 // black
num % 2 == 1 // red``````
not quite.

you could do if (i + j) is even vs odd.
or if you only have the number then (num/8 + num%8) is even vs odd...

Edited by: Encephalopathic on Aug 28, 2008 11:11 PM
• ###### 7. Re: boolean problems?? maths-header in need
In any case the result ought to be obtained from a conditional statement I though not called explicitly.
• ###### 8. Re: boolean problems?? maths-header in need
anamupota wrote:
In any case the result ought to be obtained from a conditional statement I though not called explicitly.
Are you the original poster with a different name, and what do you mean with "I though not called explicitly"? I don't understand this statement.
• ###### 9. Re: boolean problems?? maths-header in need
``( ( n - ( ( n / 8 ) % 2 ) ) % 2 == 1 )``
• ###### 10. Re: boolean problems?? maths-header in need
``Are you the original poster with a different name, and what do you mean with "I though not called explicitly"? I don't understand this statement. ``
No, thats not me Encephalopathic. Btw thankz for ur post anywy, it makes me to think more.
• ###### 11. Re: boolean problems?? maths-header in need
Foowie wrote:
``( ( n - ( ( n / 8 ) % 2 ) ) % 2 == 1 )``
while this is correct, I think that my way posted above is simpler, clearer, and shows better what is happening:
``if ((n/8 + n%8) == 1)``
• ###### 12. Re: boolean problems?? maths-header in need
Thankz Foowie, i think u got it der. U really inspire me to learn more on Java :D I'm a very beginner in Java Programming, love to learn more. THANK YOU
• ###### 13. Re: boolean problems?? maths-header in need
This brings back memories: I programmed a chess move generator once for a 6502 cpu and that little thing didn't have a hardware division nor a modulo operator; I ended up with this expression (sort of):
``((n>>3)^n)&1``
those were the days ...

kind regards,

Jos
• ###### 14. Re: boolean problems?? maths-header in need
pinez_cute wrote:
Thankz Foowie, i think u got it der. U really inspire me to learn more on Java :D I'm a very beginner in Java Programming, love to learn more. THANK YOU
inspires you to do what. oblique coding?
1 2 Previous Next