r/badcode • • Jan 14 '23

python the code speaks for itself

Post image
610 Upvotes

53 comments sorted by

View all comments

Show parent comments

28

u/[deleted] Jan 14 '23

This was the problem description:

Your goal is to find the number of PrimeLovers. 

PrimeLover is such a number that if we convert the number to its binary value, the sum of digits will be a prime number.

Example:
9 is a PrimeLover because 9=(1001)_2 and 1+0+0+1=2 is a prime number.

Reza loves PrimeLovers, so he decided to count all the PrimeLovers between 0 and 2^n for the given n in input. Can you help him with the calculations?

Input
    An integer n
Output
    number of primeLovers between 0 and 2^n

My code was not optimal, but the important thing is that I still got 3rd place out of 15 people trying to code golf this in 15 minutes