← Back to challenges

New Numbers

PythonHardnumbersvalidationmath

Instructions

A new number is a number that is not a permutation of any smaller number. 869 is not a new number because it is just a permutation of smaller numbers, 689 and 698. 509 is a new number because it can't be formed by a permutation of any smaller number (leading zeros not allowed).

Write a function that takes a non-negative integer and returns True if the integer is a new number and False if it is not.

Examples

is_new(3) ➞ True

is_new(30) ➞ True

is_new(321) ➞ False

is_new(123) ➞ True

Notes

A curious fact: out of the first one million integers, only 8002 are new.

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