Check Digitorial Permutation
Real-world version: Digits That Rebuild Their Factorial TotalThe statement here is our own: the same inputs, outputs and technique.
Take each digit of n, work out its factorial, and add those factorials together. Call the result the factorial total of n, taking 0! to be 1.
Return true when the digits of the factorial total are a rearrangement of the digits of n, that is when the two numbers use exactly the same digits the same number of times.
Examples
Example 1
- Input
- n = 154
- Output
- true
The digit factorials are 1, 120 and 24, which come to 145. Those digits are a rearrangement of 1, 5 and 4.
Example 2
- Input
- n = 123
- Output
- false
The digit factorials 1, 2 and 6 come to 9, which uses a digit that 123 does not.
Example 3
- Input
- n = 40585
- Output
- true
The digit factorials 24, 1, 120, 40320 and 120 come to 40585, the number itself.
Constraints
- 1 <= n <= 10^9
The signature
The editor starts with this. It matches the parent problem's shape, so a solution that works here works on a standard judge unchanged.
def is_digitorial_permutation(n: int) -> bool:public boolean isDigitorialPermutation(int n)Checking your plan…
How this problem was checked
- Passed: Reference solution run against 12 test cases: 12 passed
- Passed: 3 worked examples confirmed by running the code
- Passed: 0 eight-word sequences shared with the parent problem's text
- Passed: Agrees with an independent brute-force solution on random inputs
- Passed: Test set shown to catch deliberately broken solutions
- Passed: Reviewed by a separate quality pass
- Passed: Function arity matches the parent problem's