223
\$\begingroup\$

Goal

The goal of this challenge is to write code that will execute once and only once. This means basically that it damages the program, script, or environment in some way. If rebooting the system allows the code to run again that is permitted.

Scoring

Number of votes. All assumptions must be clearly listed. Any answers just initiating a reboot or halt will be disqualified.

Additional Rules because Greg Hewgill is a demi-god

No root access is permitted.

End Date

The contest will close on May 31, 2014.

Edit

This contest has been changed to popularity contest.

\$\endgroup\$
  • 7
    \$\begingroup\$ @PeterTaylor a possible Solution would be the a self delete but as the result are showing it isn't the only one. \$\endgroup\$ – Lukei May 28 '14 at 7:21
  • 101
    \$\begingroup\$ To a lot of people calling vi in a single terminal environment has this effect, no escape from it unless you reboot :) Just a joke here. \$\endgroup\$ – orion May 28 '14 at 20:41
  • 6
    \$\begingroup\$ The site is free for you to propose such a question. \$\endgroup\$ – ojblass May 30 '14 at 22:40
  • 16
    \$\begingroup\$ echo "If you try to execute me again, it means you are an idiot."; <-- Nobody will execute more than once :P \$\endgroup\$ – user3459110 Jun 5 '14 at 12:45
  • 25
    \$\begingroup\$ Would missile-related software have qualified? ;) \$\endgroup\$ – rsegal Jun 8 '14 at 4:28

75 Answers 75

1
\$\begingroup\$

Bash (7 characters)

TMOUT=1

It destroying the user session within a second by terminating the shell. See: man bash.

Example:

$ TMOUT=1
timed out waiting for input: auto-logout
Saving session...completed.

[Process completed]
\$\endgroup\$
  • \$\begingroup\$ That's not really different from typing exit or ^D. The later key combination will send EOF to the shell making it 0 bytes. \$\endgroup\$ – kasperd Nov 7 '16 at 16:19
1
\$\begingroup\$

8602/8610 machine code, 4 bytes

assuming that the program is stored at address $0800

78 4C 00 08

breakdown to assembler:

START    sei        // disable interupts
         jmp START  // endless loop

C64 machine code, 3 bytes

4C E2 FC

this jumps to the builtin reset routine of the C64 (which, among other actions, clears the RAM)

run with SYS <address>

\$\endgroup\$
  • 1
    \$\begingroup\$ This should be two different answers. \$\endgroup\$ – MD XF May 30 '17 at 16:25
1
\$\begingroup\$

OSI Challenger 1P

POKE 3,3

There are lots of BASIC answers because BASIC made the mistake of allowing users to directly access all memory. But this is the shortest POKE command yet. If only it was ...

You can try this here - scroll down, hit Run, hit C to cold-boot, then Enter-Enter to get into BASIC mode. Then type POKE 3,3 and watch the PC burn.

\$\endgroup\$
1
\$\begingroup\$

Braingolf Inline Interpreter, 28 bytes [non-competing]

'''
open(__file__,'w')
a='''

Braingolf's Inline Interpreter treats the braingolf code as simply a multiline string within the Python3 interpreter.

This allows what is effectively an injection attack, where you can end the multiline string with three single quotes, then insert python code. The code will only run if you then begin a new multiline quote at the end, however.

\$\endgroup\$
  • 1
    \$\begingroup\$ You don't have to add non-competing (that rule was removed). \$\endgroup\$ – Esolanging Fruit Jul 9 '17 at 23:36
  • \$\begingroup\$ Also, doesn't this wipe the interpreter file, and not the program file? \$\endgroup\$ – Esolanging Fruit Jul 9 '17 at 23:37
1
\$\begingroup\$

JS, 8B

a=b=>a=0

calling a means a=0, thus a can't be called 2×.

\$\endgroup\$
1
\$\begingroup\$

SmileBASIC

@memory_leak
If shift("this") then @memory_leak

There is a bug where using POP() or SHIFT() on a string literal causes a memory leak, and eventually there will not be enough memory left for the program to run. Trying to run it again will cause an error before the program starts.

IF ... THEN @LABEL is a shortcut for IF ... THEN GOTO @LABEL.

\$\endgroup\$
  • \$\begingroup\$ Oh cool to see that its If ... Then @Label in SmileBASIC - it is If ... GoTo Label In the VB family \$\endgroup\$ – Taylor Scott Mar 13 '18 at 5:36
  • 1
    \$\begingroup\$ SmileBASIC actually supports both forms, for some reason. (I think I had forgotten about it when I wrote this answer) \$\endgroup\$ – 12Me21 Mar 13 '18 at 17:17
1
\$\begingroup\$

MOO, 24 bytes

delete_verb(this, verb);

Requires that this code is run as an actual verb, rather than through eval (or $code_utils:eval_d).

\$\endgroup\$
1
\$\begingroup\$

oldschool DOS


You don't even need a compiler or interpreter, just the prompt. Not even reboot will let it run again once it completes (note: do not try on something you don't want to sacrifice. OS likely won't boot either.)

deltree C:\
\$\endgroup\$
1
\$\begingroup\$

Windows batch, 4 bytes

.>%0

This will attempt to execute '.' as a command, while redirecting stdout to the original file, resulting in destruction of the original file.

\$\endgroup\$
0
\$\begingroup\$

AutoIt - 27 bytes

Truncs itself to 0:

FileOpen(@ScriptFullPath,2)
\$\endgroup\$
0
\$\begingroup\$

Batch (This isn't code golf)

echo "">%0.bat

Assumes you call it without the extension. If you are calling it with the extension, use echo "">%0.

\$\endgroup\$
0
\$\begingroup\$

Vitsy, 8 bytes (I know it isn't Golf but I like to be concise)

iG" mr",
iG        Push name of self.
  " mr"   Push "rm " in front of it.
       ,  Execute as shell.

This assumes you run on a computer with rm as a command for delete. For an environment with del as its command for delete, it's 9 bytes (I think, I can't really test it):

iG" led",
iG        Push name of self.
  " led"  Push "del " in front of it.
        , Execute as shell.

It basically just deletes itself. :P

\$\endgroup\$
0
\$\begingroup\$

Z80 ASM on TI-83/84 series

AsmPrgm
C3FFFF

If you put this into a TI-83 or 84 (any version, except 84+CE and CSE), the calculator will completely reset itself. Everything in RAM will be reset, including the program at hand.

For the TI84+CSE:

Asm84CPrgm
C3FFFF

Disclaimer: This might not work if you are running any apps that change the functionality of your calculator significantly. (i.e. libraries, non-official OS's)

\$\endgroup\$
-1
\$\begingroup\$

tcl, 7 bytes

vwait v

Explanation

\$\endgroup\$
-3
\$\begingroup\$

Bash file linux

#!/bin/bash
shutdown -h now
\$\endgroup\$
  • 1
    \$\begingroup\$ Welcome to the site! I do believe that shutdown requires root access (It does when I test it) which is forbidden by the challenge. \$\endgroup\$ – Wheat Wizard Mar 13 '18 at 5:52

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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