Play a sound, any sound

43

12

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.

vsz

Posted 12 years ago

Reputation: 7 963

Question was closed 8 years ago

My left fan has been dying noisily for a while. Would that be a valid 0 bit answer? – Édouard – 9 years ago

1I 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. – mbomb007 – 8 years ago

1^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. – None – 11 years ago

Every program that prints "\a" to a terminal fails if xterm uses a visible bell. – kernigh – 11 years ago

19rm / will cause a lot of screaming. – cjfaure – 11 years ago

Answers

20

dc, 2 chars

this one prints the bell character, too:

7P

Run with $ dc <<< 7P or save 7P to file and run $ dc file.

Also:

Befunge, 2 chars

Similar but infinitly looping and beeping:

7,

daniero

Posted 12 years ago

Reputation: 17 193

1Could you please elaborate what language that is? I never heard about it, and its name is too short (and a very common abbreviation) to be efficiently searched for. – vsz – 12 years ago

3From the man-page: dc is a reverse-polish desk calculator which supports unlimited precision arithmetic. -- it's included in most linux/unix distros as far as I know. – daniero – 12 years ago

A few more examples if you're interested: 1, 2 and 3. Seen a few others use it here as well.

– daniero – 12 years ago

My bad for not elaborating what I mean under "language" – vsz – 12 years ago

9@vsz dc is – of course – turing complete, as any better calculator such as ghc should be. – FUZxxl – 12 years ago

Here no ^G produces a sound... ^G should not count as valid answer because it can be disabled like window-create and other OS sounds... – None – 11 years ago

4All sounds can be disabled. Just turn the volume down. – daviewales – 11 years ago

49

bash (13)

sudo rm -rf /

The faster the hard drive the better the sound. Don't work with SSDs.
(Don't try this at home, sudo rm -rf / erases everything on your hard drive)

Daniel

Posted 12 years ago

Reputation: 1 801

1The warning Don't try this at home.. is misleading - someone might try this e.g. in /tmp/ instead of ~/, which would be equally harmful (: – mykhal – 10 years ago

7I think that one should come with a disclaimer -- "Don't try this at home" :D – daniero – 12 years ago

22Yeah, that's the sound when your computer reads your mail really fast (rm -rf). – FUZxxl – 12 years ago

70Wait, you got it wrong. The task is to make the computer produce a sound, not the user... though I have to admit that scream was quite impressive... – ceased to turn counterclockwis – 12 years ago

1Don't try this at home so it's OK at work... – tigrou – 8 years ago

4It doesn't do anything without --no-preserve-root, except maybe on ancient systems. – nyuszika7h – 11 years ago

1@nyuszika7h ancient as in before 2005. – Jwosty – 11 years ago

44

*sh (5)

eject

(does not work if you have no CD/DVD or similar drive..)

mykhal

Posted 12 years ago

Reputation: 641

I like this one. But, on my Mac (Mac OS X), the command is not found : sh: eject: command not found – Nicolas Barbulesco – 11 years ago

3

Nicolas: right, on Mac, the eject "command" seems to be much shorter: (:

– mykhal – 11 years ago

@ mykhal — If you go this way, I have a solution that works on all modern Macs : http://www.woowoomac.com/storage/post-images/adjust-volume-mac-keyboard.png?__SQUARESPACE_CACHEVERSION=1286394681886

– Nicolas Barbulesco – 11 years ago

1This fails with OpenBSD. usage: eject [-t] device The device argument is not optional! The shortest that works here is eject cd0 for 9 characters. Also, if the drive has no tray (as with a slot-loading drive), then eject cd0 makes no noise unless a disc is in the drive. – kernigh – 11 years ago

1kernigh: you're right. on the other hand, it might succeed on many systems without a sound card or speaker, where most of the other solutions would fail – mykhal – 11 years ago

37

Befunge, 0

If I read the spec correctly, this is an endless loop.
Endless loop = you'll hear your CPU cooler spin up.

Johannes Kuhn

Posted 12 years ago

Reputation: 7 122

27

sh 7

w|aplay

Plays a short noise.

Also 7:

aplay *

Assembly

Another non-bell solution. Resulting binary is just 15 bytes.

mov al, 182
out 43h, al
out 42h, al
mov al, 16
out 42h, al
mov al, 3
out 61h, al
ret

Assemble with nasm sound.asm -o sound.com. Can be tried with dosbox sound.com.

copy

Posted 12 years ago

Reputation: 6 466

9+1 for not just relying on a terminal to translate BEL characters to beeps. – Ilmari Karonen – 12 years ago

25

brainfuck: 8

+++++++.

Prints the bell character.

cardboard_box

Posted 12 years ago

Reputation: 5 150

16+1 BF Solution both understandable AND shorter than C. – OldCurmudgeon – 12 years ago

15A brainfuck is easier to mentally digest than C... we should learn from this incident. – Camilo Martin – 12 years ago

23

bash (Mac OS X) 5

say a

although stylistically I prefer the somewhat longer:

say 'Hello, Code Golf !'

Paul R

Posted 12 years ago

Reputation: 2 893

1If your Mac is set to English, you could also do say 'hahahahahahahahahahahahahahahahahahahahahahahahahaj'. – tomsmeding – 12 years ago

21Oooh... I've got ssh access to an osx box... – boothby – 12 years ago

1This command works in AppleScript. I did not know it works in the Terminal too. Funny with ssh ! – Nicolas Barbulesco – 11 years ago

1Corollary on Linux: espeak... – daviewales – 11 years ago

19

Haha, good ol' QBASIC code.

BEEP

Soham Chowdhury

Posted 12 years ago

Reputation: 1 449

1

Ah, the fun that could be had with the PLAY command! For reminiscence, see e.g. this video.

– Jussi M – 11 years ago

1I'm 15, xD. We learned QBASIC in school. – Soham Chowdhury – 11 years ago

16

Python 3.3.3, one character

<bell character>

The error message will contain a bell character, causing the sound.

Python 3.3.3, 10 characters

If errors are not allowed, this solution won't output the error message, only the sound.

print('<bell character>')

user12487

Posted 12 years ago

Reputation:

Why the downvote, this code actually produces a sound. – None – 11 years ago

11 char O_o nice +1 – Timtech – 11 years ago

13

Golfscript 3

'.'

(where the . is in fact a BELL character)

The HEX representation of the above code is:

27 07 27

Cristian Lupascu

Posted 12 years ago

Reputation: 8 369

2Ouch, Golfscript strikes again! – vsz – 12 years ago

12

Java - 222

Enough of this bell character or predefined beep function stuff, this makes a real sound :)

import javax.sound.sampled.*;class S{static{try{SourceDataLine
l=AudioSystem.getSourceDataLine(new
AudioFormat(4000,8,1,0<1,0>1));l.open();l.start();for(byte
i=9;i!=0;i+=9)l.write(new byte[]{i},0,1);}catch(Exception e){}}}

aditsu quit because SE is EVIL

Posted 12 years ago

Reputation: 22 326

18Java truly sucks for golf – boothby – 12 years ago

1

@boothby not always, check this out

– aditsu quit because SE is EVIL – 12 years ago

20Okay, Java sucks for golf except when the challenge is to throw errors. ;) – boothby – 12 years ago

@boothby What about this? http://codegolf.stackexchange.com/a/28818/24965

– stommestack – 11 years ago

2@JopVernooij That's not golf, that's an underhanded popularity contest. – Jwosty – 11 years ago

10

DOS Prompt / DOS Script

a:

Requires 3.5" floppy drive :)

svidgen

Posted 12 years ago

Reputation: 311

What magic is this? – seequ – 11 years ago

1It causes DOS to try to read from the floppy, which does cause a sound. It is, however, wrong that this needs a 3.5" floppy drive; a 5.25" floppy drive works even better. – celtschk – 11 years ago

Aye. Wouldn't the 5.25" normally be b:? – svidgen – 11 years ago

1Try a CD drive with a defective disk inside, works great too :) – Alejandro – 11 years ago

The drive letter in DOS depended on which connectors of the cable the drive was attached to (and on newer machines, a BIOS setting). My first computer only had a 5.25" drive and I had to attach it as master (making it the A drive), since it couldn't boot from the slave. – Dennis – 10 years ago

9

Pascal: 30 characters

uses Crt;begin
Sound(999)
end.

This takes advantage of the lack of any rule regarding the sound's duration. So just turns on the speaker on 999 Hz and lets it so. (At least until another program calls Nosound or the computer is turned off.)

manatwork

Posted 12 years ago

Reputation: 17 865

-2: Change to 9 Hz: Sound(9). – Erik the Outgolfer – 9 years ago

@EʀɪᴋᴛʜᴇGᴏʟғᴇʀ, would be hard to prove the sound is actually generated. Frequency Range of Human Hearing

– manatwork – 9 years ago

@manatwork Well, add an identical code with another frequency that can be heard. Because the codes are identical, it can be proved. (the number only changes) – Erik the Outgolfer – 9 years ago

And the sound keeps screaming even after the program has quit ? I like this one ! :-) – Nicolas Barbulesco – 11 years ago

@NicolasBarbulesco, exactly. That was the normal behaviour of all programs on DOS, including those written in C or assembly. – manatwork – 11 years ago

9

J (2)

a.

This prints all the characters from 0 to 255, that includes the bell.

If I have to do it without printing anything else, it's 4 characters:

7{a.

marinus

Posted 12 years ago

Reputation: 30 224

8

Bash, 22

Back in the 90's, my brother taught me this one -- to be used in a computer lab where one has remote access and knows a person to be alone in said lab. Kids these days won't know what a computer lab is... but oh well.

cd /dev;cat sda1>audio

boothby

Posted 12 years ago

Reputation: 9 038

cat /dev/sda1>audio – Erik the Outgolfer – 9 years ago

1I get bash: audio: Permission denied even running under sudo. :( – Riking – 12 years ago

2This worked on Debian as of 2006. I can't get it to work on my Ubuntu box :*( – boothby – 12 years ago

1I think you mean dsp, not audio. See below for a similar example I wrote using /dev/random – None – 11 years ago

3or cat /dev/sda | aplay – TheDoctor – 11 years ago

1@TheDoctor or aplay</dev/sda (UUOC ;-)) – Digital Trauma – 11 years ago

What is this supposed to do ? – Nicolas Barbulesco – 11 years ago

8

Mathematica 6

This will evoke the system beep. On my computer, it is currently a chirp.

Beep[]

DavidC

Posted 12 years ago

Reputation: 24 524

7

cat/type/PHP 1

This is actually polyglot. It runs in cat (or Microsoft Cat called type) and PHP.

$ xxd file
0000000: 07                                       .

Execution:

$ xxd -r > file
0000000: 07                                       .
^D
$ cat file # cat could be replaced with type (on Windows) or with php

Konrad Borowski

Posted 12 years ago

Reputation: 11 185

That's not a serious attempt. – user48538 – 9 years ago

What is the program ? How to run it ? This is not clear. – Nicolas Barbulesco – 11 years ago

@NicolasBarbulesco: The program is one byte (\x07), however because it's binary, I cannot paste it here. You can run it in PHP CLI, with php. – Konrad Borowski – 11 years ago

It is not clear. But it works ! With cat. The trick is the ASCII char 7 “bell”. – Nicolas Barbulesco – 11 years ago

6

brainfuck, 5 bytes

+[.+]

prints all chars including bell

benwaffle

Posted 12 years ago

Reputation: 199

5

Ruby, 7

$><<?\a

Tested on Windows with Ruby 1.9.3.

Roy Tinker

Posted 12 years ago

Reputation: 146

5

DOS, 5

Indirect, requires user cooperation.

pause

boothby

Posted 12 years ago

Reputation: 9 038

1Are you sure? I can not remember any beeping version of DOS pause. (At least not MSDOS and FreeDOS.) – manatwork – 12 years ago

6Run the program. Cooperate. Listen. – boothby – 12 years ago

1Could you at least specify which DOS implementation's which version you used? – manatwork – 12 years ago

1Looked up. Found no mention of pause making sound. Tried it. pause made no sound. – manatwork – 12 years ago

2You have to press a key... which makes a sound. @mana He said it was indirect - pause didn't make the sound, YOU did. – Riking – 12 years ago

2@Riking, how that conforms with the “Your program has to make the computer produce a sound” part of the requirement? – manatwork – 12 years ago

5I do not understand programmers on puzzle sites who cannot think outside of the box. – boothby – 12 years ago

Well, "playing a sound" cannot be considered as a "puzzle", anyway. Just move on. Nobody can feel "puzzled" by that. – None – 12 years ago

@JoanLeaven Who said this was a puzzle? I said this was a puzzle site -- do you read (I like reading)? Well, except for manatwork, who was obviously puzzled by my far-too-subtle joke. And anyway, you move on! This is my solution, I'll comment as often as I please! – boothby – 12 years ago

4I wasn't criticizing your answer. I was criticizing the question. A pointless question will obviously get pointless answers. Your answer then make as much sense as any other answer to that stupid question. So, i'm giving you +1. – None – 12 years ago

5

PowerShell, 24 17

Since nobody has posted this version yet:

[console]::beep()

UPDATE: Removed frequencies so it uses the default frequency and duration (MSDN says the default is 800 hertz and 200 milliseconds)

ub3rst4r

Posted 12 years ago

Reputation: 282

Surely you could at least use smaller numbers – Dennis Jaheruddin – 11 years ago

5

R 9

The bell character

cat("\a")

Dason

Posted 12 years ago

Reputation: 260

4

Python 9 chars


produces beep sound when executed.

print'\a'

Anbarasan

Posted 12 years ago

Reputation: 79

1You can shorten this to 8 characters if you replace \a with the actual bell character (ASCII code 7). – flornquake – 12 years ago

But how to print with the help of the value 7 ? – Anbarasan – 12 years ago

1

You can type the bell character into your editor with Alt+07. Alternatively, you can run this snippet to create a python file with the 8-character solution: open("play_a_sound.py", 'w').write("print'"+chr(7)+"'")

– flornquake – 12 years ago

Got it now. Thanks ! – Anbarasan – 12 years ago

4

Applescript (4 Characters)

beep

This will play the default beep sound of OS X.

Mathias

Posted 12 years ago

Reputation: 41

4

top & aplay - 9

top has rhythm!

top|aplay

The periodic display sometimes does not feed the sound sink fast enough but aplay continues after grouching a bit... :-)

...this will run on many Linuxes...

Bonus:

While running this, type "s 1 ENTER" to get more beats per second. :-)

Party on!!! \o/

user19214

Posted 12 years ago

Reputation:

This is pure genius... :D – Mega Man – 9 years ago

4

Mathematica 7

Using Mathematica's built in text to speech capability.

Speak@x

Will make it say "x"

Tally

Posted 12 years ago

Reputation: 387

3

Tcl, 1 char

-

replace - with the bell char.
It will print the bell char as part of the error message. Twice.

And if you think this is not a valid program, add this before the bell char:

proc \007 {} {};

It is a valid program, I just did not define the command, because I like the error message.

Johannes Kuhn

Posted 12 years ago

Reputation: 7 122

Is that based on some Tcl 8.6 feature? In Tcl 8.5 I got different result: http://pastebin.com/bh73UF6F Or are you on Windows?

– manatwork – 12 years ago

No. The 2nd part should show that this is a valid Tcl file. And it should beep 2x (the error message contains the command to be executed twice). Calling a command that does not exist is not an error for Tcl, it is only one if it can not find it. (e.g. parray, which is loaded on the first use) – Johannes Kuhn – 12 years ago

Oops. I misunderstood you. I thought you mean, it should beep with the proc declaration too. (Regarding the beep count, probably my terminal is doing something as puts [string repeat ".\a" 10] displays 10 dots but beeps only once.) – manatwork – 12 years ago

3

C: 19

main(){puts("\a");}

edit: header file is not needed for "puts"

Trevor Hickey

Posted 12 years ago

Reputation: 341

2You can remove the space between #include and < :) – tomsmeding – 12 years ago

puts(char*);main(){puts("\a");} is smaller IMHO. – FUZxxl – 12 years ago

You can just remove the #include. – ugoren – 12 years ago

1@FUZxxl How can you have an opinion about code size? – Doorknob – 11 years ago

@DoorknobofSnow Because of the first amendment? – FUZxxl – 11 years ago

The First Amendment of what country, again? Oh wait, this is the Internet and not a specific country. – DeadMG – 11 years ago

3

><> 3

As in all answers, prints the bell (0x07) to stdout.

7o;

tomsmeding

Posted 12 years ago

Reputation: 2 034

2

Bash, 26

Standard unix (not modern linux, sadly, unless you have alsa-oss installed; the BSDs are fine):

cat /dev/random > /dev/dsp

user12447

Posted 12 years ago

Reputation:

4You can save 2 bytes by removing the whitespace around >. – nyuszika7h – 11 years ago

2

Scala: 44

java.awt.Toolkit.getDefaultToolkit().beep();

same as @nrubin29's answer, but shorter

Avinash R

Posted 12 years ago

Reputation: 181

2

GolfScript (3)

Since everyone else is doing this anyway:

'^G'

where ^G is the bell character.

Hex dump:

0000000: 2707 27                                  '.'

nyuszika7h

Posted 12 years ago

Reputation: 1 624

This is a duplicate of this answer.

– Dennis – 9 years ago

Now what is it, '^G' or "^G"? – celtschk – 11 years ago

It doesn't matter, but I'll fix the inconsistency. – nyuszika7h – 11 years ago

2

Linux shell (6 characters)

This requires a correctly configured analog modem (you also might need to run it as root):

wvdial

celtschk

Posted 12 years ago

Reputation: 4 650

2

Ruby 8

 puts"\a"

Tested on Windows with Ruby 1.9.3.

Cristian Lupascu

Posted 12 years ago

Reputation: 8 369

1

ATARI BASIC (4 chars)

?"E"

(? is short for "print". E is in fact the "escape" symbol; see http://raster.infos.cz/atari/chars/atascii.htm, item 1B. Printing this symbol would make a characteristic noise.)

Kaz Dragon

Posted 12 years ago

Reputation: 149

1

PowerShell, 3

'^G'

Of course, the ^G has to be entered manually, or written to a file with another script, like the following:

"'$([char]7)'"|Set-Content beep.ps1

Joey

Posted 12 years ago

Reputation: 12 260

1

VBScript

CreateObject("SAPI.SpVoice").speak "a"

Nice thing about this is you can make it say anything you want.

Cheezey

Posted 12 years ago

Reputation: 111

1

Windows Command Promt

logoff

Indeed, this makes an OS sound but it is not OS beeping on an error or crash.

totymedli

Posted 12 years ago

Reputation: 361

Which version of DOS has a logoff command? – celtschk – 11 years ago

@celtschk I don't know why did I wrote that:D – totymedli – 11 years ago

1

Matlab UNTESTED (1)

I am not sure whether this works in matlab, as I don't have sound available, but is in fact a single character. Hence calling or printing it may produce the desired effect in some languages.

Matlab verified (4)

beep

Dennis Jaheruddin

Posted 12 years ago

Reputation: 1 848

Calling the character actually does some strange things. See this question if you are interested.

– Dennis Jaheruddin – 11 years ago

1

Windows batch script, 14

sort %comspec%

%comspec% just points to C:\Windows\System32\cmd.exe, and calling sort will find the bell character at some point in cmd's binary.

afuous

Posted 12 years ago

Reputation: 429

Doesn't seem to work on Windows 8.1 64-bit. – nyuszika7h – 11 years ago

1

Batch, 16

type sethc.exe

I discovered this. When I do this, I'll get the 'BEEP' sound from reading the < BELL > character.

Gavriel Feria

Posted 12 years ago

Reputation: 133

1

JavaScript - 99 103

Audio
  ("data:audio;base64,UklGRgWsAABXQVZFZm10IBAAAAABAAEARKwAAESsAAABAAgAZGF0YeGrAACAbebe")
.play();

*chirp* (in firefox, it is definitely a chirp)

bebe

Posted 12 years ago

Reputation: 3 916

This code throws the following error: TypeError: Failed to construct 'Audio': Please use the 'new' operator, this DOM object constructor cannot be called as a function. – starbeamrainbowlabs – 11 years ago

firefox doesn't need that operator. however if i wanted to be pedantic (crossbrowser) i would definitely use 'new' (+4 characters) – bebe – 11 years ago

I'm getting the error TypeError: Constructor Audio requires 'new' in Firefox Aurora 32. So yeah, it does. – nyuszika7h – 11 years ago

oh dear.. "Omit the new keyword when possible" I had Firefox 29 now 30, it works like charm. (it's funny you try to prove your point with an alpha release) – bebe – 11 years ago

1

Java: 103

public class S {
    public static void main(String[] a) {
        java.awt.Toolkit.getDefaultToolkit().beep();
    }
}

nrubin29

Posted 12 years ago

Reputation: 225

Will fail to compile without class wrapper and import. – Avinash R – 11 years ago

I didn't realize we needed everything. I'll add it. – nrubin29 – 11 years ago

1

JS, 117

new Audio('data:audio/wav;base64,UklGRl9vT19XQVZFZm10IBAAAAABAAEAQB8AAEAfAAABAAgAZGF0YU'+Array(1e3).join(123)).play()

xem

Posted 12 years ago

Reputation: 5 523

1You can save 4 bytes by using audio instead of audio/wav, and 1 byte by using join(10) instead of join(123). – nyuszika7h – 11 years ago

Even Array(10).join(1) appears to play a sound, but Array(99).join(9) is more audible. – nyuszika7h – 11 years ago

1

QBASIC (8)

PLAY "A"

Body must be at least 30 characters; you entered 19.

ಠ_ಠ

nyuszika7h

Posted 12 years ago

Reputation: 1 624

1

Python3 34

Any of the python versions printing the bell character to stdout was working for me, so here it is one using the standard libarary, in Windows:

import winsound as w;w.Beep(99,99)

The semicolon could be replaced with a newline, but looks cooler this way :)

gcq

Posted 12 years ago

Reputation: 251

2You can save a character by using from winsound import*;Beep(99,99). – nyuszika7h – 11 years ago

1

Powershell, 4

"`a"

Sends a beep signal to the computer's speaker.

DarkAjax

Posted 12 years ago

Reputation: 669

1

OS X Command Line

say a

This causes the computer to say the letter 'A'

Trent

Posted 12 years ago

Reputation: 111

I do not think say is a bash command. – None – 11 years ago

sorry, yeti. I was under the impression that OS X command line was Bash. Thank you for the correction – Trent – 11 years ago

2It may be BASH where you type say a but that does not make say a BASH command. So I meant something like "say is not part of the BASH language". Maybe that was trying to be too exact... it may have caused more confusion than needed... – None – 11 years ago

1

Visual Basic 6

beep

VB 6, good times.

Evgheni Crujcov

Posted 12 years ago

Reputation: 111

1

C 23

Make a beep sound.

int main(){putchar(7);}

bacchusbeale

Posted 12 years ago

Reputation: 1 235

3This should still compile without the int at the beginning – r3mainer – 11 years ago

1

Debianish solution, works on some other systems too - 9 chars

aplay /i*

...will play the files /initrd.img and initrd.img.old which are symlinks to some system startup ramdisks in directory /boot.

If you prefer the sound of kernels, try...

aplay /v*

...and look yourself why it works or fails on your system.

I got...

$ LANG=C ls -l / | grep ^[^d]
total 88
lrwxrwxrwx   1 root root    36 Dec 15  2012 initrd.img -> /boot/initrd.img-3.2.0-0.bpo.4-amd64
lrwxrwxrwx   1 root root    30 Dec  9  2012 initrd.img.old -> boot/initrd.img-2.6.32-5-amd64
lrwxrwxrwx   1 root root     4 Dec  9  2012 lib64 -> /lib
lrwxrwxrwx   1 root root    32 Dec 15  2012 vmlinuz -> boot/vmlinuz-3.2.0-0.bpo.4-amd64
lrwxrwxrwx   1 root root    27 Dec  9  2012 vmlinuz.old -> boot/vmlinuz-2.6.32-5-amd64

...here and that may or may not explain a lot to you and I demand the absence of solid facts and that I may or may not be called vroomfondel!

user19214

Posted 12 years ago

Reputation:

you are saying that your solution needs neccessary data - that may not even exist - from outside the code. i think it needs reasons to prove it's valid. – bebe – 11 years ago

Oh... I didnt see my harddisk as "outside"! :-D               ll think about a different solution for some minutes... – None – 11 years ago

Ok... let's narrow it down: Debian is a common system and has these links... they can be disabled by editing some config file in /etc/ but their existence can be widely assumed because most users don't touch/change the defaults... – None – 11 years ago

1"The program should run on a reasonable, not too uncommon personal computer." was the wording I was looking for. And I think Debian not being configured to be far far away from the installation defaults on contemporary hardware does not describe an uncommon personal computer. – None – 11 years ago

1

PHP (CLI): 1 byte

 

Source code as seen in Notepad++:

source code

In the absence of <?php opening tag, source code is simply dumped to output.

Yeah, I know, another BEL answer, but still, tough to beat a single byte, especially in an interpreted language like PHP ;)

Niet the Dark Absol

Posted 12 years ago

Reputation: 647

1

sh 6

echo .

(where the . is in fact a BELL character)

The HEX representation of the above code is:

65 63 68 6f 20 07

Jonathan Callen

Posted 12 years ago

Reputation: 111

1

Autoit 6

Beep()

Although declaring a function would allow for less characters, not counting the declaration:

z()
Func z()
Beep()
EndFunc

Giulio Muscarello

Posted 12 years ago

Reputation: 298

5That way that you made the program longer? It didn't make it shorter. – boothby – 12 years ago

1Writing own functions count toward the the length. otherwise everything would be a how can I call the method with less chars and some languages allow that with 1 char. – Johannes Kuhn – 12 years ago

0

Windows Command Script - 1 Byte

As most of the answers, this also uses the bell character.

0x07

Note: Must be run from console to work, since the sound needs some time to trigger.

Robert Sørlie

Posted 12 years ago

Reputation: 1 036

0

Spoon, 13

1111111001010

Similarly to the BF solution, it prints the bell character.

Timtech

Posted 12 years ago

Reputation: 12 038

0

C++ 45

#include<iostream>
int main(){std::cout<<'\a';}

Mukul Kumar

Posted 12 years ago

Reputation: 2 585

0

Fortran 95, 18 chars

print*,char(7);end

Produces a bell sound

gilbertohasnofb

Posted 12 years ago

Reputation: 494

0

ZX Spectrum BASIC (3)

SAVE STR$ PI

It is only 3 bytes because BASIC keywords (with surrounding spaces) occupy single byte in ZX spectrum's memory. Here's its hex representation:

F8 C1 A7

This program saves current program to audio tape under the name "3.1415927" which is the string representation of π.

In fact it require 7 keypresses: S Caps+Symbol Y Caps+Symbol M

Vovanium

Posted 12 years ago

Reputation: 286

0

C#

System.Media.SystemSounds.Beep.Play();

It's long, but anyway...

Tr00rle

Posted 12 years ago

Reputation: 311

0

R, 7

alert()

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

user25359

Posted 12 years ago

Reputation: 1

0

In AppleScript ; 4 characters

beep

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

Nicolas Barbulesco

Posted 12 years ago

Reputation: 249

0

Ruby, 8 chars

puts ?\a

><>, 2-3 chars

7o;

or with infinite loop:

7o

clap

Posted 12 years ago

Reputation: 834

0

Autohotkey

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

SoundBeep

XiKuuKy

Posted 12 years ago

Reputation: 369

0

C#, 72 bytes

class Program{public void main(string[]args){System.Console.Beep(500);}}

NoOneIsHere

Posted 12 years ago

Reputation: 1 916

0

k/Q (6 chars)

Bell character to stdout.

1"c"$7

skeevey

Posted 12 years ago

Reputation: 4 139

-1

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.

Riot

Posted 12 years ago

Reputation: 4 639