TSQL Challenge 20 - Identify repeating digits in Fibonacci Series
This challenge has absolutely no relevance to a real-life problem, but it is very interesting because it tests your programming skills and abstract thinking.
The Fibonacci series is defined as 1, 1, 2, 3, 5, 8, 13, 21, 34, 55 etc, where each number in the series is the sum of the two numbers before it. For example: 34 = 13+21, 55 = 21+34 etc. Some Fibonacci numbers have repeating digits, like 55 for example, which has a single repeating digit. The Fibonacci number 17711 has 2 (different) repeating digits.
Your job is to look through the first 92 Fibonacci numbers (since the 93rd number is beyond BIGINT range) and produce a result set showing the 5 lowest Fibonacci numbers for each quantity of (different) repeating digits.
Expected Output
NumRepeats FiboNumber
----------- --------------------
1 55
1 144
1 233
1 377
1 317811
2 17711
2 102334155
2 433494437
2 32951280099
2 53316291173
3 27777890035288
3 117669030460994
3 5527939700884757
3 14472334024676221
3 1779979416004714189
4 1100087778366101931
Rules
- The quantity of repeating digits has to refer to DIFFERENT repeating digits. For example, if there were a Fibonacci number of 344144, this would just have 1 repeating digit, not 2.
- The repeating digits must be ADJACENT to each other. For example, if there were a Fibonacci number of 34532, the digit of 3 repeats itself, but the 3’s are not adjacent to each other.
- The repeating digits consist of 2 or more adjacent digits. For example, if there were a Fibonacci number of 23333333, the digit of 3 is considered a single repeating digit. It doesn't matter how many times it repeats.
- This should be done by a single query.
- The output should look like the result given above (sorted by NumRepeats, FiboNumber)
Notes
- Read the Submission Guidelines and make sure that your solution follows them.
- The solution should work on SQL Server 2005, 2008 or later versions
- Use this forum for any questions related to TSQL Challenge #20
Join SQL Server Challenge Idea Contest
We would like to welcome you to the SQL Server Challenge Idea Contest 2010-Q1. Submit an interesting challenge idea or details of a TSQL problem that you have seen, heard or solved. Authors of winning solutions will get a cash prize of $100 and 10 SQL Stars. Read More >>
| Syntax Bookmark of the Day! – SQL Server Database Mail Syntax |
|
|
About the Author
Challenge Evaluation Details
Though the evaluation of this TSQL Challenge is completed and winners are announced, you can still submit a solution and we will be very happy to review it. Before submitting, make sure that your solution passes the basic testing and logic testing and the performance statics are good. See the submission guidelines before submitting your solution.