Digit balanced numbers
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.
- N will have no leading zeroes.
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.
[Python 3], 43 bytes …
2h ago
Vyxal 3, 2 bytes ``` ⊞≈ ` …
24h ago
Vyxal, 4 bytes ``` Ċvt≈ …
24h ago
3 answers
Vyxal 3, 2 bytes
⊞≈
Shortest you'll probably get barring fractional bytes.
Explained
⊞≈ ## Input is a number
⊞ ## Counts of all items in the number
≈ ## Are they all the same?
0 comment threads
Vyxal, 4 bytes
Ċvt≈
Outputs 1
for true, 0
for false. The footer is to convert the output to the provided test case format.
Explained
Ċvt≈
Ċ # [x, input.count(x)] for x in uniquify(input)
vt # last item of each item in ^
≈ # are all items the same?
💎
Created with the help of Luminespire.
0 comment threads