5 kyu

Calculate Fibonacci return count of digit occurrences

636 of 1,145user8476848

Description:

Fibonacci numbers are generated by setting F0 = 0, F1 = 1, and then using the formula:

Fn = Fn-1 + Fn-2

Your task is to efficiently calculate the nth element in the Fibonacci sequence and then count the occurrence of each digit in the number. Return a list of integer pairs sorted in descending order.

10 ≤ n ≤ 100000

Examples

f(10) = 55  # returns [(2, 5)], as there are two occurances of digit 5

f(10000)    # returns:
  [(254, 3),
   (228, 2),
   (217, 6),
   (217, 0),
   (202, 5),
   (199, 1),
   (198, 7),
   (197, 8),
   (194, 4),
   (184, 9)]

If two integers have the same count, sort them in descending order.

Your algorithm must be efficient.

Algorithms

Similar Kata:

Stats:

CreatedJul 4, 2016
PublishedJul 4, 2016
Warriors Trained3391
Total Skips409
Total Code Submissions4202
Total Times Completed1145
Python Completions636
Ruby Completions58
Haskell Completions51
JavaScript Completions186
C# Completions123
Java Completions140
Total Stars62
% of votes with a positive feedback rating92% of 225
Total "Very Satisfied" Votes192
Total "Somewhat Satisfied" Votes28
Total "Not Satisfied" Votes5
Total Rank Assessments10
Average Assessed Rank
5 kyu
Highest Assessed Rank
5 kyu
Lowest Assessed Rank
7 kyu
Ad
Contributors
  • user8476848 Avatar
  • suic Avatar
  • anter69 Avatar
  • JohanWiltink Avatar
  • Voile Avatar
  • Madjosz Avatar
  • user9644768 Avatar
  • hobovsky Avatar
  • Just4FunCoder Avatar
Ad