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.

A rhyming program you write
Attempting to win the fight
For winning the contest and vote
It must compute "Hello World"
Then print it very polite

The most popular poem will win.

The requirements are:

  • The poem should be of 5 lines with rhymes AABBA
  • It can print whatever you want, but the output should contain "hello world" (uppercase/lowercase does not matter, quotes not included in the output)
  • Symbols are read aloud. For example, the fourth line above is read: It must compute quote hello world quote
  • Post below your code, on another code preview, the "read-aloud" version of your code for disambiguation on special symbols.

Excluded are poems:

  • including dead code, or characters which could be safely removed without changing the rhymes or the functionality
  • Using comments as a way to rhyme (except if there is a good reason for that)
  • using the same symbol as end of phrase for rhyme.

In case of a tie, programs outputting a poem will win. If there is still a tie, shorter programs will win.

New lines do not count. spaces, tabs and newlines are not read aloud. For example, "Hello, world!" would be read aloud "double-quote hello comma world exclamation point double-quote".

share|improve this question
    
The whole program needs to be of five lines? Can't an answer simply be the snippet of required commands? Excluding the class/function declarations and all? –  mikhailcazi Mar 5 at 11:10
    
Yes, the whole program needs to be of five lines. Try to spread your definitions and includes along lines. Most PL have a way to include multiple sentences on a single line with the semi-colon or similar. –  Mikaël Mayer Mar 5 at 12:21
    
I see that many of the answers are attempting to produce limericks, because you mention that word in your title, but not in your requirements. –  TRiG Jul 2 at 11:22
    
That's true. I only want the program to be a limerick. –  Mikaël Mayer Jul 2 at 12:39

19 Answers 19

up vote 73 down vote accepted

Whitespace

A rhyming program I	wrote  	   
	
     		  	 	
	
this poem of whitespace and bloat		 		  
	
     		 		  
	
because newlines don't count  		 				
	
     	     
	
despite the amount   	 	 			
	
     		 				
	
so deserves your sincerest upvote 			  	 
	
     		 		  
	
     		  	  
	
  


Wikipedia: Whitespace (programming language)
Online Interpreter to Test Answer

Output:

Hello World
share|improve this answer
3  
This somehow reminds me of the Beatles' Come Together. –  ace Mar 4 at 20:54
6  
It's certainly "over me" –  Sideshow Bob Mar 4 at 23:52
5  
Excluded: Using comments as a way to rhyme –  Charles Mar 5 at 17:23
2  
Well, I forgot that other chars were comments in whitespace. I don't think I will keep this rule because else this would ruin this winner. –  Mikaël Mayer Mar 5 at 18:15
3  
@MikaëlMayer I think you should keep the rule. I suspect a lot of these votes are mostly from people who are just discovering the charm of Whitespace. Personally, I'm more interested in seeing answers in the spirit of the actual challenge of rhyming code. –  Jason C Mar 6 at 9:35

HTML

<html>
<body><span
    class="poem"
    > Hello World! I'm a goat
</span></body></html><!-- Pecan -->

I had to get a little liberal with pronunciation of the last line. I hope it doesn't break the rules. It's also not 100% valid per W3C, but works in most browsers.

<!--
less than aich tee em el greater than,
less than body not equal to span,
class equals quote poem end quote,
greater than Hello World Bang I'm a goat
close span close body close root comment pecan
-->
share|improve this answer
18  
+1 just for "Bang I'm a goat" –  mikeTheLiar Mar 4 at 21:41
4  
+1 for clever re-pronunciations... + "Bang, I'm a goat" comment... –  WallyWest Mar 4 at 22:32
5  
+1 for reading >< as "not equal" –  Jan Dvorak Mar 5 at 18:42
3  
A newbie a poem he wrote-a/ Hoping to get just one vote-a/ And now in this race/ He's in second place!/ With as much rep as several years on StackOverflow-ta. –  cobaltduck Mar 6 at 14:44

Javascript

I know this isn't within the rules, but I couldn't resist

var girl, attractive = true;    // There once was a beautiful girl
var boy; girl = ' World';       // And a boy who thought she was his world
boy = 'Hello' + girl;           // When the boy said hello
if (boy != attractive)          // She said 'my goodness no!'
    alert(window['boy']);       // And the boy through the window she hurled.
share|improve this answer
4  
Creative and ingenious. –  Damon Swayn Mar 6 at 7:49
3  
There was no need to redefine girl on the second line but I still love it. –  howderek Mar 6 at 19:44

Python

a = [
'hello world']
print ''.\
join(a##
)

or,

a equals open square bracket
quote hello world quote close square bracket
print quote quote dot backslash
join paren a hash hash
and finally close unmatched bracket

I'm voluntarily signing up to additional rules, because I think (1) that limericks should have good metre and (2) that the best ones have a surprise in the last line.

(With the ending being interpreted in plain English, I figure you can work out for yourself what kind of bracket is unmatched. As to the no dead code requirement, nothing in there can be removed without changing at least one of rhyme, rhythm or output).

share|improve this answer
    
One may remove a hash without changing functionality or rhyme. It does change the rhythm as you state, but the question‘s conditions are quite clear here, I think. –  Keba Mar 4 at 23:04
1  
As the nature of poetry is to bend rules I can live with it. That said, it's not clear to me that metre isn't part of the OP's concept of rhyme anyway. –  Sideshow Bob Mar 4 at 23:21
3  
Meh. Rhyming "bracket" with itself three times is just lazy limericking. –  mikeTheLiar Mar 6 at 15:30
    
Yeah, I feel bad about that. But it is a different symbol for each rhyme, as requested by OP. –  Sideshow Bob Mar 7 at 9:29

Haskell

Taking some liberties with the pronunciation of certain symbols, i.e. Tuple construction (,,) and function application ($).

main = something that we wrote
     where something x y z = bloat
           bloat = flip ($) m putStrLn
           (that,we,wrote) = undefined
           m = "hello world"

The reading is supposed to be:

main is something that we wrote
where something x y z is bloat
bloat is flip apply m putStrLine
Tuple that we wrote is undefined
misquote hello world quote.
share|improve this answer

JavaScript

if (!!1) // and
  alert('&#10084; &#10084; the world') // and
Burn = $.cache
return 1 > his_parts.the_sum

If in brackets one follows exclaiming marks

and alert the world inside brackets after entity hearts

slash, slash and burn

equals cash, cash, return

one is greater than the sum of his parts

share|improve this answer
3  
I don't think I know anyone who pronounces "$" as "cash," although I admit to not writing JavaScript. –  Carl Witthoft Mar 5 at 18:54
1  
+1 I like the non-literal transcription, and "entity hearts" is kinda funny, despite the line break liberties. –  Jason C Mar 6 at 9:40

BASIC

More specifically, Chipmunk Basic. The syntax rules have been stretched almost to breaking point, so it may be impossible to run this in other dialects without modification.

Source:

read hi$, u$, q
print hi$ " world how are you
  print "Or as they say
  print u$ q "day
data Hello, How R U, 2

"Read-aloud" version:

read hi string comma u string comma q
print hi string quote world how are you
  print quote Or as they say
  print u string q quote day
data Hello comma How R U comma 2

Notes:

  • There are no line numbers in the source code, but it will still load and run without any problems (see below).
  • The $ sigil is read as "string" in the context of BASIC programs (see, e.g., this Wikipedia page).

And here's proof that it does actually work:

screen grab of program running in Mac OS X

share|improve this answer
    
How did you make this gif? –  Kartik Mar 6 at 7:09
    
@Kartik I used an app called IShowU –  squeamish ossifrage Mar 6 at 8:54

Java

public static void main(String[] boat
){ int i = 1.0f
  ;if(i<2
  )System.out.println
("Hello world");} //hello world wrote


public static void main paren String arr boat
paren brace int i is one-point-oh float
sem-col if paren i is less than two
paren system dot out dot print line new //for some reason it's println, not printnl
paren quote hello world quote paren sem-col brace slash-slash hello world wrote

Note that comments are not really optional in Java

share|improve this answer

Ruby

comma = ""<<44
print "Hello" or
more = ""<<32
print comma if true
puts("World!") unless print more

Live: https://ideone.com/sirBBc

Pronounced as follows (with stressed syllables capitalized)

comma Equals quote-QUOTE cons four-FOUR
print QUOTE hello END quote OR
more equals QUOTE quote cons three-TWO  # ok, that was squished
print COMma if TRUE
puts QUOTE world QUOTE UNless print MORE
share|improve this answer

Haskell

main = print . repeat
  $ head $ lines . init
     $ "Hello \
       \World!" #
         Just where (#) = const . id

Main equals printful stop repeat
Dollar head dollar line's full stop i'nnit?
Dollar quote hello back slash
Back slashworld bang quote hash
Just where parenthised hash equals constful, stop it!

This describes, hopefully, quite well the actual behaviour of the program.

share|improve this answer

Bash

As the answer is only forced to contain the phrase "Hello World", the easiest solution should be:

echo A rhyming program you write
echo Attempting to win the fight
echo For winning the contest and vote
echo It must compute "Hello World"
echo Then print it very polite
share|improve this answer
7  
Legal within the rules, but this answer is no fun at parties. meta.codegolf.stackexchange.com/a/1063/3363 –  Jonathan Van Matre Mar 4 at 16:56
1  
@JonathanVanMatre That is a sign that the problem is in the question. Anything different than just directly printing the output would be suprefluous. Further the first "excluded" rule inhibit anything more creative, even variable names with more than one char and code identing, it is a code-golf evaluated as popularity-contest, getting the worst of the two. –  Victor Mar 4 at 17:10
4  
@Timtech: It‘s Vote and Quote. –  Keba Mar 4 at 17:42
2  
Did you consider improving the question? / That might have made a better impression. / Though the damage is done / Wouldn't it be more fun / To make a real limerick-coding confection? :) –  Jonathan Van Matre Mar 4 at 18:08
1  
@Victor, "characters which could be safely removed" does seem to imply that you can't use multi-character variable names except where they are part of a rhyme. That is problematic. –  Jonathan Van Matre Mar 4 at 18:11

Brainf*ck

Ok, chide me now for the numerous rule violations. But I couldn't help making this.

++++++++[>+++++++++<-
]>.---.$#
+++++++..+
++.++++++++
.--------.+++.------.--------.

And the output (first violation of many: no space):

HELLOWORLD

Try it here: http://www.iamcal.com/misc/bf_debug/

The reading of it:

Eight plus left more nine plus less dash
Right more dot three dash dot cash hash
Sevén plus dot dot plus
Plus plus dot eight plus
Dot eight dash dot three plus dot six dash dot eight dash.
  • Note that the final dot in the program is placed as the period at the end of the limerick :) [second violation; this is cheap]. Also, the $ and # are ignored by the interpreter (I was very proud of myself for this line).

  • The accent on Sevén is to show the stress: seh-VEN

  • This violates the rule of using different symbols. But honestly I have a very limited symbol set and no space to add in other (ignored) characters.

  • I used all caps because those are faster to access in ASCII. I had no room for a space, unfortunately.

Finally: yes, I know the last line is terrible. Any suggestions to improve it? I'm not sure if you could compress this program anymore; maybe by storing repeated letters in their at their own positions?

share|improve this answer
    
Just realized that while this would make the code longer, unrolling the initial loop into 72 + would save some space in the limerick. But I'll keep my answer as is. –  baum Mar 7 at 21:34

Java

class Hello {public static void main
(String[] args)
{yellow = System; yellow
.out.print("Hello
world");} }

class Hello brace public static void main
paren string bracket bracket args paren
 brace yellow equals system sem-col yellow
 dot out dot print paren quote hello
world quote paren sem-col brace and brace again
share|improve this answer
1  
This doesn't compile. How is yellow declared? –  hexafraction Mar 6 at 12:32

Batch

@echo off >dull
set /p "=Hello "<nul
set w=World
echo %w%! || Furled
del dull || cull

at echo off to dull
set slash p quote equal Hello quote from nul
set w equal World
echo percent w percent bang pipe pipe Furled
del dull pipe pipe cull

share|improve this answer
    
Can you find another rhyme dull/dull ? –  Mikaël Mayer Mar 5 at 8:30
    
@MikaëlMayer it's more useless code, but yes. –  unclemeat Mar 5 at 21:27

TeX

I apologize in advance, because this code does not count as a limeric if you pronounce the names of each of the individual symbols (especially if you treat each letter unto itself as a token, which perhaps you ought). I have written it this way to produce the nicest possible output, which itself comes just short of being a poem.

You could safely turn it into an answer which complies with the rules by getting rid of \it and every non-alphabetic, non-whitespace character except for the final \bye (read aloud as backslash bye) and perhaps the first ! (read aloud as bang).

A \TeX\ program I think would comply,

And I'll tell you the reason for why:

``Hello world!'' tells the setter:

{\it ``Print each subsequent letter!''}

And we terminate with \bye.
share|improve this answer
    
You should remove comas and symbols at the end of each verse to let them rhyme properly. Or put them in the line afterwards. –  Mikaël Mayer Mar 6 at 12:07
    
@MikaëlMayer: see the remark in my second paragraph. –  Niel de Beaudrap Mar 6 at 12:54

C#

I've taken a few slight liberties with the rules as truly phonetic C variants would involve far too much use of "semi-colon" which, as we all know, isn't a particularly good rhyme for anything.

{
     string unfurled = "Hello World!";
     Console.WriteLine(unfurled);
}

open brace, string called unfurled

created to read "hello world"

console write line

the string we defined

a final brace, one that is curled

share|improve this answer
    
You can always put semi-colon at the beginning of a newline, no? –  Mikaël Mayer Mar 10 at 12:46
    
True, Mikael, but it makes the code look very untidy! –  BrummiePete Mar 10 at 12:57
1  
Between untidy and rhyming, here the point is about rhyming. Don't worry, this code is not peer-reviewed. –  Mikaël Mayer Mar 10 at 14:00

CSS

title>me
,body lets go party
only a stylesheet,html
:after { content: 'hello world'; font-family:Rockwell
; color: #adad20

Outputs:

title greater than me

comma body lets go party

only a stylesheet comma html

colon after bracket content colon quote hello world quote semicolon font-family colon Rockwell

semicolon color colon hashtag a dad twenty

Tested in Firefox and Chrome

share|improve this answer

Windows Batch

The spoken words are also saved within the batch file, and skipped with the last line of actual code.

@echo off >nul
set hi=Hello World
rem Now print the string,
echo !hi!
goto :) to skip the words

at echo off, greater than nul,
set H I equals sign, Hello World,
rem Now print the string,
echo pling, H I, pling
goto smile, to skip the words

:)

Edit: You'll need delayed expansion enabled for the script to work. Use cmd /v:on and run it from there.

share|improve this answer
1  
nul, world, and words do not rhyme. The pattern needs to be AABBA. Also the comma after string should be pronounced. –  unclemeat Mar 7 at 1:49

print 'the letter keys on my keyboard'
print 'are sufficient to say Hello World
print 'when I type in the dark'
print 'sitting here in the park'
print'feeling horribly,horribly bored'

share|improve this answer
    
Note the rules: symbols such as ' are read aloud and count as part of the rhyming scheme. Welcome to PPCG! –  Jonathan Van Matre Mar 6 at 23:54
    
So technically it works. It doesn't say A cannot be B. –  CompuChip Mar 10 at 13:42

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.