11
4
Background:
Pi (π
) is a transcendental number, and therefore it has a non-terminating decimal representation. Similar, the representation doesn't terminate if written in any other integer base. But what if we wrote it in base π
?
Digits in decimal represent powers of 10, so:
π = 3.14… = (3 * 10^0) + (1 * 10^-1) + (4 * 10^-2) + …
So in base π
, the digits would represent powers of π
:
π = 10 = (1 * π^1) + (0 * π^0)
In this new base, integers now have non-terminating representations. So 10 in decimal now becomes the following:
10 => 100.01022… = (1 * π^2) + (0 * π^1) + (0 * π^0) + (0 * π^-1) + (1 * π^-2) + …
Note that in base π
the digits used are 0,1,2,3 because these are the digits less than π
.
Challenge:
Given a non-negative integer x
, either:
Output (without halting) its representation in base
π
. If the number has a finite representation (0, 1, 2, 3), then the program may halt instead of printing infinite zeros.Take an arbitrarily large integer
n
, and output the firstn
digits ofx
in baseπ
.
Rules:
- Since a number has multiple possible representations, you must output the one that appears the largest (normalized). Just as
1.0 = 0.9999…
in decimal, this problem exists in this base, too. In baseπ
, one is still1.0
, but could also be written as0.3011…
, for example. Similarly, ten is100.01022…
, but could also be written as30.121…
or23.202…
. - This is code-golf, so fewest bytes wins. Program or function.
- No built-ins (I'm looking at you, Mathematica)
Results:
0 = 0
1 = 1
2 = 2
3 = 3
4 = 10.220122021121110301000010110010010230011111021101…
5 = 11.220122021121110301000010110010010230011111021101…
6 = 12.220122021121110301000010110010010230011111021101…
7 = 20.202112002100000030020121222100030110023011000212…
8 = 21.202112002100000030020121222100030110023011000212…
9 = 22.202112002100000030020121222100030110023011000212…
10 = 100.01022122221121122001111210201201022120211001112…
42 = 1101.0102020121020101001210220211111200202102010100…
1337 = 1102021.0222210102022212121030030010230102200221212…
9999 = 100120030.02001010222211020202010210021200221221010…
First 10,000 digits of ten in base Pi
Verification:
You can verify any output you want using the Mathematica code here. The first parameter is x
, the third is n
. If it times out, pick a small n
and run it. Then click "Open in Code" to open a new Mathematica worksheet with the program. There's no time limit there.
Convert the resulting output to a number here.
Related:
4Does "no built-ins" include no built-ins for getting Pi? – Nit – 2018-04-03T20:28:36.833
3@Nit No, it means no built-in that completes or trivializes the entire task. Or if such a built-in exists (like the Mathematica one I showed), make sure to include a solution without the built-in which will be used for the answer's actual score. That way, you still get to show people that the built-in exists. – mbomb007 – 2018-04-03T20:32:04.707
Can we use a limited-precision π literal? – Erik the Outgolfer – 2018-04-03T20:52:58.367
@EriktheOutgolfer No. That will not be sufficient to arrive at correct output. Though I'm not sure how many digits are required for an input of
n
, I'd guess that Pi must have at leastn
digits of precision. – mbomb007 – 2018-04-03T21:23:53.367@mbomb007 Well, outputs wrong only because of floating-point limitations are allowed by default, that's why I asked. – Erik the Outgolfer – 2018-04-03T21:25:55.087
@EriktheOutgolfer I gave a list of 10000 digits of ten in base Pi. If you can't arrive at that output, then your program is not correct. – mbomb007 – 2018-04-03T21:26:47.623
Related – FryAmTheEggman – 2018-04-03T22:11:38.287
8IMO: Banning base conversion builtins just adds needless complexity. If you feel like it trivializes the challenge, well, maybe the challenge is just that: trivial – Conor O'Brien – 2018-04-03T23:19:17.617
Strongly rely on real storage – l4m2 – 2018-04-04T08:48:33.547
I feel like there was a guidance against banning built-ins and instead simply not upvoting answers that were uninteresting. Anyone have a meta-link to that? – Lyndon White – 2018-04-06T09:53:27.043
@LyndonWhite I'm well aware. That's why I said people can post an answer using them, as long as they also post one without. That way they also have to do the work. We all know that people upvote short answers regardless of the recommendations. – mbomb007 – 2018-04-06T14:10:15.393