Take the 2-minute tour ×
Programming Puzzles & Code Golf Stack Exchange is a question and answer site for programming puzzle enthusiasts and code golfers. It's 100% free, no registration required.

This question already has an answer here:

Task:

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

Rules:

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, DigitalTrauma Mar 4 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 at 23:21
    
I second to @ace, why are you interested in "as fast as possible", how do you measure it? –  microbian Mar 3 at 23:36
    
@ace - without any intentional delays –  TheDoctor Mar 4 at 0:14
3  
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 at 0:50
    
Oh well. That attracted a lot of attention in it's short 3 hours –  TheDoctor Mar 4 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 at 23:21
    
@ace o-O It takes 24 hours for a vote to lock –  mniip Mar 4 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 at 11:07
1  
+1 for the sad face –  Quincunx Mar 4 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 at 3:02
    
yes is not bash. –  philcolbourn Mar 4 at 12:59
    
@philcolbourn then what is it? –  TheDoctor Mar 4 at 15:01
    
@TheDoctor coreutils –  mniip Mar 4 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 at 13:24

C, 29

No stack overflow on this one:

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

Golfscript, 13

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

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

T-SQL, 17

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

a:PRINT':)'GOTO a

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

main(){for(;;)puts(":)");} 
share|improve this answer
1  
I think you can remove the int for main(). (At least this definitely works for C ) –  ace Mar 3 at 23:52
    
@ace No, I tried. C++ assumes int, but won't compile without. –  hosch250 Mar 4 at 0:16
1  
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 at 8:03
    
OK. I use Visual Studio. –  hosch250 Mar 4 at 16:16

PowerShell 13

for(;;){":)"}

Test

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

Goes on and on until interrupted.

share|improve this answer

DOS Command Prompt (11)

Save "smile.bat" with following content

@echo :)
@%0

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 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 at 1:45
    
I would assume using goto would avoid a stack overflow failure. –  Cole Johnson Mar 4 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 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 at 3:22

Groovy, 16 characters

for(;;)print":)"
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 at 3:29

C, 25

main(){main(puts(":)"));}

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
6  
It overflows the stack very quickly. In like no time –  mniip Mar 3 at 23:21
3  
awww you noticed it :( –  izabera Mar 3 at 23:25

Scala 33

for(i<-Stream.from(0))print(":)")
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);
alert(jsprogram);

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){
  w=String.fromCharCode;
  y="if(t.endsWith(String.fromCharCode(10))||t.length>100){console.log(t);t=''}";
  r='(function(n){m=[];p=0;c=0;t=n.substring(0,0);';
  for(x=0;x<j.length;x++){
    q=j.charCodeAt(x);
    if(q==91)r+='while(~~m[p]){';
    if(q==93)r+='}';
    if(q==62)r+='p++;';
    if(q==60)r+='p--;';
    if(q==43)r+='m[p]=1+~~m[p];';
    if(q==45)r+='m[p]=-1+~~m[p];';
    if(q==46)r+='t+=String.fromCharCode(~~m[p]);'+y;
    if(q==44)r+='if(c<n.length)m[p]=n.charAt(c++);';
    if(q==94){z=j.indexOf(w(96),x+1);r+='t+='+w(34)+j.substring(x+1,z)+w(34)+';'+y;x=z}
    if(q==42)r+='t+=n.substring(c);c=n.length;'
  }
  return r+"if(t!=='')console.log(t)})"
}

Compiling my program:

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

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

Classic.

share|improve this answer
    
Deja vu: codegolf.stackexchange.com/a/22795/3755 –  Victor Mar 4 at 2:02

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