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.
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:
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!
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.6that counts as having
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.618you 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.
1may appear nowhere in your source code, because it's the very first digit. The code that outputs the
1.618may use any or all of the digits
, but none of
. For this purpose, all literals that are equivalent to a single digit are treated as that digit. So if your language can represent
'\t'you are not allowed to use that anywhere, where you couldn't use an
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
qdoesn't mean you get to use
qonce. Likewise, you are allowed to use a name twice if it refers to two different built-ins, like string
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.
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)/2or 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 dont' 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+2is fair game to generate the first
6(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 many
5s 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.
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.