Previous part was considered encoding of non-empty nested lists with a positive integer.
Reminding the coding procedure \$G(x)\$:
- If \$x\$ is a number, \$G(x) = 2^x\$
- If \$x\$ is a list \$[n_0, n_1, n_2, n_3, …]\$, \$G(x) = 3^{G(n_0)} \cdot 5^{G(n_1)} \cdot 7^{G(n_2)} \cdot 11^{G(n_3)} \cdot...\$
Bases are consecutive primes.
The number will be unique (it can be proved, but you don’t have to do it). So always there is valid reverse procedure: determine an array-structure from a given number, or verify that no structure exists for that number. This is the task of this challenge.
Input
Positive integer (possibly very large)
UPD
I know that in CG does not approve strict validation of input.
But here invalid in general number means: negative, float, with typo etc.
You don’t have to check it out!
But figuring out if a number is valid encoding or not is part of the challenge.
Output UPD
Very sorry I missed the important thing ((
Single number (if it is suitable for the first part of the procedure, see test cases)
or
non-empty list of non-negative integers (possibly nested, without empty sub-lists) that is encoded with given number;
printed in any appropriate form: as pure array, string, json etc.
OR
any appropriate message ([ ], None, -1
etc), if there is no decoding for this number.
Test cases
1 → 0
2 → 1
3 → [0]
4 → 2
5 → None
6 → None
7 → None
8 → 3
9 → [1]
10 → None
666 → None
729 → None
1024 → 10
1215 → None
3375 → [[0], [0]]
77777 → None
5859375 → [0, [1]]
666777666 → None
2210236875 → [3, 2, 1, 0]
7625597484987 → [[[0]]]
1111111111111111111111111111 → None
729
,1215
. I think they're both invalid. \$\endgroup\$-1
where the encoding is immediately malformed? (I assume not, but it's worth clarifying.) \$\endgroup\$8
is an invalid input, although it could be also decoded to3
, as assumed by @DominicvanEssen. Could you please clarify? \$\endgroup\$