Digit balanced numbers
Sandbox question
- Would this be better as indicating whether a specific number is digit balanced, rather than asking for the number of digit balanced numbers of a given length? Otherwise the outputs quickly become larger than most languages can handle, so either I'd have to keep the number of test cases very small, or have a set of test cases where most don't apply to most languages.
How many N digit numbers have balanced numbers of distinct digits?
You may struggle to calculate this by brute force beyond single digit inputs, but the OEIS has a closed form formula under Number of n-digit positive numbers whose digits occur with equal frequency.
Input
- A positive integer N.
Output
- A positive integer M.
- This is the total number of N digit positive integers (N digits with no leading zeroes) that have equal numbers of each distinct digit that is present.
Example
Input 4
- 1234 has 1 of each present digit, so counts towards the total.
- 1223 has 1 1 and 1 3, but 2 2s, so does not count.
- 1212 has 2 1s and 2 2s, so counts.
- 1000 has 1 1 and 3 0s, so does not count (zeroes are relevant).
- 5555 has 4 5s, so counts.
- 0123 has a leading 0, so is regarded as a 3 digit integer and does not count towards the total for 4 digit integers.
Assessing each 4 digit integer this way gives a total of 4788 that have balanced digits.
Test cases
Test cases are in the format input : output
.
1 : 9
2 : 90
3 : 657
4 : 4788
5 : 27225
6 : 146619
7 : 544329
8 : 2112084
9 : 3447369
10 : 28995255
11 : 9
12 : 1488185631
13 : 9
14 : 73556822205
15 : 38222232057
16 : 3321970172244
17 : 9
18 : 138479121435807
19 : 9
20 : 2209806802214163
21 : 19711054740199689
22 : 28570005
23 : 9
24 : 15574715941421647071
25 : 141378216540777225
26 : 421224309
27 : 9724427617362202602009
Scoring
This is a code golf challenge. Your score is the number of bytes in your code.
Explanations are optional, but I'm more likely to upvote answers that have one.
Does a number have balanced numbers of distinct digits? That is, do the number's digits appear with equal frequency?
Input
- A positive integer N.
Output
- An indication of whether the number has balanced digits.
- This can be a truthy or falsy value (where you can choose whether truthy corresponds to balanced or unbalanced), or one of 2 distinct values.
Examples
- 1234 has 1 of each present digit, so is balanced.
- 1223 has 1 1 and 1 3, but 2 2s, so is not balanced.
- 1212 has 2 1s and 2 2s, so is balanced.
- 1000 has 1 1 and 3 0s, so is not balanced (zeroes are relevant).
- 1100 has 2 1s and 2 0s, so is balanced.
- 5555 has 4 5s, so is balanced.
Test cases
Test cases are in the format input : output
.
Note that you may choose any 2 distinct values instead of true
and false
, or you may use truthy and falsy outputs rather than consistent values.
1 : true
22 : true
98 : true
222 : true
234 : true
3456 : true
3434 : true
3355 : true
4664 : true
123456789 : true
234567890 : true
11223344 : true
111222333 : true
132321213 : true
54554445 : true
999999999 : true
778 : false
565 : false
1223 : false
2123 : false
999999998 : false
999989999 : false
112233445 : false
999999990 : false
101202303 : false
Scoring
This is a code golf challenge. Your score is the number of bytes in your code.
Explanations are optional, but I'm more likely to upvote answers that have one.
0 comment threads