Beta

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!

Fundamentals
Data Structures
Algorithms
Mathematics
Logic
Strings
Permutations

Stats:

CreatedNov 11, 2016
PublishedNov 11, 2016
Warriors Trained150
Total Skips47
Total Code Submissions208
Total Times Completed11
Python Completions11
Total Stars6
% of votes with a positive feedback rating80% of 5
Total "Very Satisfied" Votes4
Total "Somewhat Satisfied" Votes0
Total "Not Satisfied" Votes1
Total Rank Assessments6
Average Assessed Rank
5 kyu
Highest Assessed Rank
4 kyu
Lowest Assessed Rank
5 kyu
Ad
Contributors
  • raulbc777 Avatar
  • user8436785 Avatar
Ad