Program that outputs a program that outputs a program ... that outputs "Hello!"

Golfscript 39 14

~'Hello!'{`}@*

Example:

Assuming that n=4 and our program is P, these are the steps:

  1. Run P with parameter 4. The output is "\"\\\"\\\\\\\"Hello!\\\\\\\"\\\"\"" (P1)

  2. Running P1 outputs "\"\\\"Hello!\\\"\"" (P2)

  3. Running P2 outputs "\"Hello!\"" (P3)

  4. Running P3 outputs "Hello!"(P4)

  5. Running P4 outputs Hello!. If you don't trust me, follow this link ☺.


Perl (45 36)

say"say q("x($m=<>),"Hello!",")"x$m         

Run with perl -M5.010 to use say.

For n=1, outputs say q(Hello!)
For n=2, outputs say q(say q(Hello!))
For n=3, outputs say q(say q(say q(Hello!)))
and so on.


JavaScript, 58 chars

function $(_){alert(_?$+'$('+--_+')':'Hello!')}$(prompt())

Tags:

Code Golf