DEV Community

Shashwat Seth
Shashwat Seth

Posted on

Define a haskell function that returns true when the binary representation of a number has more 0s than 1s.

Define a function moreZeros :: Int -> Bool such that moreZeros n returns True exactly when the binary representation of n has strictly more 0s than 1s.

Test cases:
moreZeros 0 = True
moreZeros 1 = False
moreZeros 2 = False
moreZeros 4 = True

Latest comments (1)

Collapse
 
cappe987 profile image
Casper

When you ask for help you should try to explain what you are struggling with? Is it the Haskell part? Do you have any idea on how to do the logic? Do you need help converting an integer to binary? Don't just copy-paste the problem. That just makes it look like you put no effort into solving it.

To solve this you need to first convert the integer to a binary representation. Then count the 1's and 0's and compare them.