diff options
Diffstat (limited to 'challenge-079/lubos-kolouch/python/ch-1.py')
| -rw-r--r-- | challenge-079/lubos-kolouch/python/ch-1.py | 30 |
1 files changed, 30 insertions, 0 deletions
diff --git a/challenge-079/lubos-kolouch/python/ch-1.py b/challenge-079/lubos-kolouch/python/ch-1.py new file mode 100644 index 0000000000..18cd9792cd --- /dev/null +++ b/challenge-079/lubos-kolouch/python/ch-1.py @@ -0,0 +1,30 @@ +#!/bin/env python +""" +=============================================================================== +# +# FILE: ch-1.py +# +# USAGE: ./ch-1.py +# +# DESCRIPTION: Perl Weekly Challenge Task 1 +# https://perlweeklychallenge.org/blog/perl-weekly-challenge-079/ +# Count set bits +# +# AUTHOR: Lubos Kolouch +#============================================================================== +""" + + +def get_dec2bin(what: int): + """ Get the number of set 1s """ + + count = 0 + for i in range(1, what+1): + mod_str = str(bin(i))[2:] + count += sum(list(map(int, mod_str))) + + return count + + +assert get_dec2bin(4) == 5 +assert get_dec2bin(3) == 4 |
