This was fun! However with only three digits, the fun was over way too soon. This challenge is similar, but we'll keep the fun going.
The Challenge
Print as many digits of the Golden Ratio φ as possible. The Golden Ratio is defined as the number that satisfies φ = (φ + 1)/φ and the first 100 digits are given by:
1.6180339887498948482045868343656381177203091798057628621354486227052604628189024497072072041893911375...
This challenge is not about computing φ! It's about printing as many digits as possible without using any method for doing that twice. So find as many creative ways to get your digits as you can!
Restrictions
By itself, printing the digits of φ would be a bit too simple, so here are the rules:
You have to construct the number in order from left to right, either by printing it piece by piece or by constructing a string from left to right and printing it at the end - you could even generate an array of digit characters and then join it and print it, as long as you do it in order. In the following rules "print" and "output" may refer to any of those processes (e.g. if you're building a string, and the string contains
1.6
that counts as having1.6
already printed).For your code you get a budget of 15 characters per digit. The period does not count towards that budget, but has to be printed as well. Note that the restriction is only on total code size: you may use more than 15 characters for any digit as long as you don't use more on average. In fact, you may build up a "debt" in characters and "pay it off" later. E.g. to print
1.618
you have 60 characters.Standard-library includes/imports do not count towards the code size. But you can't give those includes shorthand aliases for free!
You must not use the digit you are currently generating, nor any you have already printed. E.g.
1
may appear nowhere in your source code, because it's the very first digit. The code that outputs the8
in1.618
may use any or all of the digits[0234579]
, but none of[168]
. For this purpose, all literals that are equivalent to a single digit are treated as that digit. So if your language can represent9
as'\t'
you are not allowed to use that anywhere, where you couldn't use an9
instead.You must not produce multiple digits at once. It should be possible to clearly split your code into chunks that generate one digit a time.
You must not refer to any built-in function, mathematical/boolean/bit-wise/string operator, variable or constant which you have used in code that generated an earlier digit. Exceptions are integer-to-string conversion, string concatenation and printing functions which you might need for every single digits. Note that it doesn't matter by which name you refer to any built-in: just because you alias a built-in
PI
to bothp
andq
doesn't mean you get to usep
once andq
once. Likewise, you are allowed to use a name twice if it refers to two different built-ins, like stringlength
and arraylength
.If your programming language doesn't have functions use your best judgement on what the equivalent would be - e.g. for bash scripting, invoking other programs should follow the rules imposed on functions
Your submission must be written in a single language. So no executing another language's interpreter to get access to that language's built-ins as well.
Implications
The following points are all implied by the above rules, but I add them here to avoid questions that have already come up in the sandbox:
- You're not allowed to overwrite parts of your output by printing some backspaces (usually
'\b'
) in between. - Loops which generate/output multiple digits are forbidden. (Loops that compute a single digit are fine, though.)
- Using an obfuscated version
(1 + √5)/2
or dividing Fibonacci numbers to obtain more than a single digit is forbidden. - You cannot precalculate the 10 digits and store them in 10 variables and then just refer to those, because those variable references don't generate the digit - the code that fills the variable does, so this is a violation of rule 6.
- In fact, you can't reuse any previous (or intermediate results), because that would mean two digits would share code for being generated.
- Otherwise, you can use any means whatsoever (which do not have to purely mathematical) to generate the digits. (And you should!)
- In fact there is no need to calculate anything, if you can pull out the correct digits from many different places using your standard library.
- You may use an operator multiple times while generating a single digit, so
2+2+2
is fair game to generate the first6
(although it's unlikely the shortest). - You may use any literal as often as you want, because they are not built-in constants. So as long as you don't have to print
5
, you can as many5
s in your code as you want. - You can't hardcode the output, because that would involve using the digits you are outputting.
In short: don't use any method of generating digits twice and don't use the digit you are currently outputting or any have already printed.
If you do spot a loophole which allows you to get a (quasi-)infinite score, please don't ruin the challenge by exploiting it, but let me know so I can see if the loophole can be fixed without breaking anything.
Scoring
The program that prints the highest number of digits correctly wins. In case of a tie the shorter code breaks the tie.
Please add an ungolfed commented version that identifies which part of your code generates which digit.
PS: If anyone beats the 100 digits above, here are some more.
x = (x+1)/x
(orx^2 = x+1
) (orx^2-x+1
). \$\endgroup\$