58
3
An integer is binary-heavy if its binary representation contains more 1
s than 0
s while ignoring leading zeroes. For example 1 is binary-heavy, as its binary representation is simply 1
, however 4 is not binary heavy, as its binary representation is 100
. In the event of a tie (for example 2, with a binary representation of 10
), the number is not considered binary-heavy.
Given a positive integer as input, output a truthy value if it is binary-heavy, and a falsey value if it is not.
Testcases
Format: input -> binary -> output
1 -> 1 -> True
2 -> 10 -> False
4 -> 100 -> False
5 -> 101 -> True
60 -> 111100 -> True
316 -> 100111100 -> True
632 -> 1001111000 -> False
2147483647 -> 1111111111111111111111111111111 -> True
2147483648 -> 10000000000000000000000000000000 -> False
Scoring
This is code-golf so fewest bytes in each language wins
What if my language can't handle the last test case because it's outside the bounds of what's considered a positive integer? – musicman523 – 2017-07-13T14:52:51.130
1@musicman523 afaik Standard I/O rules state that you only have to accept numbers representable by your language's number format. Note that "gaming" this by using something like boolfuck is considered a Standard Loophole – Skidsdev – 2017-07-13T14:53:47.517
Does any truthy/falsy value count or do we need two distinct values? – Erik the Outgolfer – 2017-07-13T15:22:49.817
@EriktheOutgolfer any value – Skidsdev – 2017-07-13T15:35:22.007
6
Aka A072600, if this helps anybody.
– dcsohl – 2017-07-13T17:59:32.490What about
0
? Is it an allowed input, and if so, is it considered non-heavy? It's kind of a degenerate case. Oh nvm, you said positive, which rules out 0. – Peter Cordes – 2017-07-14T16:40:52.810I will call such numbers "flaggy". – IllidanS4 wants Monica back – 2017-07-16T13:17:35.887
@IllidanS4 just make sure you don't miss out the
l
– Skidsdev – 2017-07-16T17:24:19.217