Tell me more ×
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.

Puzzle:

Write a short, three-line program which:

  • has 5/7/5 syllables per line when read aloud
  • outputs a haiku when run.

An example of a program having the correct structure, but non-haiku output, is (Python):

>>> for x in range(3):
...     print "EXTERMINATE HUMANS"
... # I am a Dalek.
... 
EXTERMINATE HUMANS
EXTERMINATE HUMANS
EXTERMINATE HUMANS

(The comment is a bit of a cop-out.)

This reads aloud as:

for x in range three

print EXTERMINATE HUMANS!

I am a Dalek.

Any language is acceptable. For the purposes of reading aloud, symbols like !@#$%^&*()_+ can be ignored if you want, or pronounced aloud, admitting something like Waka Waka Bang Splat. (I'm sure there will be a Perl entry like !***(!:, )(*@@@#, )_(*)!.)

Extra points if either the code or the output is especially funny, or especially zen.


Edit: If your language requires boilerplate before it can do anything interesting (#include <iostream>?) then I'm happy to ignore the boilerplate.


I've accepted Paul Richter's Common Lisp haiku on the grounds that it made me laugh for a good five minutes.

Honorable mention for Timwi's creative rule-bending (compiler output?!) and for the extremely memorable line "Static void. I long for you."

This question ends;

Many more haikus await.

Continue posting!

share|improve this question
I would strongly suggest you prevent the use of cat-like languages... – MrZander May 8 '12 at 22:08
1  
"Dalek Simulator" is 6 syllables (or maybe "# Dalek Simulator" is 7 syllables ?) - either way, shouldn't it be 5 syllables for the third line ? – Paul R May 9 '12 at 8:12
@PaulR: You're right. Edited to something that's 5 syllables. ;) – Li-aung Yip May 9 '12 at 8:50
1  
Bonus to a Piet solution? – ugoren May 9 '12 at 12:59
1  
@ugoren: If you can make a Piet program look like a haiku, I'm pretty sure that would win the Grand Prize. ;) – Li-aung Yip May 10 '12 at 1:18

12 Answers

up vote 16 down vote accepted

Common Lisp

Parentheses are silent!

Program:

((lambda (&rest foo) 
   (list foo (cons 'truly foo) foo))
 'this 'is 'lisp 'haiku)

Read as:

lambda and rest foo
list foo cons truly foo foo
this is lisp haiku

Output:

((THIS IS LISP HAIKU) (TRULY THIS IS LISP HAIKU) (THIS IS LISP HAIKU))
share|improve this answer
This cracked me up for a good five minutes. Well done! – Li-aung Yip May 16 '12 at 18:39

Perl

$_
= "Repeating myself"
;print"$_\nis like $_.\n$_.\n";

How to read it out loud:

dollar underscore
equals repeating myself
print nis like line noise.

Output:

Repeating myself
is like Repeating myself.
Repeating myself.
share|improve this answer

C#

Program:

#warning Lonesome
class _{
    static void Eye(long forYou='
        ){ /* My program ends here. */ ;}}

Read:

Warning: Lonesome class.
Static void. I long for you.
My program ends here.

Compiler output:

#warning: 'Lonesome'        (read: hash warning lonesome)
Empty character literal     (read: empty character lit’ral)
Newline in constant
share|improve this answer
6  
Compiler output?! Creative interpretation of the rules - I like it. It's also strangely zen... – Li-aung Yip May 9 '12 at 4:46
1  
This is compiler poetry... +1! – w0lf May 9 '12 at 6:33
4  
I wish I could upvote this more than once. – Gareth May 9 '12 at 8:39
@Gareth ditto!! – Gaffi May 9 '12 at 13:51
I literally laughed out loud at the poetry of the compiler's loneliness. Am I sadic? Newline in constant. – Alpha May 15 '12 at 3:35

Python

Code:

for _ in range(1,3):
    print 'Hi ' * 5, 'there ' *  2 * (-1+_) 
print 'I now', 'go ' * 3

How to read:

for in range one three
print hi five there two one plus
print i now go three

Output:

Hi Hi Hi Hi Hi  
Hi Hi Hi Hi Hi  there there 
I now go go go 

Working sample: http://ideone.com/hDniW

share|improve this answer

J

Program:

p:i.4
*:*:*:i.3
!8

Read (substituting verb names):

Prime Integers Four
Square Square Square Integers 3
Factorial Eight

Output (read numbers out loud):

2 3 5 7
0 1 256                          (Read: Zero One Two-Fifty-Six)
40320                            (Read: Forty Three-Twenty)
share|improve this answer

INTERCAL

INTERCAL has limited output capabilities, but "limited capabilities" has never stopped me from writing an INTERCAL program!

DO READ OUT #18
+#3301
+#214
PLEASE GIVE UP

Please read [out] this as:

Do read out eighteen,
Three thousand three hundred one,
Two hundred fourteen.

(Note that my boilerplate is at the end of the program instead of at the beginning.)

The program produces the output:

XVIII

MMMCCCI

CCXIV

Which, when spoken aloud, goes:

Ex vee eye eye eye,
Em em em cee cee cee eye,
Cee cee ex eye vee.
share|improve this answer

CoffeeScript

With tongue firmly in cheek, I present CoffeeScript:

here = "my haiku"
were_doomed() unless 1 is 1
alert Date.now()

Pronounced:

Here is my haiku
We're doomed unless one is one
alert date dot now

If your timing is right (!), your output might be e.g. 1337181872717, pronounced:

one three three seven
one eight one eight seven two
seven one seven

Considering my first run at this was one microsecond out from a valid haiku response, I think that's zen enough to qualify!

NB: I'd be happy to hear sufficiently zen alternatives for my first two (admittedly weak) lines.

share|improve this answer

Piet, 867 executing color blocks

Grand Prize, you say? This has codel size of 2.

a haiku that prints itself

Output:

SPRING EVER RETURNS
NEVER EXACTLY THE SAME
THIS IS NOT A QUINE

This challenge was fun! I've written a Piet instruction encoder that takes instructions and translates them into a Piet script. It's short work from there to generate code to print a given string. I put a small (but effective) amount of effort into golfing the Piet code while only using single-codel instructions.

I then made a pixel font. For every pixel in a character, I blow it up into 4 codels: 2 black, and 2 executed. The first codel encountered is non-executing, so if a segment of a character has n pixels, for example, that corresponds to 2*n*-1 instructions.

The lines down the sides reverse the direction pointer and move it down by 2 pixels, taking it to the next row. Thus, instructions are reversed on every other line.

Once I had code to produce "text embedded in text", it gets fun. I probably wrote 20 haiku along the way, but I eventually settled. By tweaking the font; adding / removing serifs, rounding corners, changing height / width, etc., I was able to alter the total number of nonwhite pixels in the image such that the Piet code fit exactly into the image text.

Bonus! You can make your own quinelike haiku! http://pastebin.com/zxc9V3UX

share|improve this answer
Is there anywhere online I can test this? If it works it's definitely worth a +1. – Gareth May 19 '12 at 21:27
I found one here, but the program gave no output :-( – Gareth May 19 '12 at 21:38
@Gareth, Piet is rather notorious for its lousy editors / interpreters, and I wasn't able to get npiet's online editor to produce output for anything. The posted script works on PietIDE. – boothby May 19 '12 at 22:45
1  
Unfortunately, that one's totally borked in Chrome on my Mac. I'll see if I can download one that works tomorrow. – Gareth May 19 '12 at 22:59
@Gareth, sad. There's a interpreter in python that I've also been able to use. Unfortunately, it doesn't seem to check for termination, so you have to kill it or wait for the 100k step cutoff. – boothby May 20 '12 at 2:23
show 5 more comments

logo

Here's a Haiku procedure that's also a quine procedure (easy because of logo's introspection capability)

to better_yourself
  printout "better_yourself
end ; as you began

Read as

To better yourself
Print out quote better yourself
End as you began

share|improve this answer
I read "Logo" and thought "This is going to involve a turtle writing a Haiku, isn't it?!" +1 even though there was no PEN UP or PEN DOWN. :) – Li-aung Yip May 21 '12 at 15:09

JavaScript (doesn't work in Firefox)

             (function haiku() { with (
console) log ((('' + haiku). // output
replace)     (/[ !-@{-~[-^]+/gim, ' ')); void haiku })()

works except for mozilla
javascript engine and shows
spelling after ran

share|improve this answer

Ruby

"A ruby haiku.
Why, yes, it is."; print open(
__FILE__).read #this now, please.

Read as:

A ruby haiku.
Why, yes, it is. Print open
file. Read this now, please.

It doesn't flow very well, unfortunately. In my defense, it is 12:50am...

share|improve this answer

Python

(Only read the first level of parantheses (not the second)).

Code and how to read:

for e in range(3):                      # for e in range three
    if True == False: what = then       # if true is false, what is then?
    print "oh " * (5 + 2 * (e & 1))     # print oh times _seven_

Output, probably most basic haiku in the world:

oh oh oh oh oh
oh oh oh oh oh oh oh
oh oh oh oh oh
share|improve this answer

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

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