42
votes
\$\begingroup\$

Your program has to make the computer produce a sound, any sound.

Shortest code wins, not sooner than 10 days after the first valid answer. If there is a tie, the one submitted sooner, wins.

  • The program should run on a reasonable, not too uncommon personal computer.
  • Opening a pop-up, message box, etc. (for example, on a web page) does not count, as they might or might not produce a sound, depending on a lot of settings.
  • Just entering a wrong command or invalid character on a console and receiving a warning beep does not count, just as the compiler/interpreter/OS beeping on an error or crash does not count either. Your code must be a valid program.
\$\endgroup\$
5
  • 1
    \$\begingroup\$ ^G aka system bell or OS beep may be suppressed on many systems too (e.g. switched to be a visible "bell") and should be handled like sounds of popus and so on too: Not a valid solution. \$\endgroup\$
    – user19214
    Jun 17, 2014 at 21:43
  • \$\begingroup\$ Every program that prints "\a" to a terminal fails if xterm uses a visible bell. \$\endgroup\$
    – kernigh
    Jun 18, 2014 at 23:42
  • 19
    \$\begingroup\$ rm / will cause a lot of screaming. \$\endgroup\$
    – cjfaure
    Jun 22, 2014 at 17:23
  • \$\begingroup\$ My left fan has been dying noisily for a while. Would that be a valid 0 bit answer? \$\endgroup\$
    – Édouard
    Sep 29, 2015 at 0:11
  • 1
    \$\begingroup\$ I think this question should be reopened. The joke answers that rely on the fan spinning or the CD tray opening are invalid, since the question says "play a sound". Seems pretty clear to me that the output needs to come from the speakers as a result of the program, not the OS or the user or the hardware. \$\endgroup\$
    – mbomb007
    Dec 2, 2016 at 19:40

67 Answers 67

1 2
3
0
votes
\$\begingroup\$

R, 7

alert()

but sadly I think this is just a wrapper for printing the bell character.

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

In AppleScript ; 4 characters

beep

[ This is so short that my answer firstly did not reach the minimum length to be posted ! ]

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

Ruby, 8 chars

puts ?\a

><>, 2-3 chars

7o;

or with infinite loop:

7o
\$\endgroup\$
0
votes
\$\begingroup\$

Autohotkey

I found my answer in the Documentation on the Autohotkey Docs.

SoundBeep
\$\endgroup\$
0
votes
\$\begingroup\$

Fortran 95, 18 chars

print*,char(7);end

Produces a bell sound

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

C#, 72 bytes

class Program{public void main(string[]args){System.Console.Beep(500);}}
\$\endgroup\$
-1
votes
\$\begingroup\$

C on linux

#include <fcntl.h>
#include <linux/cdrom.h>
#include <sys/ioctl.h>

int main() {
  ioctl(open("/dev/sdb", O_RDONLY), CDROMEJECT);
}

Opens the CD-ROM door.

You may need to change sdb to whatever your optical drive's device is.

\$\endgroup\$
1 2
3

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