Skip to content

Instantly share code, notes, and snippets.

@kylelong
Created March 29, 2019 22:34
Show Gist options
  • Save kylelong/5ae259c48ef103bf94f5018cc873dbdb to your computer and use it in GitHub Desktop.
Save kylelong/5ae259c48ef103bf94f5018cc873dbdb to your computer and use it in GitHub Desktop.
Cassido's interview question of the week (3/24/19)
#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