Created
June 7, 2017 01:17
-
-
Save fmasanori/21b299253ba1fe203dd17b977db2b688 to your computer and use it in GitHub Desktop.
Dado um inteiro n positivo, calcula quantos zeros existem no final
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
n = 908007000 | |
print (len(str(n)) - len(str(int(str(n)[::-1])))) | |
print (len(str(n)) - len(str(n).rstrip('0'))) | |
from itertools import takewhile | |
l = str(n).split('0') | |
print(len(list(takewhile(lambda x: not x, reversed(l))))) | |
import re | |
print(len(re.findall('0*$',str(n))[0])) | |
f = lambda m: (lambda g: g(m, g))(lambda n, f: 1 + f(n // 10, f) if n % 10 == 0 else 0) | |
print (f(n)) | |
f = lambda x, y: y if x % 10 != 0 else f(x/10,y+1) | |
print (f(n, 0)) | |
f = lambda n : 0 if n%10 else 1 + f(n//10) | |
print (f(n)) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment