You can try the code using the following link:
Code
For further actions, you may consider blocking this person and/or reporting abuse
You can try the code using the following link:
Code
For further actions, you may consider blocking this person and/or reporting abuse
Top comments (8)
this doesn't work for all numbers
tested with 1111111 & 121111
[EDIT1]replace the loop by
[EDIT2] to explain : the
return truein the for loop will always return true on the first try, and the&&in the if need to be a||to test if it works, take high odd number, and if you wanna be sure, add
printf("%d %% %d = %d | ", n, i, n%i);andprintf("%d %% %d = %d | ", n, i+2, n%(i+2));in the for loop (that's a fastest way instead of debug)Hey thank you so much for the correction!
It's
i + 6noti + 4, the only issue was the return inside the for loop.And
n == 2 || n == 3can be simplified asn < 4orn <=3the only thing is that
i+4will check all odd number, even those divided by 3, where thei+6won't check the5+6*inumberI admit it's not usefull, because all
(5+6*i)+4numbers can be divided by 3In JS, using regex:
Would you like to explain it?
I didn't write it, but it's fascinating... noulakaz.net/2007/03/18/a-regular-...
that's evil, I love it π