Implement the Fibonacci-quine A Quine is a program which outputs its source when run.

In this challenge, You should make a Fibonacci-quine, a variant of the quine.



What is a Fibonacci-quine?

A Fibonacci-quine is a program, which outputs a modification of the source by the following rule:

The initial source should be ...2.... In other words, the source should contain 2. (Why 2? If it was 1, Nobody would know if it was the first 1 or the second, Even the program itself)

When run, You should output the source, but only the specific number (In this stage, 2) changed to the next number of the fibonacci sequence. For example, ...3.... Same goes for the output, and the output of the output, etc. You may support integers for up to 2^32-1. For integers over that limit, the next output is on your choice.


  OP's note
  
  I would really like to see a creative solution for this. I couldn't think of a single solution for this, since Both of the two important aspects of the challenge, fibonacci and quine, is not easy. I'll be waiting then!
Mathematica, 61 bytes

ToString[#0 /. v:2 :&gt; RuleCondition[Round[GoldenRatio v]]] &amp; 


Note that there is a trailing space. This is a function quine, i.e. the above code evaluates to an unnamed function which, if called returns the code itself as a string (with 2 changed to the next Fibonacci number).

This was suprisingly tricky to get to work. The basic idea is to take the function itself (with #0) and replace a number in that function with the next one using /. v:2 :&gt; nextFib[v]. However, nextFib wouldn't get evaluated at this stage so we wouldn't really end up with the new number in the source code. After searching around for a while to figure out how to force immediate evaluation, I found this great post on Mathematica.SE. The "standard" technique uses a With block which forces evaluation, but the second answer by WReach contains a shorter alternative using the undocumented built-in RuleCondition which also forces evaluation.

The way we compute the next Fibonacci number is by making use of the fact that the ratio of consecutive numbers is roughly the golden ratio 1.618... and this is accurate up to rounding. So we don't need to keep track of the last two numbers and can simply do Round[GoldenRatio v]. This will never lose precision since Mathematica's GoldenRation is a symbolic value and therefore Round can always compute an accurate result.

In summary:

... #0 ... &amp;


An unnamed function, where #0 refers to the function object itself.

... /. v:2 :&gt; ...


Find a 2 in the expression tree of the function (this 2 of course only matches itself), call it v and replace it with...

... RuleCondition[Round[GoldenRatio v]]


... the next Fibonacci number.

ToString[...]


And convert the resulting expression tree to its string representation.