Jump to content

  • Log In with Google      Sign In   
  • Create Account


Could someone give me feedback on my algorithm?


Old topic!
Guest, the last post of this topic is over 60 days old and at this point you may not reply in this topic. If you wish to continue this conversation start a new topic.

  • You cannot reply to this topic
24 replies to this topic

#21 Khatharr   Crossbones+   -  Reputation: 2852

Like
0Likes
Like

Posted 13 December 2012 - 10:07 PM

This is true. Personally I always use parens to avoid ambiguity and in this case since you're feeding it to a ? operator you can just swap the result order and drop the explicit comparison to zero.
void hurrrrrrrr() {__asm sub [ebp+4],5;}

There are ten kinds of people in this world: those who understand binary and those who don't.

Sponsor:

#22 Alpha_ProgDes   Crossbones+   -  Reputation: 4680

Like
0Likes
Like

Posted 13 December 2012 - 11:31 PM

For the record, this thread was a joy to read. So everyone got +1.

Carry on.
Beginner in Game Development? Read here.
 
Super Mario Bros clone tutorial written in XNA 4.0 [MonoGame, ANX, and MonoXNA] by Scott Haley
 
If you have found any of the posts helpful, please show your appreciation by clicking the up arrow on those posts Posted Image
 
Spoiler

#23 iMalc   Crossbones+   -  Reputation: 2260

Like
3Likes
Like

Posted 14 December 2012 - 12:53 AM

if((k+k/8)%2 == 0) {
	(*rects[(k)]).set_fill_color(Color::red);
   }
   else if((k+k/8)%2 == 1) {
	(*rects[(k)]).set_fill_color(Color::white);
   }

You need to read this article, and perhaps some of the comment as well:
http://thedailywtf.com/Articles/ButAnything-Can-Happen!.aspx
The thing you need to learn here is that you are mis-using else-if. There are only two possible outcomes of a number mod 2, ergo it is appropriate to just use an else for the second case.
"In order to understand recursion, you must first understand recursion."
My website dedicated to sorting algorithms

#24 Khatharr   Crossbones+   -  Reputation: 2852

Like
1Likes
Like

Posted 14 December 2012 - 02:02 AM

Lol @ the article.

[source lang="cpp"]for(int i = 0; i < rects.size(); ++i) rects[i]->set_fill_color((i & 1) ? Color::white : Color::red);[/source]

Edited by Khatharr, 14 December 2012 - 02:13 AM.

void hurrrrrrrr() {__asm sub [ebp+4],5;}

There are ten kinds of people in this world: those who understand binary and those who don't.

#25 Álvaro   Crossbones+   -  Reputation: 11910

Like
3Likes
Like

Posted 14 December 2012 - 06:17 AM

To test for odd vs even don't use modulation. Just binary-and with 1.


Use whichever one you find more clear. I personally find %2 more clear than &1 in this situation.

Edited by Álvaro, 14 December 2012 - 06:19 AM.





Old topic!
Guest, the last post of this topic is over 60 days old and at this point you may not reply in this topic. If you wish to continue this conversation start a new topic.



PARTNERS