Executable haiku that outputs a haiku

37

6

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!

Li-aung Yip

Posted 2012-05-08T14:29:28.373

Reputation: 481

Question was closed 2016-08-16T04:27:23.543

I would strongly suggest you prevent the use of cat-like languages... – MrZander – 2012-05-08T22:08:47.207

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 – 2012-05-09T08:12:16.203

@PaulR: You're right. Edited to something that's 5 syllables. ;) – Li-aung Yip – 2012-05-09T08:50:50.687

1Bonus to a Piet solution? – ugoren – 2012-05-09T12:59:57.813

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 – 2012-05-10T01:18:38.540

I though about adding "haiku outputting haiku" to the sandbox, but searched first... – Vi. – 2014-09-02T10:24:53.640

Answers

46

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

Paul Richter

Posted 2012-05-08T14:29:28.373

Reputation: 770

This cracked me up for a good five minutes. Well done! – Li-aung Yip – 2012-05-16T18:39:44.373

78

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

Timwi

Posted 2012-05-08T14:29:28.373

Reputation: 12 158

14Compiler output?! Creative interpretation of the rules - I like it. It's also strangely zen... – Li-aung Yip – 2012-05-09T04:46:47.267

2This is compiler poetry... +1! – Cristian Lupascu – 2012-05-09T06:33:35.070

6I wish I could upvote this more than once. – Gareth – 2012-05-09T08:39:11.140

@Gareth ditto!! – Gaffi – 2012-05-09T13:51:43.413

1I literally laughed out loud at the poetry of the compiler's loneliness. Am I sadic?

Newline in constant. – Alpha – 2012-05-15T03:35:33.763

49

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

boothby

Posted 2012-05-08T14:29:28.373

Reputation: 9 038

Is there anywhere online I can test this? If it works it's definitely worth a +1. – Gareth – 2012-05-19T21:27:17.737

I found one here, but the program gave no output :-(

– Gareth – 2012-05-19T21:38:14.507

@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 – 2012-05-19T22:45:31.443

1Unfortunately, that one's totally borked in Chrome on my Mac. I'll see if I can download one that works tomorrow. – Gareth – 2012-05-19T22:59:24.983

@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 – 2012-05-20T02:23:05.120

1I heard you like haiku, so I put a haiku in your picture of a haiku so you get a haiku when you haiku. – Li-aung Yip – 2012-05-20T04:19:50.983

# piet quinelike haiku / this is in public domain/ make war not poems This is GENIUS. – Li-aung Yip – 2012-05-20T04:22:25.160

@Boothby: consider sending this to David Morgan-Mar for inclusion in the Piet Hall of Fame.. (I see you already have one entry there. ;) )

– Li-aung Yip – 2012-05-20T11:03:14.757

already have ;) – boothby – 2012-05-20T16:53:01.210

23

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.

Timwi

Posted 2012-05-08T14:29:28.373

Reputation: 12 158

5Isn'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? – dspyz – 2014-02-02T06:29:52.943

Yes, it is really :) – Timwi – 2014-02-02T06:35:08.687

19

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.

breadbox

Posted 2012-05-08T14:29:28.373

Reputation: 6 893

1I think you need therapy. – Chris Kitching – 2016-03-06T15:50:48.567

13

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.

Johno

Posted 2012-05-08T14:29:28.373

Reputation: 301

+1 for "if your timing is right" and "one three three seven" – clap – 2015-09-06T14:46:21.597

10

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)

commando

Posted 2012-05-08T14:29:28.373

Reputation: 1 053

8

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

Cristian Lupascu

Posted 2012-05-08T14:29:28.373

Reputation: 8 369

7

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

Geoff Reedy

Posted 2012-05-08T14:29:28.373

Reputation: 2 828

1I 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 – 2012-05-21T15:09:32.190

4

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

user4740

Posted 2012-05-08T14:29:28.373

Reputation:

3

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

user8777

Posted 2012-05-08T14:29:28.373

Reputation:

3

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

Konrad Borowski

Posted 2012-05-08T14:29:28.373

Reputation: 11 185

3

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

daniero

Posted 2012-05-08T14:29:28.373

Reputation: 17 193

You could probably just replace True == False with True is False to make the program code more like how you'd read it. – None – 2013-08-11T11:38:55.550

@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". – daniero – 2013-08-11T13:26:12.280

At least in Python 3, what = then could also be replaced witn what is then. – MaxiMouse – 2019-09-03T19:03:49.047

2

Tcl

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

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

guest

Posted 2012-05-08T14:29:28.373

Reputation: 181

0

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

Destructible Lemon

Posted 2012-05-08T14:29:28.373

Reputation: 5 908

0

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

Destructible Lemon

Posted 2012-05-08T14:29:28.373

Reputation: 5 908