Created
August 24, 2014 07:48
-
-
Save yuheiomori/c0bd452ed7f9d5e490fe to your computer and use it in GitHub Desktop.
Number of Ones (CodeEval) in Python 3.x
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# coding=utf-8 | |
import sys | |
def number_of_ones(s): | |
return bin(s).count("1") | |
def main(): | |
with open(sys.argv[1], "r") as f: | |
for line in f: | |
print(number_of_ones(int(line.rstrip()))) | |
if __name__ == '__main__': | |
main() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment