Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

what is the fastest algorithm for permutations of three condition?

Can anybody help me regarding quickest method for evaluating three conditions in minimum steps? I have three conditions and if any of the two comes out to be true,then whole expression becomes true else false.

I have tried two methods:

if ((condition1 && condition2) || 
    (condition1 && condition3) || 
    (condition2 && condition3))

Another way is to by introducing variable i and

i = 0;
if (condition1) i++;
if (condition2) i++;
if (condition3) i++;
if (i >= 2)
    //do something

I want any other effective method better than the above two.

I am working in a memory constrained environment (Atmeta8 with 8 KB of flash memory) and need a solution that works in C.

like image 291
shafeeq Avatar asked Jun 20 '13 14:06

shafeeq


1 Answers

This can be reduced to:

if((condition1 && (condition2 || condition3)) || (condition2 && condition3))
    //do something

Depending on the likelihood of each condition, you may be able to optimize the ordering to get faster short-circuits (although this would probably be premature optimization...)

like image 195
Wooble Avatar answered Oct 02 '22 23:10

Wooble