Jump to content

  • Log In with Google      Sign In   
  • Create Account

#Actuallightxbulb

Posted 30 April 2013 - 01:35 AM

Careful now...

 

 

    if(input>6) //this condition is (usually) not an effective optimization and is mathematically irrelevant
        input = input % 7;
    if(input<0)
        input = (input % 7) + 7; //this is incorrect in cases where input == n * -7

 

Try:

 

 

    input %= 7;
    if(input<0)
        input +=  7;

Thanks about this! Seems I didn't predict the case when (-7*n) % 7 = 0 tongue.png

(In fact I think I did predict it but messed up my conditionals...sad.png  gotta be careful when coding)


#1lightxbulb

Posted 30 April 2013 - 01:00 AM

Careful now...

 

 

    if(input>6) //this condition is (usually) not an effective optimization and is mathematically irrelevant
        input = input % 7;
    if(input<0)
        input = (input % 7) + 7; //this is incorrect in cases where input == n * -7

 

Try:

 

 

    input %= 7;
    if(input<0)
        input +=  7;

Thanks about this! Seems I didn't predict the case when (-7*n) % 7 = 0 tongue.png


PARTNERS