Last active
March 28, 2017 17:58
-
-
Save DavidPu/2555a043a59ad5eec41507d1fc5bd1ed to your computer and use it in GitHub Desktop.
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
#!/usr/bin/env python | |
# -*- coding: utf-8 -*- | |
import os | |
def happy_number(val): | |
nums = [] | |
nums.append(val) | |
while True: | |
new_num = sum([pow(int(c), 2) for c in str(val)]) | |
if new_num == 1: | |
return True | |
elif new_num in nums: | |
return False | |
nums.append(new_num) | |
val = new_num | |
def main(): | |
print(happy_number(int(os.sys.argv[1]))) | |
if __name__ == '__main__': | |
main() | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment