Activate the auto destruct sequence

4

This is a code golf. The smallest amount of bytes wins! :)

What you need to do

You're on Deep Space Nine, a Cardassian outpost taken over by the Federation, in the year 2374. The Borg, a superior race, have collapsed your shields and assimilated half of your crew. However, you have important classified information on your hands that you can't let anyone see at all. Activate the auto-destruct sequence.

Program Sisko 197 ;)

What you're actually doing

Take as input an integer value, which will set the exact auto destruct time in seconds. Once the user has passed the value, have a countdown ensue. Countdown backwards by one second each and print each number. At the point it reaches zero, make the program crash.

Rules

  • You may use STDIN, a parameter, or any other standard input format.
  • You must put each number on a new line.
  • You may or may not have an extra delay of one second at the beginning and end.

I was looking at Shortest auto-destructive loop, so if you want to use something from that, feel free, but this isn't really a duplicate of that. You can also wait one sec at the start, but once again, I'd prefer if you don't do this:

Note: Everything in parentheses is ignored.

(input is 10)
(wait 1 sec)
10
(1 sec)
9
(1 sec)
8
(1 sec)
(..etc..)
0
(crash)

And you do this:

(input is 10)
10
(1 sec)
9
(1 sec)
8
(1 sec)
(..etc..)
0
(crash)

Examples

If you don't have stdin but you can have a parameter inputted:

(grab the number from the parameter)
(once the number is loaded in, 10 in this case, print it like so:)
10
(wait one second)
9
(wait one second)
8
(wait one second)
7
(wait one second)
6
(wait one second)
5
(wait one second)
4
(wait one second)
3
(wait one second) 
2
(wait one second)
1
(wait one second)
0
(either wait one second then crash, or crash instantly)

If you have a form of stdin:

(allow the user to enter a number, there should be no greeting message)
(once the number is entered, 10 in this case, print it like so:)
10
(wait one second)
9
(wait one second)
8
(wait one second)
7
(wait one second)
6
(wait one second)
5
(wait one second)
4
(wait one second)
3
(wait one second) 
2
(wait one second)
1
(wait one second)
0
(either wait one second then crash, or crash instantly)

Have fun!

IMustBeSomeone

Posted 2016-12-25T17:52:53.133

Reputation: 647

Question was closed 2016-12-25T19:27:39.830

6I don't think this is sufficiently different from your air conditioner challenge. – Dennis – 2016-12-25T18:17:13.323

Hmmm. I think it is not but I will try to change it the best I can. – IMustBeSomeone – 2016-12-25T19:17:36.970

Answers

5

R, 46 bytes

for(i in scan():0){cat(i,"\n");Sys.sleep(i/i)}

Crashes after printing 0 because the sleep function is called using 0/0 which returns NaN in R:

Error in Sys.sleep(time) : invalid 'time' value

Billywob

Posted 2016-12-25T17:52:53.133

Reputation: 3 363

1

Python 2, 51 bytes

import time
def f(i):print i;time.sleep(i/i);f(i-1)

Recursive function that takes in integer then counts down until the integer is 0 at which point it explodes with a DivideByZero exception.

ElPedro

Posted 2016-12-25T17:52:53.133

Reputation: 5 301

1

C, 87 bytes

#import<windows.h>
main(i){for(scanf("%d",&i);i--;){printf("%d\n",i);Sleep(1000*i/i);}}

Death by division by zero.

Steadybox

Posted 2016-12-25T17:52:53.133

Reputation: 15 798

0

Batch, 67 bytes

@echo off
for /l %%i in (%1,-1,0)do echo %%i&timeout/t>nul 1
if

Note: the trailing newline is significant; this causes the command processor to choke on the if statement. The odd placement of the >nul is to save a byte as 1>nul would eat the 1 parameter to timeout/t.

Neil

Posted 2016-12-25T17:52:53.133

Reputation: 95 035