Create a program or function that takes an integer input, which outputs a new program/function as specified below.
n: Time in seconds before the Time Bomb explodes.
The original program which had the time in seconds
n as input, will output a new program/function that does the following:
nseconds passed since the previous program was run? Print
- Else: Print a program/function which, when run itself, resets the timer back to
nseconds (and acts the same as the first outputted program/function).
NOTE: It is not exactly the same as the first outputted program/function (in most languages at least), because the starting time has changed (see clarification example below).
Let's say the original program is
ABC and the input is
DEF(60)is run within 60 seconds, it will output
DEF_G(60), which acts exactly the same as
DEF(60), but with a new starting time.
DEF(60)is run after 60 seconds, it will output
Clarification example what I mean with 'starting time':
- Base program with input
60seconds is run at
12:00:00. It outputs the first output program with a starting time of
- This first output program with starting time of
12:00:00is run at
12:00:45. It outputs a second output program with a starting time of
- This third output program with a starting time of
12:00:45is run at
12:01:25. It outputs a fourth output program with a starting time of
- This fourth output program with a starting time of
12:01:25is run at
12:05:00. It will output
Note how the first output would print
12:01:00, but the output program has progressed so even though it's
12:01:25 at step 3, it will still output the next program instead of
BOOM! (because the output-of-output programs has starting times beyond that first output program).
- Default quine rules apply.
- At least
nseconds should have passed. So if the input is
60and starting time was
12:01:00it will still output the v2 program, but at
12:01:01it will output
- The output programs will not take any input (except for an empty unused parameter if it's shorter). The starting time should be given to the next programs as 'hard-coded' value (which is why the output of an output program isn't exactly the same as the previous (in most languages).
- Only the size of your main program/function is counted in terms of bytes.
- You can output the program/function either as string (or comparable reasonable format, like byte/character array/list), as function if your language supports this, or other reasonable formats (please ask if you aren't sure).
- This is code-golf, so shortest answer in bytes wins.
Don't let code-golf languages discourage you from posting answers with non-codegolfing languages. Try to come up with an as short as possible answer for 'any' programming language.
- Standard rules apply for your answer, so you are allowed to use STDIN/STDOUT, functions/method with the proper parameters and return-type, full programs. Your call.
- Default Loopholes are forbidden.
- If possible, please add a link with a test for your code.
- Also, please add an explanation if necessary.