利默里克你好世界[关闭]


28

您编写的押韵程序
试图赢得比赛
为了赢得比赛并投票
必须计算“ Hello World”
然后打印得很有礼貌

最受欢迎的诗歌将获胜。

要求是:

  • 这首诗应该是5行,押韵AABBA
  • 它可以打印任何内容,但输出应包含“ hello world”(大写/小写无关紧要,引号不包含在输出中)
  • 大声读出符号。例如,上面的第四行显示为:它必须计算报价hello world quote
  • 在您的代码下方发布代码,在另一个代码预览中,将代码的“朗读”版本发布,以消除特殊符号的歧义。

排除的诗有:

  • 包括无效代码或可以在不更改韵母或功能的情况下安全删除的字符
  • 使用评论作为押韵的方式(除非有充分的理由,否则除外)
  • 使用与韵律词尾相同的符号。

如果出现平局,则输出一首诗的程序将获胜。如果仍然平局,则较短的程序将获胜。

新行不计算在内。空格,制表符和换行符不会大声朗读。例如,“你好,世界!” 会被大声读出“双引号你好逗号世界感叹号双引号”。


整个程序需要是五行?答案不能仅仅是所需命令的片段吗?排除类/函数声明以及所有其他内容?
mikhailcazi14年

是的,整个程序需要五行。尝试传播您的定义,包括沿线。大多数PL都可以用分号或类似的字符在一行上包含多个句子。
米凯尔·梅耶

我看到许多答案都试图产生打油诗,因为您在标题中提到了该词,但在您的要求中却没有提及。
TRiG 2014年

确实如此。我只希望该程序成为打油诗。
米凯尔·梅耶

我投票结束这个问题太广泛了,因为无法客观地确定答案是否有效。
小麦巫师

Answers:


86

空格

我写的押韵程序  	   
	
     		  	 	
	
这首空白和膨胀的诗		 		  
	
     		 		  
	
因为换行符不算  		 				
	
     	     
	
尽管数量   	 	 			
	
     		 				
	
所以值得您最诚挚的投票 			  	 
	
     		 		  
	
     		  	  
	
  


维基百科:空白(编程语言)
在线口译测试题

输出:

你好,世界

3
这使我想起了甲壳虫乐队 走到一起》
user12205 2014年

7
当然是“在我身上”
杂耍节目Bob

6
排除:使用评论作为押韵的方式
并不是说查尔斯(Charles)

2
好吧,我忘记了其他字符是空格中的注释。我认为我不会遵守这条规则,因为这会毁了这个赢家。
米卡·迈耶

3
@MikaëlMayer我认为您应该遵守规则。我怀疑其中很多选票主要来自刚刚发现Whitespace魅力的人们。就个人而言,我更感兴趣的是根据押韵代码的实际挑战来查看答案。
杰森C

60

的HTML

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

我必须对最后一行的发音有所了解。我希望它不会违反规则。每个W3C都不是100%有效的,但可以在大多数浏览器中使用。

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

4
为聪明的发音+1……+“
ang

5
+1代表><“不相等” 阅读
约翰·德沃夏克

3
他写的一首新诗-a /希望能获得一票-a /现在在这场比赛中/他位居第二!/在StackOverflow-ta上代表了多达几年。
cobaltduck 2014年

26

Java脚本

我知道这不符合规定,但我无法抗拒

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.

4
富有创造力和独创性。
戴蒙·斯威恩

3
无需在第二行重新定义女孩,但我仍然喜欢它。
howderek 2014年

23

蟒蛇

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

要么,

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

我自愿签署其他规则,因为我认为(1)打油诗应该有很好的仪表,并且(2)最好的在最后一行有惊喜。

(以通俗的英语来解释结尾,我想您可以自己找出哪种括号不匹配。对于无死角代码要求,在不更改韵律,节奏或输出中的至少一项的情况下,可以删除其中的任何内容)。


可以在不更改功能或押韵的情况下删除哈希。它确实会改变您陈述的节奏,但是我认为问题的条件在这里很清楚。
Keba 2014年

1
由于诗歌的本质是违反规则,所以我可以忍受它。话虽如此,但我仍然不清楚电表不是OP押韵概念的一部分。
秀节目Bob

3
嗯 自己押三遍“括号”只是懒惰打lime。
MikeTheLiar 2014年

是的,我对此感到难过。但是,按照OP的要求,每种韵律都有不同的符号。
秀节目Bob

14

哈斯克尔

对某些符号的发音有一些自由,即元组的构造(,,) 和功能应用 ($)

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

该读数应为:

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.

12

的JavaScript

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

如果放在方括号中,则在感叹号之后

并在实体之心后在方括号内提醒世界

斜线,斜线和燃烧

等于现金,现金,收益

一个大于他各部分的总和


3
尽管我承认不编写JavaScript,但我认为我不认识任何将“ $”发音为“ cash”的人。
卡尔·威索夫特

1
+1我喜欢非文字形式的抄写,尽管有断线的自由,“实体心”还是很有趣的。
杰森C

8

基本知识

更具体地说,Chipmunk Basic。语法规则几乎已经延伸到断点,因此可能无法在其他方言中不加修改地运行它。

资源:

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

笔记:

  • 源代码中没有行号,但是它仍然可以加载和运行,没有任何问题(请参阅下文)。
  • 在BASIC程序的上下文中,该$标记被读取为“字符串”(例如,参见此Wikipedia页面)。

这证明它确实有效:

screen grab of program running in Mac OS X


您是如何制作此gif的?
Kartik

@Kartik我使用了一个名为IShowU
ossifrage

6

重击

由于答案仅被强制包含短语“ Hello World”,因此最简单的解决方案应该是:

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

8
遵守规则是合法的,但是在聚会上这个答案并不好玩meta.codegolf.stackexchange.com/a/1063/3363
Jonathan Van Matre 2014年

1
@JonathanVanMatre这表明问题出在问题上。除了直接打印输出外,没有什么不同。此外,第一个“排除”规则禁止任何更具创造力的规则,甚至包括具有多个字符和代码标识的变量名,这是一个代码高尔夫,被认为是流行竞赛,这是两者中最糟糕的。
维克多·斯塔夫萨

4
@Timtech:是投票和报价。
Keba 2014年

2
您是否考虑过改善问题?/可能会给人留下更好的印象。/虽然造成的伤害/会不会更有趣/制作真正的打油诗编码的甜点?:)
乔纳森·范·马特雷

1
@Victor,“可以安全删除的字符”似乎暗示您不能使用多字符变量名,除非它们是押韵的一部分。那是有问题的。
乔纳森·范·马特雷

6

爪哇

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

请注意,注释在Java中并不是真正可选的


The b in "boat" needs to be removed ("oat' is a valid variable name, and fits)
pppery

6

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

The m and e in both instances of more needs to be removed (ore is a valid word in that position too)
pppery

Hm, I don't think I can legally rhyme or with either or or ore.
histocrat

This wouldn't be the only example of a limerick with duplicate words
pppery

4

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.


2

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.

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

@MikaëlMayer: see the remark in my second paragraph.
Niel de Beaudrap

2

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?


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

2

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


You can always put semi-colon at the beginning of a newline, no?
Mikaël Mayer

True, Mikael, but it makes the code look very untidy!
BrummiePete

1
Between untidy and rhyming, here the point is about rhyming. Don't worry, this code is not peer-reviewed.
Mikaël Mayer

1

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

1
This doesn't compile. How is yellow declared?
ζ--

1

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


Can you find another rhyme dull/dull ?
Mikaël Mayer

@MikaëlMayer it's more useless code, but yes.
unclemeat

1

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


1
#include <stdio.h> //
void main (void){
printf("Hello, World");
//just for rhyme I say stolon
} /**/

hash include less than stdio dot h greater than double slash after a space

void main left paren void right paren left brace

printf left paren quote Hello comma World quote right paren semi colon

double slash just for rhyme I say stolon

right brace and double asterisk between slashes at the last place


Nice one for the first two rhymes, but you use twice the same symbol to rhyme (semi-colon), which is not allowed.
Mikaël Mayer

Debugged, but I guess another bug appeared.
Nayuta Ito

0

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.


1
nul, world, and words do not rhyme. The pattern needs to be AABBA. Also the comma after string should be pronounced.
unclemeat

0

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'


Note the rules: symbols such as ' are read aloud and count as part of the rhyming scheme. Welcome to PPCG!
Jonathan Van Matre

So technically it works. It doesn't say A cannot be B.
CompuChip

0

Python (3)

print('''Nose
No punctuation hear close
Hello World
Hurled and swerled
Goodbye now''')

Print open quote quote quote nose, No punctuation hear close, Hello World, Hurled and swerled, Goodbye now quote quote quote close.


Welcome to the site, and nice first post!
caird coinheringaahing
By using our site, you acknowledge that you have read and understand our Cookie Policy and Privacy Policy.
Licensed under cc by-sa 3.0 with attribution required.