# Write a time machine quine

Write a program that takes as input a string and an integer n, and outputs:

1. The string that was passed to the program n times ago;
2. A new program that will be used for the next invocation.

You cannot store any data outside of the program, and your program cannot call previous programs in the chain. If the string does not exist, output an empty string (but still output the next program).

Example run, where I use the notation program_n for each successive program (Of course, [This text is the nth program] would be replaced with actual code.)

$program_1 "One" 1 [This text is the second program]$ program_2 "Two" 1
One
[This text is the third program]
$program_3 "Three" 2 One [This text is the fourth program]$ program_4 "Four" 2
Two
[This text is the fifth program]
• Then try a=[],b=(x,y)=>(a.push(x),${a[a.length-y-1]||""}\na=${JSON.stringify(a)};b=${b}), which leaves you at 80 bytes (after replacing \n, of course). (If you still have a problem with my code possibly being a REPL snippet, then I have other suggestions :P). Oct 12, 2015 at 22:31 • Some of the last few revisions had noncompliant output formats. Rolled back to last compliant version. Oct 12, 2015 at 23:31 # Julia 1.0, 87 bytes (a=:(a=[ARGS[1];a];print("(a=(println($a[parse(Int,ARGS[2])]);\$a))[end]|>eval")))|>eval


Try it online!

smilar approach than Jakque's answer but reversing the history order:

• a stores [<last string>, ..., <first string>, <code>]
• based on this quine by Dennis
• the code is stored as a quote, which adds some ugly formatting but is equivalent