Description:
A non-integer representation of a number uses non-integer numbers as the bases of a positional numbering system.
e.g. Using the golden ratio (the irrational number 1 + √5/2 ≈ 1.61803399 symbolized by the Greek letter φ) as its base, the numbers 1
to 10
can be written:
Decimal Powers of φ Base φ
1 φ0 1
2 φ1 + φ−2 10.01
3 φ2 + φ−2 100.01
4 φ2 + φ0 + φ−2 101.01
5 φ3 + φ−1 + φ−4 1000.1001
6 φ3 + φ1 + φ−4 1010.0001
7 φ4 + φ−4 10000.0001
8 φ4 + φ0 + φ−4 10001.0001
9 φ4 + φ1 + φ−2 + φ−4 10010.0101
10 φ4 + φ2 + φ−2 + φ−4 10100.0101
Note that just as with any base-n system, numbers with a terminating representation have an alternative recurring representation. In base-10, this relies on the observation that 0.999...=1. In base-φ, the numeral 0.1010101... can be seen to be equal to 1 in several ways:
Conversion to nonstandard form: 1 = 0.11φ = 0.1011φ = 0.101011φ = ... = 0.10101010....φ
One representation in a non-integer base can be found using the greedy algorithm.
Challenge:
Given a number n
, a non-integer real base b
(1 < b < 10
, since, as @xnor pointed out in comments, representation in current format would be nonsensical), and decimal places l
, output a non-integer representation of n
in base b
to l
decimal places.
Test Cases:
n=10, b=(1 + Sqrt[5])/2, l=5, -> 10100.01010
n=10, b=E, l=5, -> 102.11201
n=10, b=Pi, l=5, -> 100.01022
n=10, b=1.2, l=14, -> 1000000000001.00000000000001
n=10^4, b=Sqrt[2], l=12, -> 100001000010010000010000100.000000000001
Note any valid representation is allowed. e.g.
n=450, b=E, l=6, -> 222010.221120
or
n=450, b=E, l=6, -> 1002020.211202
Prohibitions:
Calling Wolfram Alpha or any other external computational site is disallowed. Standard loopholes apply. This is Code Golf, so shortest code wins.
sin
?mod
?floor
? Isb
always given as a rational approximation of the input? This is missing a clear input spec at the moment... \$\endgroup\$"sin(1+sqrt(5))"
, i.e. whether we need to evaluate those expressions. \$\endgroup\$