3 ms·
That seems more like a failure of mathematical reasoning than in programming.
by Apocryphon 5y ago
That seems more like a failure of mathematical reasoning than in programming.
- kragen 5y agoI would be amazed to meet someone who, if asked whether 3042041 was odd or even, would follow this exponential-time procedure manually. Unless the candidate was such a person, it's a failure of programming.
- Apocryphon 5y agoThey just seem numerically illiterate to the point of not realizing how to determine odds or evens. Though perhaps, if they were more competent as a programmer, they would skip decimal math altogether and use the ol' bitwise operator trick.
- boring_twenties 5y agoFWIW, gcc 10 generates identical code for `i % 2 != 0` and `i & 1 != 0` at -O1.
- kragen 5y agoYeah, but "doesn't know about the % operator" is a lot less damning than "can only think of an exponential-time algorithm to determine if a number is even". Like, this is terrible, but it's linear time: char s[32]; sprintf(s, "%d", n); char c = s[strlen(s) - 1]; return c == '0' || c == '2' || c == '4' || c == '6' || c == '8';