Numbers Having Digits Occurring Only Once
Description:
Numbers that have their digits only once are: 1234, 96421, 13. In this kata we want to collect this kind of numbers.
Obviously, 133, 881112 and 12345691 are not and will be discarded.
We have to get all the numbers composed by two different digits that are less than 68
.
The list of numbers that pass the above constraints is :
[10, 20, 30, 40, 50, 60, 12, 21, 13, 31, 14, 41, 15, 51, 16, 61, 17, 18, 19, 23, 32, 24, 42, 25, 52, 26, 62, 27, 28, 29, 34, 43, 35, 53, 36, 63, 37, 38, 39, 45, 54, 46, 64, 47, 48, 49, 56, 65, 57, 58, 59, 67]
total numbers: 52
total sum of these numbers: 2002
Now we want a special subset of these numbers, the ones that have their digits in increasing order from left to right. They are:
[12, 13, 14, 15, 16, 17, 18, 19, 23, 24, 25, 26, 27, 28, 29, 34, 35, 36, 37, 38, 39, 45, 46, 47, 48, 49, 56, 57, 58, 59, 67]
total numbers: 31
total sum of these numbers: 1057
The ones that have their digits in decreasing order from left to right are:
[10, 20, 30, 40, 50, 60, 21, 31, 41, 51, 61, 32, 42, 52, 62, 43, 53, 63, 54, 64, 65]
total numbers:21
total sum of these numbers:945
Create the function collect_num()
that receives the number of digits, d
of the wanted numbers (2 ≤ d ≤ 10), then an integer limit
and finally, may receive or not a string, order
that if it exist may have three values: increas
or decreas
or bouncy
. (Bouncy numbers are the ones that their digits are not increasing and nor decreasing, property that will have numbers with three digits and above obviously.)
The function has to output an array of two elements, the first one, the amount of numbers and the second one the sum of them.
So the cases shown above are:
collect_num(2, 68) == [52, 2002]
collect_num(2, 68, "increas") == [31, 1057]
collect_num(2, 68, "decreas") == [21, 945]
Think in the result of these cases:
collect_num(2, 68, "bouncy") == [0, 0]
collect_num(3, 68) == [0, 0]
collect_num(4, 680) == [0, 0]
collect_num(14, 8888888888, "bouncy") == [0, 0]
Enjoy it!
Similar Kata:
Stats:
Created | Nov 11, 2016 |
Published | Nov 11, 2016 |
Warriors Trained | 150 |
Total Skips | 47 |
Total Code Submissions | 208 |
Total Times Completed | 11 |
Python Completions | 11 |
Total Stars | 6 |
% of votes with a positive feedback rating | 80% of 5 |
Total "Very Satisfied" Votes | 4 |
Total "Somewhat Satisfied" Votes | 0 |
Total "Not Satisfied" Votes | 1 |
Total Rank Assessments | 6 |
Average Assessed Rank | 5 kyu |
Highest Assessed Rank | 4 kyu |
Lowest Assessed Rank | 5 kyu |