Created
March 29, 2019 22:34
-
-
Save kylelong/5ae259c48ef103bf94f5018cc873dbdb to your computer and use it in GitHub Desktop.
Cassido's interview question of the week (3/24/19)
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
#Given an integer N, find the number of trailing zeroes | |
# in the base 16 representation of the factorial of N. | |
def trailing(number) | |
num = factorial(number).to_s(16) | |
length = num.length | |
chars = num.split('') | |
count = 0 | |
for c in num.split('').reverse() | |
if(c == '0') | |
count += 1 | |
else | |
puts count | |
break; | |
end | |
end | |
end | |
#Calculates the factorial of n | |
def factorial(n) | |
if n == 0 | |
return 1 | |
else | |
return n * factorial(n - 1) | |
end | |
end | |
trailing(6) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment