Skip to content

Instantly share code, notes, and snippets.

@yuheiomori
Created August 24, 2014 07:48
Show Gist options
  • Save yuheiomori/c0bd452ed7f9d5e490fe to your computer and use it in GitHub Desktop.
Save yuheiomori/c0bd452ed7f9d5e490fe to your computer and use it in GitHub Desktop.
Number of Ones (CodeEval) in Python 3.x
# 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