Could someone give me feedback on my algorithm?

Started by
23 comments, last by alvaro 11 years, 4 months ago
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.
Advertisement
For the record, this thread was a joy to read. So everyone got +1.

Carry on.

Beginner in Game Development?  Read here. And read here.

 



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
Lol @ the article.

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

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.

This topic is closed to new replies.

Advertisement