4 kyu

Trailing zeros in factorials, in any given integer base

60 of 653Dr Phil

Description:

The factorial function is defined as follows:

0! = 1
n! = 1 * 2 * 3 * 4 * ... * n-2 * n-1 * n

Usually, the factorials of large numbers will have trailing zeroes. Your task is to create a function which returns the number of trailing zeroes of num! in a given base.

Here's two examples to get you started:

(num = 15, base = 10) => 3
# 15! = 1307674368000, which has 3 trailing 0's

(num = 7, base = 2) => 4
# 7! = 5040 = 0b1001110110000, which has 4 trailing 0's

Your code should be able to handle some very large numbers.

Note:

  • num >= 0
  • base >= 2

HINT: Should you not make any headway after trying a long time, you should try this kata first.

Mathematics
Algorithms

Stats:

CreatedOct 20, 2014
PublishedOct 20, 2014
Warriors Trained8431
Total Skips685
Total Code Submissions9182
Total Times Completed653
Ruby Completions60
JavaScript Completions175
Python Completions397
Java Completions65
OCaml Completions7
Total Stars170
% of votes with a positive feedback rating93% of 131
Total "Very Satisfied" Votes117
Total "Somewhat Satisfied" Votes10
Total "Not Satisfied" Votes4
Total Rank Assessments9
Average Assessed Rank
4 kyu
Highest Assessed Rank
2 kyu
Lowest Assessed Rank
5 kyu
Ad
Contributors
  • Dr Phil Avatar
  • jhoffner Avatar
  • GiacomoSorbi Avatar
  • Voile Avatar
  • Madjosz Avatar
  • hobovsky Avatar
  • user8436785 Avatar
  • QKiryu Avatar
  • Just4FunCoder Avatar
  • KayleighWasTaken Avatar
Ad