It frustrates me that when you say "base 16", the 16 is in base 10. We need a base neutral way of writing down numbers when favoring a specific base would be inappropriate.
How it works
We define <n>
to be the nth prime. So <1>=2
, <2>=3
, <3>=5
. Note that every positive integer can be uniquely represented by the product of some number of <>
expressions. For example 6
can be written as <1>*<2>
.
However, in this form we still have numbers that need to be represented in some base. So we must recurse on each term. Until we reach the number 1, which has the same value almost in any base.
Your challenge is to print positive integer in this base neutral format.
I hope the examples will make things more clear:
Test cases
base 10 | base neutral | Explanation |
---|---|---|
1 |
1 |
1 can't be factored |
2 |
<1> |
2 is the first prime |
3 |
<<1>> |
3 is the second prime, 2 is the first prime |
4 |
<1> * <1> |
2 times 2 |
5 |
<<<1>>> |
5 is the third prime |
6 |
<1> * <<1>> |
2 times 3 |
10 |
<1> * <<<1>>> |
|
13 |
<<1> * <<1>>> |
6th prime |
255 |
<<1>> * <<<1>>> * <<<1> * <1>>> |
3 * 5 * 17 , 17 is the 7th prime, 7 is the 4th prime |
You may replace *
with any symbol of you prefer. You may replace <>
with {}
,[]
or ()
if you prefer, as long as you don't use the symbol replacing *
. The 1
must stay a 1
though. You may also add spaces or line breaks anywhere. The spaces in the examples are just for clarity and you may omit them.
For example, a valid output would be [[1], [1]]
or {{1 }%{1 }}
for the number 7.
This is code golf. Shortest answer in each language wins.
1
s? (just have<>
) \$\endgroup\$1
would not be representable \$\endgroup\$1*<1>
a valid representation of the number2
? It obviously isn't as short as just<1>
, but seems to evaluate correctly... \$\endgroup\$