有一个老太太


23

您的目标是编写一个程序,以完全按照此处显示的方式打印以下诗歌:

There was an old lady who swallowed a fly.
I don't know why she swallowed that fly,
Perhaps she'll die.

There was an old lady who swallowed a spider,
That wriggled and iggled and jiggled inside her.
She swallowed the spider to catch the fly,
I don't know why she swallowed that fly,
Perhaps she'll die.

There was an old lady who swallowed a bird,
How absurd to swallow a bird.
She swallowed the bird to catch the spider,
She swallowed the spider to catch the fly,
I don't know why she swallowed that fly,
Perhaps she'll die.

There was an old lady who swallowed a cat,
Imagine that to swallow a cat.
She swallowed the cat to catch the bird,
She swallowed the bird to catch the spider,
She swallowed the spider to catch the fly,
I don't know why she swallowed that fly,
Perhaps she'll die.

There was an old lady who swallowed a dog,
What a hog to swallow a dog.
She swallowed the dog to catch the cat,
She swallowed the cat to catch the bird,
She swallowed the bird to catch the spider,
She swallowed the spider to catch the fly,
I don't know why she swallowed that fly,
Perhaps she'll die.

There was an old lady who swallowed a horse,
She died of course.

文本必须与此处完全一样,并且最少的字符获胜。

编辑:您的程序可能无法访问Internet。


2
以UTF-8编码的字节计数吗?
JB

高尔夫球清楚地说“最少的字符”,而不是字节。只要它仍然是有效程序,就可以对其进行编码。
Thomas Eding

1
作为参考,这首诗长1208个字符。
JB

Answers:


16

Perl 5.10的,392 384 372 235 369(ASCII)/ 234(Unicode)的

ASCII的最短版本为369个字符长:

@_=(fly,spider,bird,cat,dog);$_="There was an old lady who!ed a";for$P("",",
That wrJand Jand jJinside her",",
How absurd&",",
Imagine that&",",
What a hog&"){$p=$c;$c=$".shift@_;$t=$p?"She!ed the$c to catch the$p,
$t":"I don't know why she!ed that$c,
Perhaps she'll die.

$_";$_.="$c$P.
$t";s/&/ to! a$c/}s/!/ swallow/g;s/J/iggled /g;say"$_ horse,
She died of course."

它从以下基本程序开始:

my @animals = qw(fly spider bird cat dog);
my $buf = "There was an old lady who swallowed a ";
for my $phrase ( "",
                 ",\nThat wriggled and iggled and jiggled inside her",
                 ",\nHow absurd&",
                 ",\nImagine that&",
                 ",\nWhat a hog&" ) { 
  $previous = $current;
  $current = shift @animals;
  $trail = $previous ? "She swallowed the $current to catch the $previous,\n$trail"
                     : "I don't know why she swallowed that $current,\n"
                       . "Perhaps she'll die.\n\n$buf";
  $buf .= "$current$phrase.\n$trail";
  $buf =~ s/&/ to swallow a $current/;
}
say "$buf horse,\nShe died of course.";

核心思想是保持韵律的结束和下一首韵律的开始$trail,并随着我们的进行不断增加。首次使用时需要特殊情况,并且尝试重新使用动物名称变量,即使在动物特定的短语中,也使其变得不平凡。进一步的优化包括:

  • 所有内容的单字符标识符
  • 在动物列表中使用裸词而不是用引号引起来的字符串
  • 使用累加器$_$buf进一步缩短大多数替换操作(使用@_是出于习惯,不会比任何其他角色赢得更多的东西)
  • 在动物名称变量内直接包含前一个空格(从$"变量中获取的空格字符)
  • 正则表达式替换以缩短最常用的短语:' swallow''iggled '
  • 没有任何代码间距,所有\n字符串文字都替换为实际的换行符

除了最后的优化之外,所有其他优化都会产生以下结果:

@_ = (fly, spider, bird, cat, dog);
$_ = "There was an old lady who!ed a";
for $P ( "",
         ",\nThat wrJand Jand jJinside her",
         ",\nHow absurd&",
         ",\nImagine that&",
         ",\nWhat a hog&" ) { 
  $p = $c;
  $c = $" . shift @_;
  $t = $p ? "She!ed the$c to catch the$p,\n$t"
          : "I don't know why she!ed that$c,\nPerhaps she'll die.\n\n$_";
  $_ .= "$c$P.\n$t";
  s/&/ to! a$c/;
}
s/!/ swallow/g;
s/J/iggled /g;
say "$_ horse,\nShe died of course.";

此外,这种高尔夫是未指定编码问题的受害者。到目前为止,由于它以指定的编码来计数单个字符而不是字节,因此通过在启动之前从UCS2解码程序源可以获得很大的收益。最终结果不是很可读,但是很简短。(234个字符,perl -E''与往常相比有所不同)(我必须在结尾加上换行符以使其成为有效的UCS2)

$ perl -MEncode=from_to -e'$_="䁟㴨晬礬獰楤敲Ɫ楲搬捡琬摯朩㬤弽≔桥牥⁷慳⁡渠潬搠污摹⁷桯Ⅵ搠愢㭦潲⑐⠢∬∬੔桡琠睲䩡湤⁊慮搠橊楮獩摥⁨敲∬∬ੈ潷⁡扳畲搦∬∬੉浡杩湥⁴桡琦∬∬੗桡琠愠桯朦∩笤瀽④㬤挽␢⹳桩晴䁟㬤琽⑰㼢卨攡敤⁴桥④⁴漠捡瑣栠瑨攤瀬ਤ琢㨢䤠摯渧琠歮潷⁷桹⁳桥Ⅵ搠瑨慴④Ⰺ健牨慰猠獨攧汬⁤楥⸊ਤ弢㬤弮㴢④⑐⸊⑴∻猯☯⁴漡⁡④⽽猯ℯ⁳睡汬潷⽧㭳⽊⽩杧汥搠⽧㭳慹∤张桯牳攬੓桥⁤楥搠潦⁣潵牳攮∊";from_to($_,utf8,ucs2);eval'

在采用Unicode之前,有很多事情可以做,这不是一件好事,否则不会很有趣。

编辑: 找不到将234个字符的版本复制/粘贴到此浏览器的方法,所以我要保留235个字符的版本。当我把手放在真正的UTF8感知剪贴板上时,它将在今天晚上修复。找到了办法。 亚乙基酮的准证明。


2
我撤消了我的投票。Unicode包装技巧越来越老了。
乔伊·亚当斯

2
您知道非压缩版本仍然存在; p
JB

5
@JoeyAdams真的吗?在阅读您的评论之前,我什至没有注意到打包版
Cyoce

8

Perl,120 94个字符

计数包括对口译员的呼叫。

你说过重现它正是因为它这里;)

perl -MLWP::Simple -E'($p=get("http://goo.gl/kg17j"))=~s#^.+?pr.*?de>|</co.*?re>.+$##sg;say$p'

NB

这种解决方案促使出现了“无互联网”限制。让它成为将来的代码高尔夫球问题规范的一课:)


3
我张贴的那一刻,这个条目就变成了奎因!进行一点正则表达式操作即可将服务恢复正常...
Zaid

2
解决它的烂方法,因为它依赖于外部资源的存在。我会像针对从文件中读取诗的程序那样计算问题的长度。
dmckee 2011年

2
外部资源不是问题,因为什么是资源,什么是环境是很可疑的。我喜欢在未严格定义的初始问题中利用差距。这不是一个解决方案,但很好的例子,采取照顾发问:-)
安特

3
解决该问题的方法可能很烂,但是它依赖于外部资源,该外部资源与它所回答的问题一样容易存在。这使其完全可以接受作为对上述问题的答复,即国际海事组织。
JB,

2
@trinithis:我发帖后强加了“禁止上网”的限制。诚然,这不是对解决方案进行编码的认真尝试,但是在发布时符合了规范。哦,LWP::Simple Perl的核心的一部分,至少在v5.12.3。
Zaid的

3

Python 3.x:407个字符

import base64,zlib;print(zlib.decompress(base64.b64decode(b'eNrlkLFOxDAQRPt8xXTXoHwHdEhEot7L+myD8Z7snKz8Pd6LT7mgFFQIRGftPs/OzOBMMiiUQRESGIF4RnGCXCgEKYZBOIW5B7onsMTDhPcopTIzsjN33ORoUvShos8mOTpnJQ4hgL3pu2741rF89mySigwqWJK3NugmMu6eb+3tY648qrRafPniyDQ5TIKRptFdZ83kz+Q5+sQq8ViP0DFfEquZRrT9vnXdbI2v3fzCoPXs9dgHWR/NorpJWoH9oONCrr5vnf35TlisKryqGsGJ3TZS1/uN8EKurlu5/6k7Jymbm7f6kSEnjHKp0/4TSSOZgA==')).decode('utf8'))

3
你可以做这样的事情弄下来到391个字符:进口的zlib;打印zlib.decompress( “” “eJzlkLFOxDAQRPt8xXTXoHwHdEhEot7L + myD8Z7snKz8Pd6LT7mgFFQIRGftPs / OzOBMMiiUQRES GIF4RnGCXCgEKYZBOIW5B7onsMTDhPcopTIzsjN33ORoU​​vShos8mOTpnJQ4hgL3pu2741rF89myS igwqWJK3NugmMu6eb + 3tY648qrRafPniyDQ5TIKRptFdZ83kz + Q5 + sQq8ViP0DFfEquZRrT9vnXd bI2v3fzCoPXs9dgHWR / NorpJWoH9oONCrr5vnf35TlisKryqGsGJ3TZS1 / uN8EKurlu5 / 6k7Jymb m7f6kSEnjHKp0 / 4TSSOZgA ==” “” .decode('base64'))
ESultanik 2011年

创造性的压缩方式。
juniorRubyist

3

的JavaScript(422)

无政府状态高尔夫ideone都使用的SpiderMonkey解释器版本中工作

for(a="fly0spider0bird0cat0dog0horse0How absurd0Imagine that0What a hog".split(i=0);p=print;p("I don't know why she swallowed that fly,\nPerhaps she'll die.\n")){p("There was an old lady who swallowed a",a[i]+(i?",":"."));i>4&&quit(p("She died of course."));i&&p(i>1?a[4+i]+" to swallow a "+a[i]+".":"That wriggled and iggled and jiggled inside her.");for(j=i++;j;)p("She swallowed the "+a[j]+" to catch the "+a[--j]+",")}

格式更好:

for (a = "fly0spider0bird0cat0dog0horse0How absurd0Imagine that0What a hog".split(i = 0);
p = print; p("I don't know why she swallowed that fly,\nPerhaps she'll die.\n")) {
    p("There was an old lady who swallowed a", a[i] + (i ? "," : "."));
    i > 4 && quit(p("She died of course."));
    i && p(i > 1
        ? a[4 + i] + " to swallow a " + a[i] + "."
        : "That wriggled and iggled and jiggled inside her."
    );
    for (j = i++; j;) p("She swallowed the " + a[j] + " to catch the " + a[--j] + ",");
}

巧妙地使用分割0技巧将其初始化i0仅2个字节。+1
Cyoce '17

3

Vim 373次击键

iThere was an old lady who swallowed a fly.
I don't know why she s<C-n> that f<C-n>,
Perhaps she'll die.

T<C-x><C-l><Left><C-w>spider<Esc>oThat wriggled <Esc>6hiand <Esc>3hy$u$ppbij<End>inside her.
She s<C-n> the sp<C-n> to catch the f<C-n>,
I<C-x><C-l><C-x><C-l><Esc>qqyapGp3jYPkk$Bqcwbird<Esc>+CHow absurd to sw<C-n><Backspace><Backspace> a b<C-n>.<Esc>qwyb5wvep$Bvepq@qcwcat<Esc>+CImagine that to sw<C-p> a cat.<Esc>@w@qcwdog<Esc>+CWhat a hog to sw<C-p> a dog.<Esc>@w@qcwhorse<Esc>+cGShe d<C-p>d of course.

有趣的是,加扰是指数级的。


3

C(gcc)429424字节

--5个字节,感谢ceilingcat

*w[]={"384fly<1","I don't know why she5ed that fly<Perhaps she'll die.772","There was an old lady who5ed a ","She5ed the "," to catch the "," swallow"," to5 a ","\n","spider","bird","cat","iggled ",",7","3948<0"};U(char*s){for(;*s;s++)*s>47&*s<65?U(w[*s-48]):putchar(*s);}f(){U("2fly.718<That wr;and ;and j;inside her.709<How absurd69.7=:<Imagine that6:.73:49<=dog<What a hog6dog.73dog4:<3:49<=horse<She died of course.7");}

在线尝试!


2

Ruby,436个​​字符

w=" swallowed "
f="There was an old lady who#{w}a "
c=" to swallow a %s"
b="dog","cat","bird","spider","fly"
s=nil,"That wriggled and iggled and jiggled inside her","How absurd"+c,"Imagine that"+c,"What a hog"+c
a=[]
5.times{k=g=b.pop;t,*s=s
puts f+k+(t ??,:?.),t&&[t%k+?.,a.map{|x|y,k=k,x;"She#{w}the #{y} to catch the #{k},"}],"I don't know why she#{w}that fly,","Perhaps she'll die.",""
a=[g]+a}
puts f+"horse,","She died of course."

2

阶(706 619 599 550个字符)

val L=Seq("fly","spider","bird","cat","dog")
val M="\nThere was an old lady who %sed a %s,"
type S=String
def s(l:S,a:S="",b:S="")=l.format("swallow",a,b)
def p(l:S,a:S=""){println(s(l,a))}
var i=0
var r=List[S]()
L.map{a=>{p(M,a)
if(i>0){p(Seq("","That wriggled and iggled and jiggled inside her.","How absurd","Imagine that","What a hog")(i)+(if(i>1)" to %s a %s."else""),a)
r::=s("She %sed the %s to catch the %s,",L(i),L(i-1))
r.map(p(_))}
p("I don't know why she %sed that fly,\nPerhaps she'll die.")
i+=1}}
p(M,"horse")
p("She died of course.")

使用map而不是foreach可以挤压更多字符...在代码高尔夫中,我们不在乎性能,优雅(不可变异性)或逻辑...


2

370个 369 354字节

LIST B=fly,spider,bird,cat,dog,horse
VAR s=" swallow"
-(i)~B=B(i)
There was an old lady who{s}ed a {B}{.|,}
{|That wriggled and iggled and jiggled inside her|How absurd|Imagine that|What a hog|She died of course.->END}{|.| to{s} a {B}.}
-(k)~B--
{B:
She{s}ed the {B+1} to catch the {B},
->k
}I don't know why she{s}ed that fly,
Perhaps she'll die.
\ 
->i

在线尝试!

说明

LIST B=fly,spider,bird,cat,dog,horse           // Ink's "LIST"s aren't much like lists - they're more like enums. Here we create a list type stating what animals exist, and make a set containing none of them.
VAR s=" swallow "                              // Pretty self-explanatory
-(i)~B=B(i)                                    // The i label keeps track of how many times we've visited it. We set B (the set) to be equal to the i-th item in B (the list type).
There was an old lady who{s}ed a {B}{.|,}      // Print the first line. {.|,} is a sequence - it's a period the first time it's encountered, and a comma every subsequent time.
                                               // Sequences can have more than one item in them, which is how we print the second line. When we get to the horse one, we terminate the program right away.
{|That wriggled and iggled and jiggled inside her|How absurd|Imagine that|What a hog|She died of course.->END}{|.|to{s} a {B}}.}
-(k)~B--                                       // Step back through the list type.
{B:                                            // A conditional - we execure the next two lines if B is non-empty.
She{s}ed the {B+1} to catch the {B},           // Print the "she swallowed the..." line
->k                                            // And repeat
}I don't know why she{s}ed that fly,           // Only reached when the conditional fails.
Perhaps she'll die.
\                                              // A backslash and a space to force an empty line.
->i                                            // Back to the top

1

哈斯克尔,515 498

分数不计算换行符和为演示添加的空格。

b c a="There was an old lady who swallowed a "++a++c++".\n"
t r a=b(",\n"++r++" to swallow a "++a)a
s(a,b)="She swallowed the "++a++" to catch the "++b++",\n"
z=["fly","spider","bird","cat","dog"]
h=[b"",b",\nThat wriggled and iggled and jiggled inside her",t"How absurd",
 t"Imagine that",t"What a hog"]
v(g,p)=g++(=<<)s(zip p$tail p)++
 "I don't know why she swallowed that fly,\nPerhaps she'll die.\n\n"
main=putStr$(=<<)v(zip(zipWith($)h z)(tail$scanl(flip(:))[]z))++b
 ",\nShe died of course""horse"

取消高尔夫:

type Animal = String
type Comment = String

beginning :: Animal -> Comment -> String
beginning animal comment = "There was an old lady who swallowed a " ++ animal ++ comment ++ ".\n"

ending :: String
ending = "I don't know why she swallowed that fly,\nPerhaps she'll die.\n\n"

to_swallow :: String -> Animal -> Comment
to_swallow start animal = ",\n" ++ start ++ " to swallow a " ++ animal

swallowed_to_catch :: (Animal, Animal) -> String
swallowed_to_catch (a, b) = "She swallowed the " ++ a ++ " to catch the " ++ b ++ ",\n"

animals :: [(Animal, Animal -> Comment)]
animals = [("fly",    const "")
          ,("spider", const ",\nThat wriggled and iggled and jiggled inside her")
          ,("bird",   to_swallow "How absurd")
          ,("cat",    to_swallow "Imagine that")
          ,("dog",    to_swallow "What a hog")
          ]

-- Turn [1,2,3,4,5] into [[1], [2,1], [3,2,1], [4,3,2,1], [5,4,3,2,1]]
trail :: [a] -> [[a]]
trail = tail . scanl (flip (:)) []

verses :: [String]
verses = zipWith verse animals (trail $ map fst animals)

verse :: (Animal, Animal -> Comment) -> [Animal] -> String
verse (animal, comment) swallow_chain =
    beginning animal (comment animal) ++
    concatMap swallowed_to_catch (zip swallow_chain (tail swallow_chain)) ++
    ending

poem :: String
poem = concat verses ++ beginning "horse" ",\nShe died of course"

main :: IO ()
main = putStr poem

(++)使用较短的标识符进行别名可能是个好主意。
Thomas Eding

@ThomasEding或将其别名给#运算符或类似内容
Cyoce

1

蟒蛇,484

好的,我做到了,但是很无聊...

最后一句话总是带有“ fly”,因此一些字符被删除了。

f,s,b,c,d=o='fly spider bird cat dog'.split()
x='There was an old lady who swallowed a %s.\n'
t=' to swallow a %s.\n'
r=['That wriggled and iggled and jiggled inside her.\n','How absurd'+t%b,'Imagine that'+t%c,'What a hog'+t%d]
t=("She swallowed the %s to catch the %s,\n"*4%(d,c,c,b,b,s,s,f)).split('\n')
print("I don't know why she swallowed that fly,\nPerhaps she'll die.\n\n".join([x%f]+[x%o[i]+r[i-1]+'\n'.join(t[-i-1:])for i in range(1,5)]+[''])+x%'horse'+'She died of course.')

少打高尔夫球的版本:

f,s,b,c,d = all = 'fly spider bird cat dog'.split()

what = 'There was an old lady who swallowed a %s.\n'

t = ' to swallow a %s.\n'
comments = ['That wriggled and iggled and jiggled inside her.\n',
            'How absurd' + t%b,
            'Imagine that' + t%c,
            'What a hog' + t%d]

swallowed = "She swallowed the %s to catch the %s,\n"
lines = (swallowed*4%(d,c,c,b,b,s,s,f)).split('\n')

end = '''I don't know why she swallowed that fly,
Perhaps she'll die.\n\n'''

def who_catch_who(i):
    return '\n'.join(lines[-i-1:])

p = end.join([what % f] + 
             [what % all[i] +
              comments[i-1] +
              who_catch_who(i) for i in range(1,5)] +
             [''])

print(p + what % 'horse' + 'She died of course.')

1

C,好玩(561个字符)


分数不计算换行符和为演示添加的空格。

感谢JB的改进!

#include <stdio.h>

void main() {
    char *e = "\nShe swallowed the cat to catch the bird,\nShe swallowed the bird to catch the spider,\nShe swallowed the spider to catch the fly,\nI don't know why she swallowed that fly,\nPerhaps she'll die.\n\nThere was an old lady who swallowed a ";
    printf("%sfly.%sspider,\nThat wriggled and iggled and jiggled inside her.%sbird,\nHow absurd to swallow a bird.%scat,\nImagine that to swallow a cat.%sdog,\nWhat a hog to swallow a dog.\nShe swallowed the dog to catch the cat,%shorse,\nShe died of course.", e+191, e+128, e+85, e+41, e, e);
}

你确定你需要所有这些&[]
JB

1
@JB是正确的,您可以将* [a]替换为* a,而只需删除&。您应该获得25个字符。
PhiLho 2011年

在C中可能需要完成一些很酷的事情,即使用指向公共共享字符串中间的指针。
JB,

@PhiLho谢谢,昨天我的大脑有点炸了,我忘记了&在使用指针时删除s的问题,但是:P JB,我不知道不需要索引的方法(甚至可以使用更多字符)。
马修(Matthew)

1
这样的事情。您的版本已重新排序,最多 627个字符pastebin.com/MQ4LJue7 ; 我的版本为561个字符,pastebin.com / 7eMAWmAi
JB

1

C#,556个字符

class P{static void Main(){string a="There was an old lady who swallowed a ",b="I don't know why she swallowed that ",c="She swallowed the ",d=" to catch the ",e="Perhaps she'll die.\n\n",f="fly",g="spider",h="bird",i="cat",j="dog",k=",\n",l=".\n",m="to swallow a ",n=c+g+d+f+k,o=c+h+d+g+k,p=b+f+k,q=c+i+d+h+k,r=n+p,s=o+r,t=q+s,u=e+a;System.Console.Write(a+f+l+p+u+g+k+"That wriggled and iggled and jiggled inside her"+l+r+u+h+k+"How absurd "+m+h+l+s+u+i+k+"Imagine that "+m+i+l+t+u+j+k+"What a hog "+m+j+l+c+j+d+i+k+t+u+"horse"+k+"She died of course.");}}

1

Perl,489个字符

sub Y{$t=pop;my$s;while($b=pop){$s.="She ${W}ed the $t to catch the $b,\n";$t=$b;}$s.=$l{fly}.$/;}$W='swallow';$w='iggled';$q=" to $W a";$o="There was an old lady who ${W}ed a";$h='hat';@f=qw/fly spider bird cat dog/;@l{@f}=("I don't know why she ${W}ed t$h fly,
Perhaps she'll die.$/","T$h wr$w and $w and j$w inside her.","How absurd$q bird.","Imagine t$h$q cat.","W$h a hog$q dog.");map{$m=$f[$_];print"$o $m,
$l{$m}
",$_?Y@f[0..$_]:'';}0..$#f;print"$o horse,
She died of course.$/"

1

PHP,344字节

<?=gzinflate(base64_decode("5VAxTsQwEOz9iu2uifIO6JA4iXovu2cbjPdk+2Tl96zjoLugFFQIRGfNjGdn5ug4MVTMgBEkEASkGaoTyBVDkMoECOcwj+YRSOKhwFuUqooZsuM7VXFYmnAwT5wcXnLjDyEAeR6NOX7rUL544jSoWs1q8taGhkeCu+fr+vYxqxrUeDTPX7LwagVFYMIyuQVb4v1Ej5NPNJgHPYCnfE3UYqz8yu5Fbvg28Ocev6yentRD72h95O646af0Xr2p6255+0p/eAcSO5iX5oTgxG5XUHJvBeq6W9plzP+wlpOUuafSbwRyhkmuio0f"));

在线尝试!

PHP,405字节

<?=strtr("0fly.
106That wr8and 8and j8inside her.
23107,
How absurd57.
274623109,
Imagine that59.
2947,
27462310dog,
What a hog5dog.
2dog49,
2947,
27462310horse,
She died of course.",["There was an old lady who swallowed a ","I don't know why she swallowed that fly,
Perhaps she'll die.

","She swallowed the ","spider to catch the fly,
"," to catch the "," to swallow a ","spider,
",bird,"iggled ",cat]);

在线尝试!


1

Bubblegum,255个字节

0000000: e0 04 85 00   f7 5d 00 2a   1a 08 a7 55   8e 22 31 d2 │ à...÷].*..§U."1Ò
0000010: cb f7 30 fa   52 4d 88 81   61 e4 be 9d   c2 f0 0e f8 │ Ë÷0úRM..aä¾.Âð.ø
0000020: dc c9 de 24   63 c9 1f c7   f7 71 e4 ed   40 68 0e d2 │ ÜÉÞ$cÉ.Ç÷qäí@h.Ò
0000030: cd 76 d8 d9   0d 61 78 f7   40 cf 23 95   48 e9 be 27 │ ÍvØÙ.ax÷@Ï#.Hé¾'
0000040: aa 75 57 ff   51 9e 1f 1f   25 d8 93 4d   18 69 c9 01 │ ªuWÿQ...%Ø.M.iÉ.
0000050: 12 16 ec c1   ff e0 01 7e   fa ea 1e cc   84 d7 58 b8 │ ..ìÁÿà.~úê.Ì.×X¸
0000060: 47 d4 40 b4   ff c7 64 a9   2f 07 bf 7b   f4 25 74 94 │ GÔ@´ÿÇd©/.¿{ô%t.
0000070: af da 8a fc   0c 18 81 58   b8 3c 2e 97   c0 9d e8 27 │ ¯Ú.ü...X¸<..À.è'
0000080: 3e 02 8a d2   1b 7c 94 cc   cb f4 05 7c   c7 77 f3 75 │ >..Ò.|.ÌËô.|Çwóu
0000090: ea 7e 02 d6   3a 84 5c 4e   1f 88 e7 03   9a 1d 3f 13 │ ê~.Ö:.\N..ç...?.
00000a0: a6 9f 2e cf   be 77 16 be   f1 5f 01 52   cf 13 89 b3 │ ¦..Ͼw.¾ñ_.RÏ..³
00000b0: f3 8a f7 90   18 08 50 99   27 f7 83 d2   a4 32 08 76 │ ó.÷...P.'÷.Ò¤2.v
00000c0: ef b4 99 6c   80 dd 1a 47   04 26 fe b1   02 b3 d4 e7 │ ï´.l.Ý.G.&þ±.³Ôç
00000d0: 3d 44 3a 64   64 46 39 77   35 61 6b 6c   7b 68 34 db │ =D:ddF9w5akl{h4Û
00000e0: 51 75 39 2e   bc 46 8e 96   d1 8a 4c 79   f4 7a 7b e0 │ Qu9.¼F..Ñ.Lyôz{à
00000f0: f5 44 85 eb   ef 68 d5 22   26 4a 2a ef   fc 60 00    │ õD.ëïhÕ"&J*ïü`.

1

Python 2中453个442 427 387字节

  • @nore保存了11个字节:谢谢!!:£之前使用的是双字节字符!
  • 保存15个字节:swallow速记
  • @nore保存了40个字节!!!!! 非常感谢!!!
  • @Zachary T保存了1个字节:空格in与空格之间"..."已删除
  • 感谢notepad ++的查找和替换工具。;)
r="%2(:0)That wr66j5 inside her(_1)How absurd+1({3)Imagine that+3(}4)What a hog+4(~4*3)}horse)She died of course."
for i in"}~3*1){!{~1*0)_!_~0*2):!:^2)$%!~She7ed the !%There was an old lady who7ed a !$Perhaps she'll die(\n!* to 3ch the !^I don't know why she7ed that !+ to7 a !(.\n!),\n!0spider!1bird!2fly!3cat!4dog!65 and !5iggled!7 swallow".split("!"):r=r.replace(i[0],i[1:])
print r

在线尝试!


1
您可以使用~代替来节省很多字节£(因为不是ASCII,所以两个字节长)。
诺雷

哇,谢谢你!从来不知道那是一个扩展的角色!!
Officialaimm

1
仍然可以打很多球(开头有几个字符,带有符号的1个字符,使用Python2的字符,还有更多优化替换的字符)
2017年

1
您不需要在in字符串文字之间加空格。
扎卡里

1

Groovy,475个字节

b="swallowed"
a="There was an old lady who $b a"
c="I don't know why she $b that fly,\nperhaps she'll die."
d="She $b the"
e=" to catch the"
f=" to swallow a"
g="iggled"
h=" spider"
i=" fly"
j=" dog"
k=" cat"
l=" bird"
m="$d$h$e$i,"
n="$d$l$e$h,"
o="$d$k$e$l,"
print"""
$a$i.
$c

$a$h,
That wr$g and $g and j$g inside her.
$m
$c

$a$l,
How absurd$f$l.
$n
$m
$c

$a$k,
Imagine that$f$k.
$o
$n
$m
$c

$a$j,
What a hog$f$j
$d$j$e$k,
$o
$n
$m
$c

$a horse,
She died of course."""

没什么有趣的,只是很多字符串插值。欢迎在此方面打高尔夫球!


您的意思是写吞咽而不是变浅吗?
破坏的柠檬

@Destructible Lemon,现在修复:P
静态方法

1

tcl,451个字节

lassign {\ swallowed fly, spider " to catch the " bird cat iggled " to swallow a"} W f s c b a i w
puts "[set t "There was an old lady who$W a "]fly.
[set I "I don't know why she$W that $f
Perhaps she'll die.

"]$t$s,
That wr$i and $i and j$i inside her.
[set S "She$W the "]$s$c$f
$I$t$b,
How absurd$w $b.[set v \n$S$b$c$s,\n$S$s$c$f\n$I]$t$a,
Imagine that$w $a.
[set X $S$a$c$b,$v$t]dog,
What a hog$w dog.
${S}dog$c$a,
$X\horse,
She died of course."

可在以下网址上运行:http//rextester.com/live/GXF89639(第10次尝试)


1

Wolfram语言(Mathematica),295个字节

BinaryDeserialize@ByteArray@ToCharacterCode@"8C:xœåPANÃ0<ãWì­—(ï€R‘8o³[ÛÅx+;••ðnÖqª6(NÄÍšÏÎÌþãáÅqb(˜#H H'† …	Žaê͐ÄÝoQŠ*&ÈŽïT£Ã±
;óÌÉá9W~çÞ˜ïÊgOœ:U«YIÞÚPñHp÷<-o³ªA{³ÿ’…+7cs¼Ÿèqð‰:ó¨ð/‰jŒ…_Ø­È_¾îñËêéI=ôŽÖGnŽ«~JoÕšî–·­ô‡w ±y­NNìz%·V ¦»¥Çük9I™[*ýF Gä¢Xÿ	Tÿ”\""

在线尝试!

此解决方案是一个46字节的解压缩器,BinaryDeserialize@ByteArray@ToCharacterCode@"..."作用于伪装为ASCII字符串的248字节的数组上。在不同程序之间传输此字符串有些棘手。例如,TIO使用UTF-8编码而不是保留ASCII字符串将该解决方案扩展为416字节。要获得最小295字节的解决方案,请将文本保存在变量中text并运行

BinaryWrite["ThereWasAnOldLady.wl", Join[
  ToCharacterCode["BinaryDeserialize@ByteArray@ToCharacterCode@\""],
  Normal[BinarySerialize[text, PerformanceGoal -> "Size"]] /. {34 -> Sequence[92, 34]},
  ToCharacterCode["\""]]]

然后使用以下命令在命令行上执行生成的文件

wolframscript -print -f ThereWasAnOldLady.wl 

0

Java 758个字符

这是我的Java工作(758个字符)

public class Poem{public static void main(String[] args){String s1="swallowed",st="There was an old lady who "+s1+" a |.",d1="Perhaps she'll die.",d2="She died ofcourse.",e="I don't know why she " + s1 + " that fly,\n";String[] a={ "fly","spider","bird","cat","dog","horse"};String[] q={ "","That wriggled and iggled and jiggled inside her.","How absurd |","Imagine that |","What a hog |",null};for(int i=0;i < a.length;i++){print(st.replace("|",a[i]));if(q[i]==null){print(d2);break;}if(!q[i].isEmpty()){               print((q[i].replace("|","to swallow a " + a[i])).trim());for(int j=i;j > 0;j--){print("She swallowed the " + a[j] + " to catch the " + a[j - 1] + ",");}}print(e + d1 + "\n");}}
static void print(String value){System.out.println(value);}}

2
您可以获得一些字符...诗=> P,args => x,打印=> p,值=> v,两个字母vars =>一个字母vars,删除更多空格。
PhiLho 2011年

0

Java,655个字节

public class M{public static void main(String[]P){String S="swallowed",T="There was an old lady who "+S+" a |.",e="I don't know why she "+S+" that fly,\n";String[]a={"fly","spider","bird","cat","dog","horse"};String[]q={"","That wriggled and iggled and jiggled inside her.","How absurd |","Imagine that |","What a hog |",null};for(int i=0;i<a.length;i++){p(T.replace("|",a[i]));if(q[i]==null){p("She died of course.");break;}if(!q[i].isEmpty()){p((q[i].replace("|","to swallow a "+a[i])).trim());for(int j=i;j>0;j--){p("She swallowed the "+a[j]+" to catch the "+a[j-1]+",");}}p(e+"Perhaps she'll die.\n");}}static void p(String v){System.out.println(v);}}

这是此答案修正版本。在小事上节省了100多个字节。


打高尔夫球的更多事情:public 可以删除;class M{public static void main可以interface M{static void main; String S=...,T=...,e=...;String[]a=...;String[]q=...;可以String S=...,T=...,e=...,a[]=...,q[]=...;; for(int i=0;...)...for(int j=i可以for(int i=0,j;...)...for(j=i; for(j=i;j>0;j--)...a[j]...a[j-1]可以for(j=i;j>0;)...a[j]...[a--j]; static void p(String v){...}可以为static<T>void p(T v){...}623字节在线尝试。
凯文·克鲁伊森

0

木炭369个 366字节

A”↓0*)B⎚D³9;7Q7∨-f¶_²χ⁶;↧l⁺I´”¦αA“V×q▶²▷O≕⦃0j↖▷(τ⎇⦄4ω\`j0T⁹ψI2b1züρÀ↑‹⁻ê£AZ‹?DOR§1φ”¦βA⟦spider¦bird¦cat¦dog⟧¦λA,¶¦νA⟦”↶7⎇IPVpθθ⪪➙S²p⸿H⁸✂ν‖2↖²φ↘nτME⦄B↓ξlF⁵y”¦”↶7Nl@;⪫λ38N∕´≕⁺)³ nÀ‴⦃”¦”↶7←´<7YKBYχnZ-↖U⎇ι\HUθ%;⟧”¦”↶7∧§‴⟧O×φ¢\`*NQ¶G⁺$π‽ξat”⟧μA”↓/!Zm⪫⟧αÀ⁻Vε>⟲”¦σA”|‽aC-⁴t;Z⌕”¦τA“Y∨↷ur1BO#ÿk»⁻υv‽⌊←zω↘^”¦η⁺αβF⁴«⁺⁺⁺α§λιν§μιF⮌…⁰ι«⁺⁺⁺⁺σ§λ⁺κ¹τ§λκν»⁺⁺⁺σ§λ⁰τβ»⁺αη

在线尝试!

链接到详细版本的代码。


0

PowerShell的,512字节

[IO.StreamReader]::new(([IO.Compression.GZipStream]::new([IO.MemoryStream]::new(([Convert]::FromBase64String('H4sIAAAAAAAEAOVQQWoDMQy8L+wfdMsl5B3tLdBAz8pKsd26VrAdzP4+cm2SbNlDT6WlN6EZzYzmYDkyFEyAAcQTeKQZihVIBb2XwgQIJz/vxuEZSMImw3uQopQZkuUHWraYK3M7DnuOFs+pEjbeAznW83E4fMssnR1x3Fa6CpbojPEVCAQP41ufXUhKB1VWi5cvgbiLQRaYME/2c9cy/tA3RxdJNZ7UBI/pEqlm6YQOrwavwDL2rZdf+KXaVrMPNC5wU128qfjql1Mj3lP3uv56HyRGJV6rGoIVs2xD0dU2qBHvmVut/6c2KzFxj6aXBHKCSS663F0B')),0,249),[IO.Compression.CompressionMode]::Decompress))).ReadToEnd()

在线尝试!

感谢@Chirishman他们的岗位


0

Stax,195 字节

ó┤♣≤jß¡εD<Çjò≡²£c¼ìv┴Åô║,·~┼¢╝EΦ5xZ&√σ"ømÿ≡ZπvÅ╦♣1♦>▄\¬◘¡jS¢í╞╟╚);4j↕i¢s♦éÇöy‼ac┴àÇ╩»-ó»ónú¢│g5εÿ╔µ┬bîæ¢k‼f╓fJ○▐═╜<^Γ▀o▀Δnq░╩αÄ&│♣ⁿâmû╣Ç≡*@☺pG_ⁿö┤mσ/V\└?iq┌îB½Ä¿L╙N┐£Ç≥δ2 0δrµLä⌡(⌡▀╬àΦ⌠tƒìg" ⌠ZHó

运行并调试

拆开包装,松开包装并进行评论,看起来像这样。

`]q~*}8x9uA3_P0O`jX         push ["fly", "spider", "bird", "cat", "dog"] and store in X register
{                           start iteration over animal list
  `p{+P91{m@Lwe\Jk?!#8`Yp   Store "There was an old lady who swallowed a " in Y register and print it
  .,.i!@+                   Concatenate "." on the first iteration and "," thereafter to the animal
  P                         Print
  i{                        On all iterations after the first, execute this block
    `r4uB2O'O(4XghNqE PhaMg^-riMgR{N>A8LfCNqh@Rn$=aHX|93@_5d?d7qp2-`
                        Push "That wriggled and iggled and jiggled inside her. How absurd, bird. Imagine that, cat. What a hog, dog. She died of course"
    ',`?~nA${F"`R       Replace "," with " to swallow a"
    .. /                Split on string ". "
    iv@                 Get the (i-1)th element where i is the iteration index
    '.+P                Concatenate "." and print
  }M                    End of conditional block
  x2B                   Get adjacent pairs from x (list of animals)
  i(                    Keep first i pairs where i is the iteration index
  r{                    Iterate over reversed list of pairs
    `_,m+"S3&#`p        Print "She swallowed the "
    Ep                  Print the second animal from the pair
    `p<qr?t`p           Print " to catch the "
    ',+P                Concatenate "," to the first animal from the pair and print
  F                     End iterating block
  `;p(9Cv,77BzpP'kB|"`P Print "I don't know why she swallowed that fly,"
  `%?/3.=iHiS6y!`P      Print "Perhaps she'll die."
  zP                    Print a newline
F                       End outer animal iteration.
yp                      Print y register. ("There was an old lady who swallowed a ")
`zvVH`P                 Print "horse,"
                        Print "She died of course." with an unterminated literal
`AJt6Q.3+$!

运行这个


-1

PowerShell,349字节=脚本:9 +存档:340

tar xOf t

在线尝试!

用于创建归档文件的Powershell脚本t(请参见TIO):

(
@'
There was an old lady who swallowed a fly.
I don't know why she swallowed that fly,
Perhaps she'll die.
......
There was an old lady who swallowed a horse,
She died of course.
'@
) | Set-Content f -Force
tar zcfo t f
Get-ChildItem f,t # output info about archive size
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.