Challenge:
Create a program or function that takes an integer input, which outputs a new program/function as specified below.
Input:
Integer n
: Time in seconds before the Time Bomb explodes.
Output:
The original program which had the time in seconds n
as input, will output a new program/function that does the following:
- Has
n
seconds passed since the previous program was run? PrintBOOM!
- Else: Print a program/function which, when run itself, resets the timer back to
n
seconds (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).
Pseudo-code Example:
Let's say the original program is ABC
and the input is 60
seconds:
ABC
& 60
outputs DEF(60)
.
- If
DEF(60)
is run within 60 seconds, it will outputDEF_G(60)
, which acts exactly the same asDEF(60)
, but with a new starting time. - If
DEF(60)
is run after 60 seconds, it will outputBOOM!
.
Clarification example what I mean with 'starting time':
- Base program with input
60
seconds is run at12:00:00
. It outputs the first output program with a starting time of12:00:00
. - This first output program with starting time of
12:00:00
is run at12:00:45
. It outputs a second output program with a starting time of12:00:45
. - This third output program with a starting time of
12:00:45
is run at12:01:25
. It outputs a fourth output program with a starting time of12:01:25
. - This fourth output program with a starting time of
12:01:25
is run at12:05:00
. It will outputBOOM!
.
Note how the first output would print BOOM!
after 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).
Challenge Rules:
- Default quine rules apply.
- At least
n
seconds should have passed. So if the input is60
and starting time was12:00:00
, at12:01:00
it will still output the v2 program, but at12:01:01
it will outputBOOM!
. - 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).
General rules:
- 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.