37
\$\begingroup\$

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."

Now this question ends;

Many more haikus await.

Continue posting!

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

16 Answers 16

78
\$\begingroup\$

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
\$\endgroup\$
5
  • 14
    \$\begingroup\$ Compiler output?! Creative interpretation of the rules - I like it. It's also strangely zen... \$\endgroup\$ Commented May 9, 2012 at 4:46
  • 2
    \$\begingroup\$ This is compiler poetry... +1! \$\endgroup\$ Commented May 9, 2012 at 6:33
  • 6
    \$\begingroup\$ I wish I could upvote this more than once. \$\endgroup\$
    – Gareth
    Commented May 9, 2012 at 8:39
  • \$\begingroup\$ @Gareth ditto!! \$\endgroup\$
    – Gaffi
    Commented May 9, 2012 at 13:51
  • 1
    \$\begingroup\$ I literally laughed out loud at the poetry of the compiler's loneliness. Am I sadic? Newline in constant. \$\endgroup\$
    – Alpha
    Commented May 15, 2012 at 3:35
50
\$\begingroup\$

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

\$\endgroup\$
9
  • \$\begingroup\$ Is there anywhere online I can test this? If it works it's definitely worth a +1. \$\endgroup\$
    – Gareth
    Commented May 19, 2012 at 21:27
  • \$\begingroup\$ I found one here, but the program gave no output :-( \$\endgroup\$
    – Gareth
    Commented May 19, 2012 at 21:38
  • \$\begingroup\$ @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. \$\endgroup\$
    – boothby
    Commented May 19, 2012 at 22:45
  • 1
    \$\begingroup\$ Unfortunately, that one's totally borked in Chrome on my Mac. I'll see if I can download one that works tomorrow. \$\endgroup\$
    – Gareth
    Commented May 19, 2012 at 22:59
  • 1
    \$\begingroup\$ I heard you like haiku, so I put a haiku in your picture of a haiku so you get a haiku when you haiku. \$\endgroup\$ Commented May 20, 2012 at 4:19
45
\$\begingroup\$

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))
\$\endgroup\$
1
  • \$\begingroup\$ This cracked me up for a good five minutes. Well done! \$\endgroup\$ Commented May 16, 2012 at 18:39
22
\$\begingroup\$

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.
\$\endgroup\$
2
  • 5
    \$\begingroup\$ Isn't it a cop out to read the dollar underscore aloud in the first line but then skip it (along with quite a few other characters) on the third line? \$\endgroup\$
    – dspyz
    Commented Feb 2, 2014 at 6:29
  • \$\begingroup\$ Yes, it is really :) \$\endgroup\$
    – Timwi
    Commented Feb 2, 2014 at 6:35
18
\$\begingroup\$

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.
\$\endgroup\$
1
  • 1
    \$\begingroup\$ I think you need therapy. \$\endgroup\$ Commented Mar 6, 2016 at 15:50
12
\$\begingroup\$

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.

\$\endgroup\$
1
  • \$\begingroup\$ +1 for "if your timing is right" and "one three three seven" \$\endgroup\$
    – clapp
    Commented Sep 6, 2015 at 14:46
9
\$\begingroup\$

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)
\$\endgroup\$
8
\$\begingroup\$

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

\$\endgroup\$
6
\$\begingroup\$

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

\$\endgroup\$
1
  • 1
    \$\begingroup\$ 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. :) \$\endgroup\$ Commented May 21, 2012 at 15:09
3
\$\begingroup\$

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

\$\endgroup\$
3
\$\begingroup\$

Python

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

Code and how to read:

for e in range(3):                      # for e in range three
    if True is 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
\$\endgroup\$
3
  • \$\begingroup\$ You could probably just replace True == False with True is False to make the program code more like how you'd read it. \$\endgroup\$
    – user8777
    Commented Aug 11, 2013 at 11:38
  • \$\begingroup\$ @LegoStormtroopr agreed. Edit: I had forgot about this one. As stupid as the output is, I find it strangely satisfying to read it out loud in my most serious "peotry voice". \$\endgroup\$
    – daniero
    Commented Aug 11, 2013 at 13:26
  • \$\begingroup\$ At least in Python 3, what = then could also be replaced witn what is then. \$\endgroup\$
    – Maximouse
    Commented Sep 3, 2019 at 19:03
3
\$\begingroup\$

Python (2 entries)

Entry 1: A haiku in time

You need to save this in a file and run it from the same directory. This haiku very slowly prints itself out to screen, a poem in words and time.

from time import sleep
for line in open(__file__):
  print line; sleep(len(line))

Entry 2: A haiku without symbolism

This is similar to the above, but was an attempt to write a Python haiku that used just keywords and minimal brackets or substitutions of symbols (eg. = pronounced as "is").

if __file__ is not None:
 for line in open(__file__):
  print not False and line
\$\endgroup\$
2
\$\begingroup\$

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...

\$\endgroup\$
1
  • \$\begingroup\$ Cheating quine? \$\endgroup\$
    – user100411
    Commented Apr 17, 2021 at 4:02
2
\$\begingroup\$

Tcl

Here's a self-documenting, self-outputting, example:

catch {me as I make}
proc unknown args {puts [read $args]}
[open [info script]]
\$\endgroup\$
0
\$\begingroup\$

Vim

ia0 <esc><c-x>
YpA-<esc>
px5<c-x><c-x>

read as

i a zero x
Y p A hyphen escape
p x five x x

Writes:

a-1
a-1-
-7

read as:

a negative one
a minus one negative
negative seven
\$\endgroup\$
0
\$\begingroup\$

Python 3

print(print.__doc__[:15])
print(print.__doc__[13:][:13])
print(print.__doc__[32])

Read as:

print print doc one five
print print doc one three one three
print print doc three two

Prints:

print(value, ..
..., sep=' ',
\

Read as:

print value dot dot
ellipses, sep equals blank
reverse solidus
\$\endgroup\$

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