Consider the Following Function taking into account
- addition costs you 4 Operations
- assignment costs 1 Operations
- Comparision costs 1 Operations
Calculation of the above function will cost 14 Operations
int function1(int a,int b,int c, int d, int e)
{
int returnNumber;
//int no = randomNumber(); //Some Random Number Generator Function , Lets Assume the cost of this function to be 0 for simplicity purpose
switch(randomNumber())
{
case 0: returnNumber = a+b; // costs 6 Operations , Case Check costs 1, assignment costs 1 and addition costs 4
break;
case 1: returnNumber = c+d; // Costs 6 Operations
break;
default: returnNumber = e; // costs 2 Operations
}
return returnNumber;
}
Total Cost of this Function is 14 Operations , Is there any code which can do the same thing as well as reduce the cost of this function atleast by 1 ?
EDIT 1 Added the Break Statement in Switch Statements as well as assignment of variable no to a randomNumber generator function
EDIT 2 i came across this question from a friend of mine who happened to have faced this question in the F2Fs , i wonder if this question has a solution or not , since i havent been able to find any till Now.