9
Write some code that takes a single non-negative integer n and outputs the nth power of Phi (ϕ, the Golden Ratio, approximately 1.61803398874989) with the same number of decimal digits as the nth Fibonacci number.
Your code must produce the correct sequence of digits for all inputs up to at least 10 (55 decimal digits). The output must be human-readable decimal. You may choose whether to round the last digit to the closest value, or truncate the value. Please specify which one your code uses.
n and output, up to 10, rounding down:
0 1
1 1.6
2 2.6
3 4.23
4 6.854
5 11.09016
6 17.94427190
7 29.0344418537486
8 46.978713763747791812296
9 76.0131556174964248389559523684316960
10 122.9918693812442166512522758901100964746170048893169574174
n and output, up to 10, rounding to the closest value:
0 1
1 1.6
2 2.6
3 4.24
4 6.854
5 11.09017
6 17.94427191
7 29.0344418537486
8 46.978713763747791812296
9 76.0131556174964248389559523684316960
10 122.9918693812442166512522758901100964746170048893169574174
The 7th Fibonacci number is 13, so the output for n=7, ϕ7, has 13 decimal places. You must not truncate trailing zeros that would display too few digits; see output for 6 in the first table, which ends in a single zero to keep the decimal precision at 8 digits.
Maybe as a bonus, say what the highest number your program can correctly output is.
What about languages that can't handle that many decimal places? I got a 24 byte Pyth solution here that only works till n=7, since I can't display more than 15 decimal places. Should I post it anyway? – Denker – 2016-02-05T08:19:08.593
@DenkerAffe Sure, you can post it but with a note saying that it's not valid because it can't do the last three test cases. It might be inspiration for someone to add precision to your answer! – CJ Dennis – 2016-02-05T21:04:00.517