Talk:Prime Number
From Hack Wars Wiki
optimizing code
this is about a challenge. a challenge which is not implemented in HW anymore. - please dont delete these challenge description. they are still a good training for starters -
If the solution does the job then it is ok.
If you really want to optimize this code then:
half the steps by changing i++ to i+=2 (<=> i=i+2) and add a simple
if (num == 2) //num is a prime
if (num % 2 == 0) //num is not a prime
Make sure that your code runs!
void testCode(int input) { //here the Code you want to test //change int num = getInputInt(); to int num=input; } int main() { int ii=0; for (ii=0;ii<10;ii++) { setOutputString(""+ii+":"); //Outputs input testCode(ii); } } |
Get a copy of ReverseString.challenge and run your testCode as Challenge "6565".
You will probably fail challenge 6565 but you will see if your code would pass the prime number challenge
Silverlight 17:40, 2 March 2009 (UTC)
