Created
March 2, 2016 06:44
-
-
Save davidbj/5c1ca7e567531d09d0ab to your computer and use it in GitHub Desktop.
给定一个非负整数num,重复的加每一位,直到最后只剩一位
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
| def add(*args): | |
| from functools import reduce | |
| sum = reduce(lambda x,y:x+y, args) | |
| return sum | |
| def sum(fn, num): | |
| while True: | |
| if num < 9: | |
| return num | |
| num = fn(*[int(i) for i in str(num)]) | |
| sum(add, 102) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment