노부가 있었다


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.

텍스트는 여기와 똑같이 나타나야하며 가장 적은 문자가 이깁니다.

편집 : 프로그램이 인터넷에 액세스하지 못할 수 있습니다.


2
UTF-8로 인코딩 된 바이트로 계산 되었습니까?
JB

골프는 분명히 바이트가 아니라 "가장 적은 문자"라고 말합니다. 여전히 유효한 프로그램이라면 원하는 방식으로 인코딩하십시오.
토마스 에딩

1
참고로시의 길이는 1208 자입니다.
JB

답변:


16

펄 5.10 392 384 372 235 369 (ASCII) / 234 (유니 코드)

가장 짧은 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'

유니 코드에 의지하기 전에 골프를 많이 타는 것이 좋았습니다.

편집 : 234 자 버전을이 브라우저에 복사 / 붙여 넣는 방법을 찾을 수 없으므로 235 자 버전을 남겨 두겠습니다. 실제 저녁 UTF8 인식 클립 보드에 손을 대면 오늘 저녁에 고칠 것입니다. 방법을 찾았습니다. ideone에 준-증거.


2
나는 투표를 취소했다. 유니 코드 패킹 트릭이 오래되었습니다.
Joey Adams

2
압축되지 않은 버전은 아직 남아 있습니다. p
JB

5
@JoeyAdams 정말? 나는 당신의 의견을 읽을 때까지 포장 된 버전을 보지 못했습니다
Cyoce

8

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

2
외부 자원은 문제가되지 않습니다. 자원이 무엇인지, 환경이 무엇인지는 상당히 의문입니다. 나는 엄격하게 정의 된 초기 질문에 격차를 이용하는 것을 좋아합니다. 이것은 해결책이 아니지만주의를 기울이는 좋은 예입니다. :-)
Ante

3
그것을 해결하는 썩은 방법 일지 모르지만 대답하는 질문만큼 정확하게 존재하는 외부 리소스에 의존합니다. 이는 IMO라는 질문에 대한 답변으로 완벽하게 수용 가능합니다.
JB

2
@trinithis : 게시물 이후 '인터넷 없음'제한이 부과되었습니다. 분명히 이것은 솔루션을 코딩하려는 심각한 시도는 아니지만 솔루션을 게시 할 때 사양을 충족했습니다. 아, 그리고 LWP::Simple 이다 적어도 v5.12.3에, 펄 코어의 일부입니다.
Zaid

3

파이썬 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 GIF4RnGCXCgEKYZBOIW5B7onsMTDhPcopTIzsjN33ORoUvShos8mOTpnJQ4hgL3pu2741rF89myS igwqWJK3NugmMu6eb + 3tY648qrRafPniyDQ5TIKRptFdZ83kz + Q5 + sQq8ViP0DFfEquZRrT9vnXd bI2v3fzCoPXs9dgHWR / NorpJWoH9oONCrr5vnf35TlisKryqGsGJ3TZS1 / uN8EKurlu5 / 6k7Jymb m7f6kSEnjHKp0 / 4TSSOZgA ==" "".decode ( 'base64'))
ESultanik

이것을 압축하는 창의적인 방법.
juniorRubyist

3

자바 스크립트 (422)

에서 작동 무정부 상태 골프이데온 모두에서 사용되는 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

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) , 429 바이트

ceilingcat 덕분에 -5 바이트

*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

루비, 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.")

foreach 대신 map을 사용하면 더 많은 문자를 짜낼 수 있습니다 ... codegolf에서는 성능, 우아함 (비 변이성) 또는 논리에 신경 쓰지 않습니다 ...


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

(++)식별자가 더 짧은 별명을 사용하는 것이 좋습니다.
토마스 에딩

@ThomasEating 또는 #운영자 에게 알리거나 비슷한 것
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

공통 공유 문자열의 중간에 대한 포인터를 사용하여 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

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

풍선 껌, 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

파이썬 2 , 453442427 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를 사용하지 않는 2 바이트 길이 의 바이트를 사용하여 많은 바이트를 저장할 수 있습니다 .
Nore

와, 고마워! 그것이 연장 된 chararcter 인 것을 결코 몰랐다!!
officialaimm

1
이것은 여전히 굉장히 골프를 칠 수 있습니다 (처음에는 기호가있는 몇 개의 문자, Python2를 사용하여 1, 더 최적화 된 교체)
Nore

1
in문자열 리터럴 사이에는 공백이 필요하지 않습니다 .
Zacharý

1

그루비, 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
staticmethod

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 Language (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ÿ”\""

온라인으로 사용해보십시오!

이 솔루션은 BinaryDeserialize@ByteArray@ToCharacterCode@"..."ASCII 문자열로 가장 한 248 바이트 배열에서 작동 하는 46 바이트 압축 풀기 프로그램 입니다. 다른 프로그램간에이 문자열을 전송하는 것은 약간 까다 롭습니다. 예를 들어, TIO는 ASCII 문자열을 유지하는 대신 UTF-8 인코딩을 사용하여이 솔루션을 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

자바 758 자

여기 내 자바 노력이 있습니다 (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

0

자바, 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 바이트 ) 온라인으로 사용해보십시오.
Kevin Cruijssen

0

, 369366 바이트

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
당사 사이트를 사용함과 동시에 당사의 쿠키 정책개인정보 보호정책을 읽고 이해하였음을 인정하는 것으로 간주합니다.
Licensed under cc by-sa 3.0 with attribution required.