Forum — Daily Challenge
    • Categories
    • Recent
    • Tags
    • Popular
    • Users
    • Groups
    • Login

    Python 3 test to prove efficiency of this method

    Module 5 Day 6 Challenge Part 4
    1
    1
    16
    Loading More Posts
    • Oldest to Newest
    • Newest to Oldest
    • Most Votes
    Reply
    • Reply as topic
    Log in to reply
    This topic has been deleted. Only users with topic management privileges can see it.
    • S
      sympatheticseagull M5
      last edited by

      (Slowest) Bruteforce method:
      def trailing_zeroes_bf(n):
      import math
      count=0
      for i in str(math.factorial(n))[::-1]:
      if i=='0':
      count+=1
      else:
      break
      return count

      (Second fastest) Count 5s:
      def trailing_zeroes_5(n):
      count=0
      power=[i for i in range(100) if 5i<=n][::-1]
      for i in range(1,n+1):
      for pwr in power:
      if i%(5
      pwr)==0:
      count+=pwr
      break
      return count

      (Fastest) Divide rounded quotient by 5:
      def trailing_zeroes_improv5(n):
      import math
      count=0
      start=math.floor(n/5)
      while True:
      count+=start
      start=math.floor(start/5)
      if start==0:
      return count

      The method taught really is more efficient

      1 Reply Last reply Reply Quote 0

      • 1 / 1
      • First post
        Last post
      Daily Challenge | Terms | COPPA