0
\$\begingroup\$

This is a cops and robbers challenge - Robber's Thread

Write a program that terminates after exactly 60 seconds (or as close to it as possible). For example:

#include <unistd.h>
int main(int argc, char **argv){
    sleep(60);
    return 0;
}

However, your goal is to write this program such that terminating after exactly 1 minute is essentially inherent to the program's execution - it should be difficult to change the program to predictably run for a different amount of time without overhauling the algorithm. The robbers will attempt to change your program such that it terminates after 31 seconds instead of 60, and they will have to do so with a solution whose Levenshtein edit distance is up to half of the length of your submission.

If you do not wish to take advantage of system interrupts or the system clock, you can use either of the following:

  • The speed of printing to stdout is controlled by the baud rate of the terminal you are printing to. If you wish, you can control the speed of your program by printing to stdout with a set baud rate. However, you must also cite an actual piece of hardware or terminal program that has that baud rate as default (e.g. a serial printer with a default print speed of 300 baud).
  • If you are working in a language where all operations take some constant amount of time (such as assembly language), you can control the speed of your program by specifying the processor's clock rate. However, this too must be accompanied with a citation of an actual processor chip that runs at that speed (e.g. the 1 MHz 6502 put inside Apple //e and NES boards).

This is cops and robbers, so prepare to rigorously defend your algorithm! If your solution has been cracked, put [Cracked](link to cracker) in your header. If your solution remains uncracked after exactly 2 weeks, it is safe from future cracking attempts - put Safe in your header and explain how your algorithm works.

The winner of this challenge is the Safe solution with the most upvotes.

\$\endgroup\$
18
  • 1
    \$\begingroup\$ I believe this fits into the category of popcon "do [task] in a creative way" which is considered too broad by our community, so this might be closed. Seems like a cool challenge, though... \$\endgroup\$ Dec 3, 2016 at 23:19
  • 1
    \$\begingroup\$ @Challenger5 maybe it could be turned into a police v robbers challenge, where the robbers are supposed to edit the program to terminate in 30 seconds for example. That is, if this would indeed be considered too broad. \$\endgroup\$
    – JAD
    Dec 3, 2016 at 23:21
  • 1
    \$\begingroup\$ As before, without overhauling the algorithm isn't well-defined. In case you're not aware, we have a sandbox where you can get feedback from the community before posting your challenge on the main site. \$\endgroup\$
    – Dennis
    Dec 4, 2016 at 3:55
  • 1
    \$\begingroup\$ What would be accurate enough for 31 seconds? Is 31.01 seconds okay? Where's the "window" for an accurate time? \$\endgroup\$
    – clismique
    Dec 4, 2016 at 9:50
  • 1
    \$\begingroup\$ edit distance of half the length is too high, I think. It should be max(3, log_2(#chars)+2) or something like that. \$\endgroup\$
    – justhalf
    Dec 5, 2016 at 4:27

4 Answers 4

6
\$\begingroup\$

Perl 52 bytes (26 edits allowed) (Safe, technically speaking)

sub a{[gmtime+time]->[0]^$x}$x=a;0 until a;0 while a

Unfortunately, I don't think it's possible to write an uncrackable Perl program (it should become obvious why if and when this is cracked; being able to edit half the program is just too much), but this algorithm should be very hard to change to wait for any length of time other than 1 minute.

Marking this as safe, as nobody's officially submitted a crack for 14 days (although someone unofficially cracked it by just writing a separate program and commenting out the existing code). The basic idea of the program is as follows: we look at the seconds digit of the time, loop until it changes, then loop until it returns to its original value. This requires quite some changes to alter to a length of time other than 1 minute, 1 hour, or 1 day (although 26 edits is easily enough – you can do some modular arithmetic on the seconds value to determine a new target to wait until – but nobody found that solution).

\$\endgroup\$
2
  • \$\begingroup\$ sleep(31)#ime+time]->[0]^$x}$x=a;0 until a;0 while a is what you meant, right? I'm not posting this as a solution hoping that someone will try to provide a "proper" solution. (I don't know perl, so I'm out) \$\endgroup\$
    – Leo
    Dec 5, 2016 at 11:49
  • \$\begingroup\$ Yes, that's what I meant. The algorithm might be hard to change (although probably not impossible; I can see an approach that might work), but under the rules of the challenge you can just completely ignore it and write your own program to do the waiting. \$\endgroup\$
    – user62131
    Dec 5, 2016 at 15:33
1
\$\begingroup\$

Jelly, 30 bytes, cracked

69266249554160949116534784œSÆl

This can't be tested online since TIO has a 60 second timeout.

Verification

$ time jelly eun '69266249554160949116534784œSÆl'
69266249554160949116534784

real    1m0.033s
user    0m0.433s
sys     0m0.041s

How it works

The natural logarithm (Æl) of 69266249554160949116534784 is 59.5. œS sleeps that many seconds before returning its left argument. Adding the wait time to the 500ms boot time of Jelly (mostly spent loading SymPy and NumPy) gives an execution time of roughly one minute. This is on a third generation Core i7 CPU at 3.40 GHz and an SSD. The boot time will naturally vary on other computers.

\$\endgroup\$
1
  • \$\begingroup\$ Cracked. \$\endgroup\$
    – user62131
    Dec 5, 2016 at 4:52
0
\$\begingroup\$

reticular, 11 bytes, Cracked

[[3w]5*]4*;

Running:

λ timecmd reticular test.ret
command took 0:1:0.38 (60.38s total)

(timecmd link)

Explanation

[[3w]5*]4*;
[      ]4*  execute this 4 times
 [  ]5*     execute this 5 times
  3w        wait 3 seconds
          ; terminate program
\$\endgroup\$
2
  • \$\begingroup\$ Where can I find the documentation for / an implementation of this language? \$\endgroup\$
    – user62131
    Dec 5, 2016 at 2:30
  • \$\begingroup\$ Cracked. \$\endgroup\$
    – user62131
    Dec 5, 2016 at 2:44
0
\$\begingroup\$

Pyth - 5 bytes (distance of 2 allowed) Cracked.

.d*T6

Mess with it online (though it times out with 60 seconds).

\$\endgroup\$
2
  • \$\begingroup\$ Cracked. (for real this time) \$\endgroup\$
    – Dennis
    Dec 5, 2016 at 3:55
  • \$\begingroup\$ @Dennis nice one \$\endgroup\$
    – Maltysen
    Dec 5, 2016 at 4:09

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Not the answer you're looking for? Browse other questions tagged or ask your own question.