Programming Puzzles & Code Golf Stack Exchange is a question and answer site for programming puzzle enthusiasts and code golfers. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

This question already has an answer here:


Make a program that prints a smiley (:)) indefinitely.


Your program must print :) as fast as possible until interrupted

This is , so the shortest answer wins.

share|improve this question

marked as duplicate by Doorknob, primo, Timtech, Hosch250, Digital Trauma Mar 4 '14 at 2:01

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.

What is meant by "as fast as possible"? How do you measure the speed? – ace Mar 3 '14 at 23:21
I second to @ace, why are you interested in "as fast as possible", how do you measure it? – microbian Mar 3 '14 at 23:36
@ace - without any intentional delays – TheDoctor Mar 4 '14 at 0:14
I think, in almost all cases, the shortest solution in any language will be while(1){print":)"} or a variant thereof. I don't think this makes for a very interesting question. – primo Mar 4 '14 at 0:50
Oh well. That attracted a lot of attention in it's short 3 hours – TheDoctor Mar 4 '14 at 2:15

18 Answers 18

up vote 12 down vote accepted

Befunge - 6


Infinite looping is provided by the fact that befunge source file wraps around.

share|improve this answer
I would be even with you if bash didn't parse )s – TheDoctor Mar 3 '14 at 23:21
@ace o-O It takes 24 hours for a vote to lock – mniip Mar 4 '14 at 10:24
That's not true. I tried removing the vote after 7 minutes and I couldn't. I'm really sorry. – ace Mar 4 '14 at 11:07
+1 for the sad face – Justin Mar 4 '14 at 19:44

Bash, 7

yes :\)

I know. It was too hard to resist.

share|improve this answer
+1 for the Pinocchio smiley. – epidemian Mar 4 '14 at 3:02
yes is not bash. – philcolbourn Mar 4 '14 at 12:59
@philcolbourn then what is it? – TheDoctor Mar 4 '14 at 15:01
@TheDoctor coreutils – mniip Mar 4 '14 at 16:13
@TheDoctor. yes is a program that - as mniip stated - is part of GNU coreutils. To be bash, it should only contain commands built into bash as per 'man bash'. – philcolbourn Mar 13 '14 at 13:24

C, 29

No stack overflow on this one:

main(){l:puts(":)");goto l;}
share|improve this answer
-1 for goto. Use for. – Cole Johnson Mar 4 '14 at 2:08
@ColeJohnson Really? This is code-golf. Answers should be as short as possible, regardless of any normal conventions applied for your language of choice. – Digital Trauma Mar 4 '14 at 2:18
No. I didn't actually downvote. – Cole Johnson Mar 4 '14 at 2:22
No. I can't.... – Cole Johnson Mar 4 '14 at 2:41
I don't see how this is shorter than for(;;). – ace Mar 4 '14 at 8:06

Golfscript, 13

My Golfscript is weak, so there may be a shorter way.

share|improve this answer
p is implemented as {`puts}, so you could use {":)":`p}do. – Dennis Aug 30 '14 at 16:32

T-SQL, 17

Take that, C and C++, and probably Java even though there is no Java answer yet.


Edited to add: Still running. It overflowed the integer line counter on the Results page and kept on chugging. CPU at 17%, plenty of free memory.

share|improve this answer

Brainfuck - 45 bytes


The longest program here, but considering how long Brainfuck programs can be it's not that bad of a margin.

Set cells 2,3,4 to 10,40,60 with a loop, add 1 to cell 3 and subtract 2 from cell 4. Print 4,3,2 and go back to 4 forever.

share|improve this answer

C++ - 26

share|improve this answer
I think you can remove the int for main(). (At least this definitely works for C ) – ace Mar 3 '14 at 23:52
@ace No, I tried. C++ assumes int, but won't compile without. – Hosch250 Mar 4 '14 at 0:16
I tried to compile with g++ and it works. Or, you can just change your answer to C and remove the int . – ace Mar 4 '14 at 8:03
OK. I use Visual Studio. – Hosch250 Mar 4 '14 at 16:16

PowerShell 13



PS > for(;;){":)"}

Goes on and on until interrupted.

share|improve this answer

DOS Command Prompt (11)

Save "smile.bat" with following content

@echo :)

On command prompt run smile.

C:\> smile

It will run for ever until interrupted.

share|improve this answer
This fails after a short period of time for me. I assume it's failing due to a recursion stack exception. – unclemeat Mar 4 '14 at 1:44
The following will work, though it has a bit of extra unwanted output: @echo :)&@start /B %0. It allows the previous instance of the bat file to end, whereas your answer will not, and therefore use up all of your memory. – unclemeat Mar 4 '14 at 1:45
I would assume using goto would avoid a stack overflow failure. – Cole Johnson Mar 4 '14 at 2:09
@unclemeat, how much long did it take before it failed on you? I ran it for a minute and it did not fail on me. As far as I know current batch file stops executing as soon as another one is called from within. To make it a real stack based call there is a 'CALL' command that calls and returns. – microbian Mar 4 '14 at 2:24
@microbian it fails fairly quickly. It was my understanding that using %0 works in a similar way to call %0, keeping the previous instance open until the next ends. It crashes cmd. – unclemeat Mar 4 '14 at 3:22

Groovy, 16 characters

share|improve this answer

Java, 75

class s{public static void main(String[]a){for(;;)System.out.print(":)");}}

Is it really that bad.. Can anyone improve on it?

share|improve this answer
goes to show java's verbosity – qwr Mar 4 '14 at 3:29

C, 25


It outputs :) followed by a newline infinitely many times, as fast as possible until interrupted.

1 char shorter than the obvious solution: main(){for(;;)puts(":)");}

share|improve this answer
It overflows the stack very quickly. In like no time – mniip Mar 3 '14 at 23:21
awww you noticed it :( – izabera Mar 3 '14 at 23:25

Scala 33

share|improve this answer

Python 2 - 17 bytes

while 1:print':)'

Trivial, but shorter than some of the other answers.

share|improve this answer

GW-BASIC, 20 characters

1 PRINT":)"
2 GOTO 1
share|improve this answer

Brainfuckoff, 7 characters


Unfortunately, my implementation of the brainfuckoff compiler given in the linked answer can't handle infinite output. But below, I provide a new implementation of the compiler that does. The problem is in the code generated by the javascript compiler, which provides all the output in a single shot, instead of outputting it as it is generated.

To prove that it actually should do what is asked, lets see what is the javascript program resulting from the compiled brainfuckoff program:

program = '+[^:)`]';
jsprogram = bfg(program);

This is what is show:

(function(n){m=[];p=0;c=0;t=n.substring(0,0);m[p]=1+~~m[p];while(~~m[p]){t+=":)";}return t})

And this clearly keeps sending to the output a sequence of :) forever. Unfortunately, due to the way that it is compiled, it crashes before you can see any of the output.

Then I fixed the compiler (not changing the language nor inventing one just for this challenge, just fixing a compiler for an already existing language without any change in the language spec). Beware, it still crashed my Firefox once (but worked in the second try).

Here is the new Brainfuckoff compiler:

function bfg(j){
  return r+"if(t!=='')console.log(t)})"

Compiling my program:

program = '+[^:)`]';
input = '';
compiled = bfg(program);

It outputs a long sequence of :). When your browser asks for you if you want to interrupt the script because it is taking too much time to finish, say yes.

share|improve this answer

Batch - 20 Bytes

This will loop infinitely, without causing a Recursion Stack Exception.

@echo :)&goto :)

It can be cut down by changing goto :) to goto ) - But I like having it there.

share|improve this answer
10 PRINT ":)"
20 GOTO 10


share|improve this answer

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