Created
August 23, 2014 06:43
-
-
Save yuheiomori/0b067b695bd11acf3b89 to your computer and use it in GitHub Desktop.
Decimal To Binary (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 decimal_to_binary(n): | |
if n == 0: | |
return '0' | |
result = '' | |
while n > 0: | |
result = str(n % 2) + result | |
n //= 2 | |
return result | |
def main(): | |
with open(sys.argv[1], "r") as f: | |
for line in f: | |
print(decimal_to_binary(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