Write a program that takes as input a string and an integer n
, and outputs:
- The string that was passed to the program
n
times ago; - 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]
$ program_5 "Five" 1
Four
[This text is the sixth program]
program_n+1
's to the output line like[program_3, One]
if that is what you would like to see. If both output goes to stdout how should they be separated? Also are function allowed instead of full programs? \$\endgroup\$