4
\$\begingroup\$

This question already has an answer here:

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!

\$\endgroup\$

marked as duplicate by FlipTack, Rɪᴋᴇʀ, ETHproductions code-golf Dec 25 '16 at 19:27

This question has been asked before and already has an answer. If those answers do not fully address your question, please ask a new question.

  • 6
    \$\begingroup\$ I don't think this is sufficiently different from your air conditioner challenge. \$\endgroup\$ – Dennis Dec 25 '16 at 18:17
  • \$\begingroup\$ Hmmm. I think it is not but I will try to change it the best I can. \$\endgroup\$ – IMustBeSomeone Dec 25 '16 at 19:17
5
\$\begingroup\$

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
\$\endgroup\$
1
\$\begingroup\$

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.

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

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.

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

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.

\$\endgroup\$

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