Today's challenge is a new take on a classic. Without using the modulus operator or converting the number to binary to check the least significant bit, can you write a function to determine if an integer is odd or not?
Today's challenge is a new take on a classic. Without using the modulus operator or converting the number to binary to check the least significant bit, can you write a function to determine if an integer is odd or not?
Permalink: http://problemotd.com/problem/isodd-hard/
Content curated by @MaxBurstein
Comments:
Anonymous - 10 years, 1 month ago
reply permalink
Akshay Bist - 10 years, 1 month ago
Prime or odd? Which is it?
reply permalink
Max Burstein - 10 years, 1 month ago
My bad on that. Meant to say odd
reply permalink
Driphter - 10 years, 1 month ago
Clojure!
reply permalink
phansen73 - 10 years, 1 month ago
C++
reply permalink
asheehan - 10 years, 1 month ago
felt like playing with floor... in Ruby
reply permalink
Jojo Masala - 9 years, 10 months ago
Java:
private boolean nIsOdd(double n) { boolean isOdd = false; n /= 2.0; double roundDown = (int) n; double roundUp = roundDown + 1; if((n > roundDown) && (n < roundUp)) { isOdd = true; } return isOdd;
reply permalink