Do you need a cup holder?

8

You're going to replicate the 90's cup holder joke software.

Here's what's it did, and you have to do:

  • Display the message Do you need a cup holder?
  • If the user confirms, enter an infinite loop that keeps opening the CDROM drive.
  • If the user doesn't confirm, silently exit.

You may display the message using either a console message (confirmation is y, decline is n), or display a message window with the two options "Yes" and "No". You can assume the default (or most common) CDROM drive (D: on Windows, /cdrom on linux etc.). Standard loopholes (except built-ins) are forbidden. No additional input nor output may be involved. If your PC has no physical drive, or another "style" of tray, make sure the program is valid.

, so shortest program in bytes wins.

Trivia: The loop is there to prevent anyone from closing the drive. On desktop drives, the re-open command will be sent while the drive is closing, therefore staying open and not "spilling the coffee".

mınxomaτ

Posted 2016-02-03T00:03:23.907

Reputation: 7 398

2

Minus the necessary CD eject system call, I think this is strikingly similar to http://codegolf.stackexchange.com/questions/62732/implement-a-truth-machine

– Digital Trauma – 2016-02-03T00:17:28.730

4I think the requirement to interact with the hardware makes this sufficiently distinct from Implement a Truth Machine. – Alex A. – 2016-02-03T03:06:20.303

FYI http://meta.codegolf.stackexchange.com/a/8214/8478 (specifically "having long fixed output strings that benefit from compression.").

– Martin Ender – 2016-02-03T08:33:56.010

Answers

4

Bash, 115 69 68 66 bytes

This was written on Mac OS X but it should work on other BSD-based systems as well.

echo Do you need a cup holder?;sed 1q|grep y&&yes drutil\ eject|sh

We echo the prompt, get input with set 1q, and determine whether the user confirmed with grep y. If the user said y, we pipe the infinite output of yes with the string drutil eject to the shell, which will continuously eject the disk tray.

Saved 50 bytes thanks to Digital Trauma!

Alex A.

Posted 2016-02-03T00:03:23.907

Reputation: 23 761

1@DigitalTrauma You are the bash master! – Alex A. – 2016-02-03T01:04:52.503

Can you save bytes by replacing the sed and grep with read? – CousinCocaine – 2016-02-03T07:09:44.360

Shouldn't it be drutil tray eject? – Addison Crump – 2016-02-03T07:48:08.177

@VoteToClose drutil eject is a synonym for drutil tray open. It works as expected. ;) – Alex A. – 2016-02-03T15:38:12.833

1@CousinCocaine I was using read in a previous revision, but then I'd need an equality check, which makes it longer overall. You can take a look at the revision history to see what I mean. – Alex A. – 2016-02-03T15:40:15.707

4

Vitsy + Mac OSX bash, 55 bytes

'?redloh puc a deen uoy oD'ZWb2^/([1m]
<,'drutil eject'

Expects input as y or n. If it is n, it will execute line 2 (infinite loop with the shell command), otherwise, it will halt.

Addison Crump

Posted 2016-02-03T00:03:23.907

Reputation: 10 763

2

Python (3.5) 84 bytes

import os
i=input("Do you need a cup holder?")
while i=='y':os.system("eject cdrom")

On linux

edit: fix bytes count ;)

Erwan

Posted 2016-02-03T00:03:23.907

Reputation: 691

FYI: I noticed this because I'm using this script, which (among other things) adds a byte/char counter above blocks of code on PPCG.

– 3D1T0R – 2018-06-08T21:02:53.900

0

Python 3.5 on Windows 7, 135 Bytes

import ctypes
r=input('Do you need a cup holder?')
while r=='y':ctypes.windll.WINMM.mciSendStringW('set cdaudio door open',None,0,None)

MrGeek

Posted 2016-02-03T00:03:23.907

Reputation: 231

0

AutoIt, 85 bytes

If MsgBox(4,0,"Do you need a cup holder?")=7 Then Exit
Do
CDTray("D:","open")
Until 0

No one will ever answer anything in AutoIt anyway :)

mınxomaτ

Posted 2016-02-03T00:03:23.907

Reputation: 7 398