4 ms·
Brute force in python: n = 12345 # your input s = ''.zfill(n) # fill as many zeroes while len(s)>3: s=s[3:] # trim 3 zeroe
by Kilimanjaro 14y ago
Brute force in python:
n = 12345 # your input
s = ''.zfill(n) # fill as many zeroes
while len(s)>3: s=s[3:] # trim 3 zeroes each time
print 'divisible by 3' if len(s)==3 else 'nop'
- Kilimanjaro 14y agoBtw, a loop counter will tell you the result and the reminder will be len(s) at the end.
- beambot 14y agoUse slicing to do the counting for you: n_divideby_3 = lambda n: len(''.zfill(n)[2::3])