Created
February 24, 2014 07:17
-
-
Save deppyu/9183277 to your computer and use it in GitHub Desktop.
计算一个数字的出现1的次数
This file contains 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 counter(n) | |
return 0 if n<=0 | |
(n%10) == 1 ? 1+counter(n/10) : counter(n/10) | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment