← Back to challenges

Non-Repeating Integers

JavaScriptHardalgorithmsmathnumbers

Instructions

Let's define a non-repeating integer as one whose digits are all distinct. 97653 is non-repeating while 97252 is not (it has two 2's). Among the binary numbers, there are only two positive non-repeating integers: 1 and 10. Ternary (base 3) has ten: 1, 2, 10, 20, 12, 21, 102, 201, 120, 210.

Write a function that has as it's argument the base or radix and returns the number of non-repeating positive integers in that base.

Examples

nonRepeats(2) ➞ 2

nonRepeats(4) ➞ 48

nonRepeats(5) ➞ 260

nonRepeats(6) ➞ 1630

Notes

Assume a radix of 1 is not legitimate.

javascript
Loading editor…
to run
Walks through the solution with reasoning and edge cases.