12 일의 크리스마스 가사


17

나는 이것이 모든 사람에게 재미있는 도전이 될 것이라고 생각했고 사람들이 생각해내는 해결책을보고 싶어합니다.

"12 Days Of Christmas"가사 인쇄

On the first day of Christmas, 
my true love gave to me,
A partridge in a pear tree. 

On the second day of Christmas, 
my true love gave to me,
Two turtle doves, 
And a partridge in a pear tree. 

...

On the twelfth day of Christmas,
My true love gave to me,
Twelve drummers drumming,
Eleven pipers piping,
Ten lords-a-leaping,
Nine ladies dancing,
Eight maids-a-milking,
Seven swans-a-swimming,
Six geese-a-laying,
Five golden rings,
Four calling birds,
Three french hens,
Two turtle doves,
And a partridge in a pear tree.

규칙

  • 대문자 사용에 대해 걱정할 필요가 없습니다. 전체 텍스트는 대소 문자를 구분하지 않을 수 있습니다
  • 하이픈은 공백이 될 수 있고 쉼표와 마침표는 무시할 수 있습니다.
  • 각 구절 사이에 빈 줄이 있어야합니다
  • "당신은 당신의 번호를 ordinalize해야한다 첫째 ,"크리스마스의 일 " 4 개의 새 전화"등

3
각 줄의 정식 버전을 제공 할 수 있습니까? 나는 "나의 진정한 사랑 내게 것"에 익숙하며 다른 버전을 사용하면 솔루션에 영향을 줄 수 있습니다.
Matthew 읽기

완전한 가사를 업데이트했습니다.
macek

"문장 대문자를 버릴 수 있습니까"또는 "텍스트 전체가 대소 문자를 구분하지 않습니다"같은 유형의 대문자 사용에 대해 걱정하지 않습니까?
JB

또한 구두점을 무시하는 줄에서 구두점을 공백 (및 역수)으로 바꿀 수 있습니까?
JB

1
@ macek : 더 좋지만 내 질문의 잠재 측면은 공백 대신 하이픈을 인쇄 할 수 있습니까?
JB

답변:


23

브레인 씨발-2,974

나는 이것을 자랑스럽게 생각합니다. 꽤 큰 숫자처럼 들리지만 외부 압축 라이브러리를 사용하지 않았으며 원래 텍스트가 내 프로그램에 어디에도 없습니다. 다른 제출물 중 누구도 그렇게 말할 수 없습니다. 이것은 모두 직접 코딩되어 있습니다. 더 순진한 텍스트 생성기는이 텍스트에 대해 39k 이상을 제공하므로 이것이 상당히 개선되었다고 말할 수 있습니다.

>--[<->+++++]<---[>+>+>+>+>+<<<<<-]++++++++++>>[+++++>]<<<[+++++>]<<[+
++++>]<+++++>>++++[<++++++++>-]++++++++++++>+>+>>>>>>>>>>>>>+<<<<<<<<<
<<<<<<[<<<<++.-.->>>.<<++.--<<.<++.-->>>>>.>>>>>>>>>>>>>>[<<<<<<<<<<<<
<<<<++.>.<<<<++.-->>-.+<--.++>>.--<<.>>>>.>>>>>>>>>>>>>>-]<[<<<<<<<<<<
<<<<<<<<++.>>-.<<.>>>>-.+<<<<.-->>++.>++.--<<.>->>>.>>>>>>>>>>>>>>+<-]
<[<<<<<<<<<<<<<<++.<<<++.-->>+.->.--<<.>>>>.>>>>>>>>>>>>>+<-]<[<<<<<<<
<<<<<<<+.<+.>.->++.--<<-.>>>>.>>>>>>>>>>>>+<-]<[<<<<<<<<<<<<<<<++.-->+
.--.+.>>++.--<<.>>>>.>>>>>>>>>>>+<-]<[<<<<<<<<<<<+.<<<++.>>>>-.+<<<<.-
->>+.->+.--<<.>>>>.>>>>>>>>>>+<-]<[<<<<<<<<<<+.<<+.>>>+.-<+.--<<-.>>>>
.>>>>>>>>>+<-]<[<<<<<<<<<<<--.+++.---.>>++.--<<++.>>>>.>>>>>>>>+<-]<[<
<<<<<<<<<--.>++.-->>--.++<.++.--<<++.>>>>.>>>>>>>+<-]<[<<<<<<<++.<<.+.
->>--.<<<+.->>>>>.>>>>>>+<-]<[<<<<<<+.-<<<++.--.>>++.-.-<<+.->>>>>.>>>
>>+<-]<[<<<<<<<--.+++.->>.+.+.-->>.>>>>+<-]<<<<<<<<+.---.>>>>++.>.<<<+
+.<--.>>>>.<<<<<++.>++.>>.<<+.>>+.+.<--.<<--.>>>-.>>.<<<.>>.>.<<+.--.>
----.<<<<++++.>>>>>.<<<-.+++.>>+.<<<<.>>>>>.<<<<--.<----.>>>>.<<<<++++
.>>>>>.<<++.<.>>>.<<<--.<<.>>>>>.<<<<<-->+>>-->+>>>>>>>>>>>>>>>>>>>>>>
>>>>>>[<<<<<<<<<<<<<<<<<<<<<<<<<<<<<++.>.<<<<++.>>-.>>-.<<<<.->>>>>.<<
<<<.>>>--.>-.<<+..<<+.>>>.+.>>.<<<<<-.->>>-.>.<<..<+.>+.-<--.+>>>++>.>
>>>>>>>>>>>>>>>>>>>>>>>>>>-]<[<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<++.>>-.<<
.>>>>-.+<<<<.>>++.>>>.<<--.<<+.>>.<<<.-->>>++.+.>>.<<---.<<.>>.++<<.>.
-<--.+>>>>.>>>>>>>>>>>>>>>>>>>>>>>>>>-]<[<<<<<<<<<<<<<<<<<<<<<<<<<<<++
.<<<++.>>+.>>>.<<<--.+++.>--.<<<-.>>>+.>>.<<<<<---.>>>>>.<<<---.<<++++
.----.++>>>---.++<<+.>++.-<--.+>>>>.>>>>>>>>>>>>>>>>>>>>>>>>>-]<[<<<<<
<<<<<<<<<<<<<<<<<<<<<<+.<+.>.<<++.>>>>>.<<<--.<<----.+++.>.<+.>>>+.->>
.<<<<<-.---.>>++.<<++.>.>.-<--.+>>>>.>>>>>>>>>>>>>>>>>>>>>>>>-]<[<<<<<
<<<<<<<<<<<<<<<<<<<<<<<++.>+.--.+.>>++.>>.<<<.<<----.>+.<+++.>>>-.->>.
<<<<<---.++>>>>>.<<<.<.>-.-.<.>+++.-<--.+>>>>.>>>>>>>>>>>>>>>>>>>>>>>-
]<[<<<<<<<<<<<<<<<<<<<<<<<<+.<<<++.>>>>-.<<<<.>>+.>>>.<<.>+.<<<<----.>
>.>.>>.<<<<<.++>>>>>.<<.->.<<<+.>-..<.>+.-<--.+>>>>.>>>>>>>>>>>>>>>>>>
>>>>-]<[<<<<<<<<<<<<<<<<<<<<<<<+.<<+.>>>+.>.<<<<--.<++..>>>.-<<<.>>>>>
.<<<<<----.>>>>>.<<<-.<<.++>>>>+.--<<<++.>++.-<--.+>>>>.>>>>>>>>>>>>>>
>>>>>>>-]<[<<<<<<<<<<<<<<<<<<<<<<<<--.+++.>>>-.+<<<<++.>>>>>.<<<<--.>+
+.---.<<-.+.-->>++.>>>.<<.<<++.>.-<--.+>>+.->>.>>>>>>>>>>>>>>>>>>>>-]<
[<<<<<<<<<<<<<<<<<<<<<<<--.>++.>>--.++<.>>.<<<<<.--.>>---..<+++.>++.-<
--.>>>>.<<<<<+.>++.->>.<<<++.->>>+.->>.>>>>>>>>>>>>>>>>>>>-]<[<<<<<<<<
<<<<<<<<<<<<++.<<.>>--.<<<++..>>>>>.<<<<--.>>.<<<.>>+.<<--.>++.>>>>.<<
<<.<++.-->>.->+.->>.>>>>>>>>>>>>>>>>>>-]<[<<<<<<<<<<<<<<<<<<<++.>.<<++
.>>>.<<.>--.<--.++.<---.<<++.>>>>>.<<<<<-.>>+++.>>+.<<<<+.>>>-.>>.<<<<
<----.>>-.-<<+++.->>>->+>.>>>>>>>>>>>>>>>>>-]<[<<<<<<<<<<<<<<<<<<<<<--
.>>>>>.<<--.<<<.>>>++.++.--.<<+.<+++.>--.<+.>>>>>.<<<<++.>+.>>>.<<<<<-
---.>>>>>.<<<++.<<++++.----.>>>.>>.<<++.--.<<<++++..>>>>>.<<<<<-->->--
->>>>>>>>>>>>>>>>>>>-]<<<<<<<<<<<<<<<<<<<<<<..>>>>>>>->+[>+>>>>>>>>>>>
>>[>]+[<]<<<<<<<<<<<<<-]>[<+>-]<<]

불행히도 이것은 자체 출력보다 약 600 자 더 길지만 무엇이든간에. c, h, m, r, w 문자를 배열로 유지하고이를 사용하여 모든 텍스트를 인쇄합니다. 12 개의 공간 오른쪽에있는 2 개의 배열은 각각 우리가 계산할 날짜와 출력 할 수있는 항목을 추적합니다. 나는 같은 긴 사슬 피하기 위해 두 계수 배열 사이에 인쇄 문자를 가지고 메모리 맵을 재구성하여 조금을 최적화 할 수 있습니다 <<<<<<<>>>>>>있지만,이 시점에서 많은 작업이 될 것입니다. 또한 주파수 분석을 통해 증분 / 감소를 최소화하기 위해 더 나은 시드 문자를 선택할 수도 있습니다.

이것은 제대로 작동하기 위해 8 비트 랩핑 셀에 의존합니다.

언 골프 드 :

>--[<->+++++]<---

[>+>+>+>+>+<<<<<-]++++++++++
>>[+++++>]<<<[+++++>]<<[+++++>]<+++++>>
++++[<++++++++>-]
++++++++++++>+>+>>>>>>>>>>>>>+<<<<<<<<<<<<<<<
[ 
   <<<<++o.-n.->>>.<<++t.--<<h.<++e.-->>>>>.    
   >>>>>>>>>>>>>>
   12[<<<<<<<<<<<<<<<<++t.>w.<<<<++e.-->>-l.+<--f.++>>t.--<<h.>>>>.>>>>>>>>>>>>>>-]
   11<[<<<<<<<<<<<<<<<<<<++e.>>-l.<<e.>>>>-v.+<<<<e.-->>++n.>++t.--<<h.>->>>.>>>>>>>>>>>>>>+<-]
   10<[<<<<<<<<<<<<<<++t.<<<++e.-->>+n.->t.--<<h.>>>>.>>>>>>>>>>>>>+<-]
   9<[<<<<<<<<<<<< <<+n.<+i.>n.->++t.--<<-h.>>>> . >>>>>>>>>>>>+<-]
   8<[<<<<<<<<<<< <<<<++e.-->+i.--g.+h.>>++t.--<<h.>>>> . >>>>>>>>>>>+<-]
   7<[<<<<<<<<<< <+s.<<<++e.>>>>-v.+<<<<e.-->>+n.->+t.--<<h.>>>> . >>>>>>>>>>+<-]
   6<[<<<<<<<<< <+s.<<+i.>>>+x.-<+t.--<<-h.>>>> . >>>>>>>>>+<-]
   5<[<<<<<<<< <<<--f.+++i.---f.>>++t.--<<++h.>>>>. >>>>>>>>+<-]
   4<[<<<<<<< <<<--f.>++o.-->>--u.++<r.++t.--<<++h.>>>> . >>>>>>>+<-]
   3<[<<<<<< <++t.<<h.+i.->>--r.<<<+d.->>>>>.>>>>>>+<-]
   2<[<<<<<<+s.-<<<++e.--c.>>++o.-n.-<<+d.->>>>>.>>>>>+<-]
   1<[<<<<<<<--f.+++i.->>r.+s.+t.-->>.>>>>+<-]
   <<<<<<<<+d.---a.>>>>++y.>_.<<<++o.<--f.>>>>_.<<<<<++c.>++h.>>r.<<+i.>>+s.+t.
   <--m.<<--a.>>>-s.>>_.<<<m.>>y.>_.<<+t.--r.>----u.<<<<++++e.>>>>>_.
   <<<-l.+++o.>>+v.<<<<e.>>>>>_.   
   <<<<--g.<----a.>>>>v.<<<<++++e.>>>>>.
   <<++t.<o.>>>.
   <<<--m.<<e.>>>>>.
   <<<<<-->+>>-->+
   >>>>>>>>>>>>>>>>>>>>>>>>>>>>
   12[<<<<<<<<<<<<<<<<<<<<<<<<<<<<<++t.>w.<<<<++e.>>-l.>>-v.<<<<e.->>>>>.
   <<<<<d.>>>--r.>-u.<<+m.m.<<+e.>>>r.+s.>>.<<<<<-d.->>>-r.>u.<<m.m.<+i.>+n.-<--g.+>>>++>.
   >>>>>>>>>>>>>>>>>>>>>>>>>>>-]
   11<[<<<<<<<<<<<<<<<<<<<<<<<<<<< <<<<++e.>>-l.<<e.>>>>-v.+<<<<e.>>++n.>>>.
   <<--p.<<+i.>>p.<<<e.-->>>++r.+s.>>.<<---p.<<i.>>p.++<<i.>n.-<--g.+>>>>.>>>>>>>>>>>>>>>>>>>>>>>>>>-]
   10<[<<<<<<<<<<<<<<<<<<<<<<<<<< <++t.<<<++e.>>+n.>>> .<<<--
   .+++o.>--r.<<<-d.>>>+s.>>.<<<<<---a.>>>>>.<<<---l.<<++++e.----a.++>>>---p.++<<+
   i.>++n.-<--g.+>>>> .    >>>>>>>>>>>>>>>>>>>>>>>>>-]
   9< [<<<<<<<<<<<<<<<<<<<<<<<<< <<+n.<+i.>n.<<++e.>>>>> .<<<--l.<<----a.+++d.>
   i.<+e.>>>+s.->> .<<<<<-d.---a.>>++n.<<++c.>i.>n.-<--g.+>>>> . >>>>>>>>>>>>>>>>>>>>>>>>-]
   8< [<<<<<<<<<<<<<<<<<<<<<<<< <<<<++e.>+i.--g.+h.>>++t.>> .<<<m.<<----a.>+
   i.<+++d.>>>-s.->> .<<<<<---a.++>>>>> .<<<m.<i.>-l.-k.<i.>+++n.-<--g.+>>>> . >>>>>>>>>>>>>>>>>>>>>>>-]
   7< [<<<<<<<<<<<<<<<<<<<<<<< <+s.<<<++e.>>>>-v.<<<<e.>>+n.>>> .<<s.>+w.<<<<
   ----a.>>n.>s.>> .<<<<<a.++>>>>> .<<s.->w.<<<+i.>-m.m.<i.>+n.-<--g.+>>>>.  >>>>>>>>>>>>>>>>>>>>>>-]
   6< [<<<<<<<<<<<<<<<<<<<<<< <+s.<<+i.>>>+x.> .<<<<--g.<++e.e.>>>s.-<<<e.>>>>> 
   .<<<<<----a.>>>>> .<<<-l.<<a.++>>>>+y.--<<<++i.>++n.-<--g.+>>>> .  >>>>>>>>>>>>>>>>>>>>>-]
   5< [<<<<<<<<<<<<<<<<<<<<< <<<--f.+++i.>>>-v.+<<<<++e.>>>>> .<<<<--g.>++o.---
   l.<<-d.+e.-->>++n.>>> .<<r.<<++i.>n.-<--g.+>>+s.->> .   >>>>>>>>>>>>>>>>>>>>-]
   4< [<<<<<<<<<<<<<<<<<<<< <<<--f.>++o.>>--u.++<r.>> .<<<<<c.--a.>>---l.l.<+++
   i.>++n.-<--g.>>>> .<<<<<+b.>++i.->>r.<<<++d.->>>+s.->> .  >>>>>>>>>>>>>>>>>>>-]
   3< [<<<<<<<<<<<<<<<<<<< <++t.<<h.>>--r.<<<++e.e.>>>>> .<<<<--f.>>r.<<<e.>>+
   n.<<--c.>++h.>>>> .<<<<h.<++e.-->>n.->+s.->> .    >>>>>>>>>>>>>>>>>>-]
   2< [<<<<<<<<<<<<<<<<<<<++t.>w.<<++o.>>>.<<t.>--u.<--r.++t.<---l.<<++e.>>>>>.
   <<<<<-d.>>+++0.>>+v.<<<<+e.>>>-s.>>.<<<<<----a.>>-n.-<<+++d.->>>->+>.
   >>>>>>>>>>>>>>>>>-] 
   1<[<<<<<<<<<<<<<<<<<<<<<--a.>>>>>.<<p--.<<<a.>>>++r.++t.--r.<<+i.<+++d.>--g.<+
   e.>>>>>.<<<<++i.>+n.>>>.<<<<<----a.>>>>>.<<<++p.<<++++e.----a.>>>r.>>.<<++
   t.--r.<<<++++e..>>>>>.<<<<<-->->--->>>>>>>>>>>>>>>>>>>-]
   <<<<<<<<<<<<<<<<<<<<<<..>>>>>>>->+
   [>+>>>>>>>>>>>>>[>]+[<]<<<<<<<<<<<<<-]>[<+>-]<<
]

1
나는 그 크기의 제출에 대한 인라인 의견을 용납합니다 (골프 점수에 포함되지 않음). 어쨌든 +1했습니다.
JB

확실한 것. ungolfed 버전을 추가했습니다. 일수의 경우 12 비트 중 1 비트 만 설정되고 출력 후 다음 일 비트가 설정됩니다. 항목의 경우 마지막 줄 옆에 n 비트를 높은 행으로 설정하고 모든 활성 get 출력을 설정합니다.
captncraig

10

펄, 438 291 자

Jeff Burdges의 DEFLATE compression 사용 , Ventero의 압축 Ruby 코드JB의 Lingua :: EN :: Numbers 사용에서 영감을 얻어 압축 해제 코드를 포함하여 291 자 (웰, 바이트)로 항목을 압축 할 수있었습니다. 프로그램에 인쇄 할 수없는 문자가 포함되어 있으므로 MIME Base64 형식으로 제공했습니다 .

dXNlIENvbXByZXNzOjpabGliO2V2YWwgdW5jb21wcmVzcyAneNolkMFqAkEMhu8+RVgELdaIXmXB
S2/FFyhF4k7cHTqTsclMZd++M3pJvo+QH5JiDJ9exkKrj/PqXOKV1bod77qj9b2UeGBZ7w/bpd9s
3rCDruf3uWtwS3qS/vfROy0xsho+oWbB3d+b19YsJHWGhIHp5eQ8GzqSoWkk/xxHH36a24OkuT38
K21kNm77ND81BceCWtlgoBAq4NWrM7gpyzDhxGKQi+bA6NIfG5K4/mg0d0kgTwwdvi67JHVeKKyX
l3acoxnSDYZJveVIBnGGrIUh1BQYqZacIDKc5Gvpt1vEk3wT3EmzejcyeIGqTApZmRftR7BH3B8W
/5Aze7In

프로그램의 인코딩을 해제하려면 다음 도우미 Perl 스크립트를 사용할 수 있습니다.

use MIME::Base64;
print decode_base64 $_ while <>;

이름이 지정된 파일에 출력을 저장 12days.pl하고로 실행하십시오 perl -M5.01 12days.pl. 언급 한대로 코드가 작동 하려면 Lingua :: EN :: Numbers 모듈이 설치되어 있어야합니다.

궁금한 점이 있다면 코드에서 읽을 수있는 부분은 다음과 같습니다.

use Compress::Zlib;eval uncompress '...'

여기서 ...254 바이트의 RFC 1950 압축 Perl 코드를 나타냅니다. 압축되지 않은 코드의 길이는 361 자이며 다음과 같습니다.

use Lingua'EN'Numbers"/e/";s==num2en(12-$i++)." "=e,y"." "for@n=qw=drummers.drumming pipers.piping lords.a.leaping ladies.dancing maids.a.milking swans.a.swimming geese.a.laying golden.rings calling.birds french.hens turtle.doves.and=;say"on the ".num2en_ordinal($_)." day of christmas my true love gave to me @n[$i--..@n]a partridge in a pear tree
"for 1..12

이 코드를 작성하는 것은 이상한 종류의 골프 연습이었습니다. 그것은 반복을 최대화하고 사용 된 고유 문자 수를 최소화하는 것이 관련 메트릭이 압축 후 크기 일 때 원시 문자 수를 최소화하는 것보다 훨씬 중요하다는 것을 알 수 있습니다.

마지막 몇 문자를 짜기 위해이 코드의 작은 변형을 시도하여 가장 압축되는 코드를 찾는 간단한 프로그램을 작성했습니다. 압축을 위해 Ken Silverman의 KZIP 유틸리티를 사용했는데, 이는 최대 압축 설정에서도 표준 Zlib보다 더 나은 압축 비율 (속도 비용)을 산출합니다. 물론 KZIP는 ZIP 아카이브 만 생성하므로 아카이브에서 원시 DEFLATE 스트림을 추출하여 RFC 1950 헤더 및 체크섬으로 래핑해야했습니다. 내가 사용한 코드는 다음과 같습니다.

use Compress::Zlib;
use 5.010;

@c = qw(e i n s);
@q = qw( " );
@p = qw( = @ ; , );
@n = ('\n',"\n");

$best = 999;

for$A(qw(e n .)){ for$B(@q){ for$C(@q,@p){ for$D(@p){ for$E(@q,@p){ for$F(qw(- _ . N E)){ for$G("-","-"eq$F?():$F){ for$H(@c){ for$I(@c,@p){ for$N(@n){ for$X(11,"\@$I"){ for$Y('$"','" "',$F=~/\w/?$F:()){ for$Z('".num2en_ordinal($_)."'){
    $M="Lingua'EN'Numbers";
    $code = q!use MB/A/B;sDDnum2en(12-$H++).YDe,yCFC Cfor@I=qwEdrummersFdrumming pipersFpiping lordsGaGleaping ladiesFdancing maidsGaGmilking swansGaGswimming geeseGaGlaying goldenFrings callingFbirds frenchFhens turtleFdovesFandE;say"on the Z day of christmas my true love gave to me @I[$H--..X]a partridge in a pear treeN"for 1..12!.$/;
    $code =~ s/[A-Z]/${$&}/g;

    open PL, ">12days.pl" and print PL $code and close PL or die $!;
    $output = `kzipmix-20091108-linux/kzip -b0 -y 12days.pl.zip 12days.pl`;
    ($len) = ($output =~ /KSflating\s+(\d\d\d)/) or die $output;

    open ZIP, "<12days.pl.zip" and $zip = join("", <ZIP>) and close ZIP or die $!;
    ($dfl) = ($zip =~ /12days\.pl(.{$len})/s) or die "Z $len: $code";

    $dfl = "x\xDA$dfl" . pack N, adler32($code);
    $dfl =~ s/\\(?=[\\'])|'/\\$&/g;

    next if $best <= length $dfl;
    $best = length $dfl;
    $bestcode = $code;
    warn "$A$B$C$D$E$F$G$H$I $X $Y $best: $bestcode\n";

    open PL, ">12days_best.pl" and print PL "use Compress::Zlib;eval uncompress '$dfl'" and close PL or die $!;

}}}}}}
    print STDERR "$A$B$C$D$E$F\r";
}}}}}}}

이것이 끔찍한 kluge처럼 보인다면, 그것이 바로 그것이 기 때문입니다.


역사적 관심을 끌기 위해 줄 바꿈과 문장 부호를 포함하여 더 나은 출력을 생성하는 원래의 438 문자 솔루션이 있습니다.

y/_/ /,s/G/ing/for@l=qw(twelve_drummers_drummG eleven_pipers_pipG ten_lords-a-leapG nine_ladies_dancG eight_maids-a-milkG seven_swans-a-swimmG six_geese-a-layG five_golden_rGs four_callG_birds three_french_hens two_turtle_doves);s/e?t? .*/th/,s/vt/ft/for@n=@l;@n[9..11]=qw(third second first);say map("\u$_,\n","\nOn the $n[11-$_] day of Christmas,\nMy true love gave to me",@l[-$_..-1]),$_?"And a":A," partridge in a pear tree."for 0..11

이 버전의 주요 특징은 정규 표현식 쌍 s/e?t? .*/th/,s/vt/ft/으로, 선물 행의 시작 부분에서 추기경에서 4-12의 서수를 구성합니다.

물론이 코드는 위에서 설명한 Zlib 트릭을 사용하여 압축 할 수도 있지만 단순히 출력을 압축하는 것이 더 효율적이며 다음 338 바이트 프로그램 (Base64 형식)이 생성됩니다.

dXNlIENvbXByZXNzOjpabGliO3NheSB1bmNvbXByZXNzICd42uWTwU7DMAyG730KP8DGOyA0bsCB
vYBp3MYicSo7W9e3xx3ijCIQDHZIUjn683+/k3ZPAjUSDKxWIeACZYC7qGw1o226hwWqHghSORKM
6FMtkGnT3cKEWpXDSMACCBOhQlWim+7jUKO+SGg5dT8XqAetiSD4nrmPBMDPvXywtllF18OgJH2E
SGJfcR+Ky2KL/b0roMeUWEZ4cXb7biQeGol4LZQUSECdyn4A0vjUBvnMXCcYiYy2uE24ONcvgdOR
pBF9lYDNKObwNnPOTnc5kYjH2JZotyogI4c1Ueb06myXH1S48eYeWbyKgclcJr2D/dnwtfXZ7km8
qOeUiXBysP/VEUrt//LurIGJXCdSWxeHu4JW1ZnS0Ph8XOKloIecSe39w/murYdvbRU+Qyc=

또한 동일한 DEFLATE 스트림으로 구성된 가사의 312 바이트 gzip 아카이브가 있습니다. "zcat 스크립트"라고 부를 수 있다고 생각합니다. :)


당신 같은 외모는 대체 할 수 ringsrGs할인율이 개 문자
macek

@macek : 내 원래 버전 내가 대체했기 때문에 내가 할 수 없었다에서 G함께 ing,하지만 쉼표를 추가하면 나중에 참으로 짧은 것으로 나타났다. 감사!
Ilmari Karonen

'읽기 전용 값 수정'오류를 어떻게 피합니까?
Jeff Burdges

@ JeffBurdges : 원래 버전에서? 문자열을 먼저 배열에 할당합니다.
Ilmari Karonen

"읽기 전용 값의 수정은 /opt/local/lib/perl5/5.12.3/Compress/Zlib.pm 357 행에서 시도되었습니다." $_아래 업데이트에서 에 할당 하여이 문제를 피했습니다 .
Jeff Burdges

10

커먼 리스프, 333 363

(dotimes(n 12)(format t"on-the-~:R-day-of-christmas
my-true-love-gave-to-me
~v*~@{~R-~A
~#[and-~]~}a-PARTRIDGE-IN-A-PEAR-TREE

"(1+ n)(- 22 n n)12'drummers-drumming 11'pipers-piping 10'lords-a-leaping 9'ladies-dancing 8'maids-a-milking 7'swans-a-swimming 6'geese-a-laying 5'golden-rings 4'calling-birds 3'french-hens 2'turtle-doves))

서수 형식을 지정하는 기본 제공 기능이 도움이되지만 대부분의 압축은 동일한 인수 목록을 반복해서 사용하여 각 실행에서 더 적은 수의 인수를 건너 뛰어 나옵니다.

의견에서 코어 덤프 에 의해 입증 된 바와 같이 , 내장 시설은 여전히 ​​카디널을 잘 활용할 수 있습니다.


라인이 "12", "11", "ten", ...으로 시작하면 약간 더 압축 할 수 있습니다.
coredump

아마 그렇습니다. 당신의 제안은 무엇입니까?
JB

1
나는 먼저 나머지 수의 인수가 사용될 수 있기를 희망했지만 사양을 읽었으며 그것을 할 수 없습니다. 내가 가진 반바지는 333 자입니다 :(dotimes(n 12)(format t"on-the-~:R-day-of-christmas my-true-love-gave-to-me ~v*~@{~R-~A ~#[AND-~]~}A-PARTRIDGE-IN-A-PEAR-TREE "(1+ n)(- 22 n n)12'drummers-drumming 11'pipers-piping 10'lords-a-leaping 9'ladies-dancing 8'maids-a-milking 7'swans-a-swimming 6'geese-a-laying 5'golden-rings 4'calling-birds 3'french-hens 2'turtle-doves))
coredump

이제 이야기하고 있습니다. 내 꿈은 스킵 카운터를 서수와 공유하는 것이었지만, 그렇게 할 수있는 짧은 방법을 찾지 못했습니다.
JB

7

자바 스크립트 570

이것은 내 첫 골프입니다. 자바 스크립트 570

var l=["first","second","third","fourth","fifth","sixth","seventh","eigth","nineth","tenth","eleventh","twelth","Two turtle doves","Three french hens","Four calling birds","Five golden rings","Six geese-a-laying","Seven swans-a-swimming","Eight maids-a-milking","Nine ladies dancing","Ten lords-a-leaping","Eleven pipers piping","Twelve drummers drumming"];var b = "<br/>";for(var i=0;i<12;i++){var p="On the "+l[i]+"day of Christmas"+b+"My true love gave to me"+b;for(var x=i;x>0;x--)p+=l[13+x]+b;if(i>0)p+="and ";p+="a partridge in a pear tree"+b+b;document.write(p);}

6

파이썬 2.7 (465)

for k in range(12):
 print'On the %s day of Christmas\nMy true love gave to me'%'first^second^third^fourth^fifth^sixth^seventh^eighth^ninth^tenth^eleventh^twelfth'.split('^')[k]
 print'\n'.join('Twelve drummers drumm*Eleven pipers pip*Ten lords-a-leap*Nine ladies danc*Eight maids-a-milk*Seven swans-a-swimm*Six geese-a-lay*Five golden rings^Four calling birds^Three french hens^Two turtle doves and^a partridge in a pear tree^'.replace('*','ing^').split('^')[11-k:])

그러나 'and'를 파트 리지 대신 비둘기와 같은 줄에 배치했습니다.


1
당신은 나와 같은 철자 실수를했습니다 : 그것은 "12 번째"
Andrew Shepherd

글쎄, 그러면 저에게 또 다른 캐릭터를 구할 수 있습니다 ... 감사합니다!
Daan

5

루비 (474)

(0..11).each{|i|puts "On the #{"first^second^third^fourth^fifth^sixth^seventh^eighth^ninth^tenth^eleventh^twelfth".split("^")[i]} day of Christmas\nMy true love gave to me";puts "a partridge in a pear tree\n\n^two turtle doves and^three french hens^four calling birds^five golden rings^six geese-a-lay*Seven swans-a-swimm*Eight maids-a-milk*Nine ladies danc*Ten lords-a-leap*Eleven pipers pip*Twelve drummers drumming".gsub('*','ing^').split('^')[0..i].reverse.join("\n")}

또는 더 읽기 쉬운 형태 (486) :

(0..11).each do |i|
    puts "On the #{"first^second^third^fourth^fifth^sixth^seventh^eighth^ninth^tenth^eleventh^twelfth".split("^")[i]} day of Christmas\nMy true love gave to me"
    puts "a partridge in a pear tree\n\n^two turtle doves and^three french hens^four calling birds^five golden rings^six geese-a-lay*Seven swans-a-swimm*Eight maids-a-milk*Nine ladies danc*Ten lords-a-leap*Eleven pipers pip*Twelve drummers drumming".gsub('*','ing^').split('^')[0..i].reverse.join("\n")
end

누구든지 .reverse를 우회하는 방법을 알고 있습니까? 나는 해결책을 찾지 못했습니다.


"ing"을 나타내는 *로 트릭을 좋아합니다. 당신은에 의해 (440)에 대해 그것을 아래로 얻을 수 있어야합니다 : 사용 12.times하는 대신 (0..11).each, 하나의 인수로 두 개의 풋 대신 두 개의 인수로 한 풋을 수행하십시오. 크리스마스 일 배열에 % w () 표기법을 사용하십시오. 마지막으로, 목록을 반대로 바꾸고 문자열 끝에 ^를 추가 한 다음 [-i..-1][0..i] 대신 사용하여 역순을 제거 할 수 있습니다 .
Wayne Conrad

"drumming"을 "drumm *"로 변경할 수 없습니까?
undergroundmonorail

5

500 485

@s=(first,second,third,fourth,fifth,sixth,seventh,eighth,ninth,tenth,eleventh,twelfth);
$;=ing;
@a=(
"Twelve drummers drumm$;",
"Eleven pipers pip$;",
"Ten lords-a-leap$;",
"Nine ladies danc$;",
"Eight maids-a-milk$;",
"Seven swans-a-swimm$;",
"Six geese-a-lay$;",
"Five golden r$;s",
"Four call$; birds",
"Three french hens",
"Two turtle doves\nAnd "
);
for(0..11){
print"\n\nOn the $s[$_] day of Christmas\nMy true love gave to me\n";
$"=$/;
print"@b";
unshift@b,pop@a;
print"A partridge in a pear tree"
}

이것은 나의 첫 번째 시도이며 훨씬 짧아 질 수 있다고 확신합니다. 줄 바꿈은 가독성을위한 것입니다. 여기에는 세 개의 중요한 배열이 있는데, 그중 하나는 매일 이름을 가지고 있으며 @s, 그중 하나는 모든 선물을 나열하고 (첫 번째는 제외) @a, 다른 선물은 이미 주어진 선물을 나열합니다 @b. 주요 메커니즘은 매일 매일 @b추가 선물을 인쇄 하여에서로 전송 @a하는 것 @b입니다.

500-> 485의 Andrew에게 감사합니다.


당신은 대체 할 수 ringsr$1s1 더 많은 문자 저장
macek

@macek 나는 perl이 s변수 이름의 일부로 해석 하고 변수 $is가 존재하지 않기 때문에 그렇게 할 수 없습니다 . (실제로 그들은 나 대신 사람입니다, btw)
PhiNotPi

eigth->eighth
Matthew 읽기

$i예를 들어, 그 문제 $;를 해결하기 위해 바꿀 수 있습니다. $;어쨌든 아무도 의도 된 목적 으로 사용하지 않습니다 .
Ilmari Karonen

@IlmariKaronen 나는 조언을했지만 오타를 수정하여 문자 수는 동일하게 유지되었습니다.
PhiNotPi

5

Vim – 578 키 입력

나는 이것을 vim-golf하기로 결정했다. 이것은 vim-golfed 할 수있는 종류이기 때문이다.

"크리스마스의 X 일"라인을 총 12 회 프레임 워크 (89 개의 키 입력)로 삽입합니다.

                                         KS   TL   GT
12iOn the X day of Christmas,<Enter>     30   30   30
my true love gave to me,<Enter>          25   55   55
and a partridge in a pear tree.<Enter>   32   87   87
<Enter><Esc>                              2   89   89

그런 다음 가사에 필요한 각 위치에 2에서 12까지의 숫자를 삽입하는 일련의 매크로를 수행하십시오 (172 개의 키 입력).

                                      KS   TL   GT
42kqmO2<Esc>9/a<Enter>q10@m           17   17  106
dw                                     2   19  108
6jqm/2<Enter>O3<Esc>jq9@m             14   33  122
/3<Enter>qm/3<Enter>O4<Esc>jq8@m      16   49  138
/4<Enter>qm/4<Enter>O5<Esc>jq7@m      16   65  154
/5<Enter>qm/5<Enter>O6<Esc>jq6@m      16   81  170
/6<Enter>qm/6<Enter>O7<Esc>jq5@m      16   97  186
/7<Enter>qm/7<Enter>O8<Esc>jq4@m      16  113  202
/8<Enter>qm/8<Enter>O9<Esc>jq3@m      16  129  218
/9<Enter>qm/9<Enter>O10<Esc>jq2@m     17  146  235
/10<Enter>qm/10<Enter>O11<Esc>jq@m    18  164  253
?11<Enter>O12<Esc>                     8  172  261

두 번째 줄의 "dw"는 첫 번째 "and"를 제거하는 것입니다. 왜냐하면 그곳에 가지 않기 때문입니다.

그런 다음, 참사랑이 준 수 (319 건)에 대한 일련의 대체를 수행하십시오.

                                       KS   TL   GT
:%s/12/twelve drummers drumming,/g     34   34  295
:%s/11/eleven pipers piping,/g         30   64  325
:%s/10/ten lords-a-leaping,/g          29   93  354
:%s/9/nine ladies dancing,/g           28  117  382
:%s/8/eight maids-a-milking,/g         30  147  412
:%s/7/seven swans-a-swimming,/g        31  178  443
:%s/6/six geese-a-laying,/g            27  205  366
:%s/5/five golden rings,/g             26  231  392
:%s/4/four calling birds,/g            27  268  419
:%s/3/three french hens,/g             26  294  445
:%s/2/two turtle doves,/g              25  319  470

마지막으로 각 항목을 X서수로 바꿉니다 .

                         KS   TL   GT
/X<Enter>sfirst<Esc>     10   10  480
nssecond<Esc>             9   18  488
nsthird<Esc>              8   27  497
nsfourth<Esc>             9   36  506
nsfifth<Esc>              8   44  514
nssixth<Esc>              8   52  522
nsseventh<Esc>           10   62  532
nseighth<Esc>             9   71  541
nsninth<Esc>              8   79  549
nstenth<Esc>              8   87  557
nseleventh<Esc>          11   98  568
nstwelfth<Esc>           10  108  578

그리고 우리는 끝났습니다!


내가 놓친 다른 최적화가 있다고 확신하지만 그 자체로는 꽤 좋습니다.


어, 나는 탈출을 잊었다.
Joe Z.

:이처럼 대체와 함께 / g를 생략 할 수 있습니다:%s/2/two turtle doves,
therealfarfetchd

4

C (644)

개수에는 프리젠 테이션에 사용 된 공백이 포함되지 않습니다.

#include <stdio.h>

void main() {
    char *e = "On the \0 day of Christmas my true love gave to me\0 Twelve drummers drumming Eleven pipers piping Ten lords-a-leaping Nine ladies dancing Eight maids-a-milking Seven swans-a-swimming Six geese-a-laying Five golden rings Four calling birds Three french hens Two turtle doves and A partridge in a pear tree\n\n";
    printf("%sfirst%s%s%ssecond%s%s%sthird%s%s%sfourth%s%s%sfifth%s%s%ssixth%s%s%sseventh%s%s%seighth%s%s%sninth%s%s%stenth%s%s%seleventh%s%s%stwelfth%s%s",
           e, e+8, e+276, e, e+8, e+255, e, e+8, e+237, e, e+8, e+218, e, e+8, e+200, e, e+8, e+181, e, e+8, e+158, e, e+8, e+136, e, e+8, e+116, e, e+8, e+96, e, e+8, e+75, e, e+8, e+50);
}

출력은 다음과 같습니다

On the first day of Christmas my true love gave to me A partridge in a pear tree

...

On the twelfth day of Christmas my true love gave to me Twelve drummers drumming Eleven pipers piping Ten lords-a-leaping Nine ladies dancing Eight maids-a-milking Seven swans-a-swimming Six geese-a-laying Five golden rings Four calling birds Three french hens Two turtle doves and A partridge in a pear tree

4

파워 쉘, 487 453

0..11 | % {
   'On the {0} day of christmas my true love gave to me {1}`n'-f
   (
        'first^second^third^fourth^fifth^sixth^seventh^eighth^ninth^tenth^eleventh^twelfth'.Split('^')[$_],
        (
            'a partridge in a pear tree^two turtle doves and^three french hens^four calling birds^five golden rings^six geese-a-laying^Seven swans-a-swimming^Eight maids-a-milking^Nine ladies dancing^Ten lords-a-leaping^Eleven pipers piping^Twelve drummers drumming'.Split('^')[$_..0]-join' '
        )
    )
 }

감사합니다 연결된 문자열을 분할하는 아이디어에 대해 Daan 에게 합니다.

나는 원래 첫 구절을 제외한 모든 부분에 대해 "및"을 얻기 위해 전환 문을 포함시켰다. 그러나이 질문은 구두점을 해결하기 때문에 비둘기에 "and"를 붙이면됩니다.

결과는 다음과 같이 줄 바꿈됩니다.

On the first day of christmas my true love gave to me a partridge in a pear tree

On the second day of christmas my true love gave to me two turtle doves and a partridge in a pear tree

On the third day of christmas my true love gave to me three french hens two turtle doves and a partridge in a pear tree

열두 번째가 아닌 열두 번째입니다.
Joey Adams

@Joey Adams-저를 고쳐 줘서 고맙습니다 :-)
Andrew Shepherd

4

Perl, 368 389 (유니 코드 / 압축 없음)

use Lingua::EN::Numbers"/n/";@s=qw(A-partridge-in-a-pear-tree turtle-doves french-hens calling-birds golden-rings geese-a-laying swans-a-swimming maids-a-milking ladies-dancing lords-a-leaping pipers-piping drummers-drumming);$_=$s[0];for$m(1..12){$n=num2en_ordinal$m;say"On the $n day of christmas
my true love gave to me
$_
";s/A/and a/;$_=num2en($m+1)." $s[$m]
$_"}

하네스 링구아 :: EN :: 숫자 , 나는 100 %거야하지만 내가 모듈과 식별자 이름 '길이를 볼 때 좋은 아이디어이다 설득했다. Perl 5.10 이상이 필요하면 -E스위치 를 사용하여 명령 행에서 실행하십시오 .

편집 : 사소한 개선 : 배열 사용을 중지 $_하고 불필요한 공백을 더 잘 사용하십시오 .


+1, 쿨! 누군가 비표준 모듈을 사용하는 것에 대해 불평 할 수 있지만, GolfScript와 같은 특수 목적 언어를 포함하여 어떤 언어를 사용하도록 허용하면 왜 "Perl + Lingua :: EN :: Numbers"가 표시되지 않을까요? 솔루션에 유효한 언어가 아닙니다. "Acme :: 12Days"모듈을 작성하여 CPAN에 제출하는 것은 속임수 일 것입니다. :)
Ilmari Karonen

사람들이 불평 할 때 @Ilmari Karonen은 보통 "CPAN"으로 언어 이름을 바꿉니다. 자주 발생하지 않습니다.
JB

2
Ilmari, Golfscript는 특수 목적 언어가 아닙니다.
Joey

2
"우연히 일반적인"언어와 비슷합니다. : D
JB

1
친애하는 주님, 왜 사람들이 더 이상 자신의 코드를 골프로 칠 수 없습니까?
JB

4

PowerShell, 440

-join('On the 1 day of Christmas
my true love gave to me
1a partridge in a pear tree

1first1second1third1fourth1fifth1sixth1seventh1eighth1ninth1tenth1eleventh1twelfth1Twelve drummers drumm7Eleven pipers pip7Ten lords-a-leap7Nine ladies danc7Eight maids-a-milk7Seven swans-a-swimm7Six geese-a-lay7Five golden rings
1Four calling birds
1Three french hens
1Two turtle doves
And '-replace7,'ing
1'-split1)[(26..15|%{0
29-$_
1
$_..26-le25
2})]

이것은 질문에 주어진 가사를 한 절에 여러 줄로 인쇄합니다. 해당 요구 사항이 없으면 몇 개의 문자를 저장할 수 있습니다.


홀리 크랩 +1 마지막 줄에는 "And"뿐만 아니라 줄 바꿈을 사용하여이 작업을 수행했습니다.
앤드류 셰퍼드

글쎄, 다른 텍스트를 인쇄하는 것은 결코 옵션이 아니며 마지막 줄의 "And"는 다른 모든 사람들과 같은 트릭을 사용합니다. 아직도, 나는 다른 솔루션이하지 않는 줄 바꿈을 유지하고 싶었습니다 (더 길지만).
Joey

3

C # (528)

class P{static void Main(){for(int i=1;i<12;i++){Console.WriteLine("On the "+"^first^second^third^fourth^fifth^sixth^seventh^eighth^ninth^tenth^eleventh^twelfth".Split('^')[i]+" day of christmas my true love gave to me "+"a partridge in a pear tree^two turtle doves and^three french hens^four calling birds^five golden rings^six geese-a-laying^Seven swans-a-swimming^Eight maids-a-milking^Nine ladies dancing^Ten lords-a-leaping^Eleven pipers piping^Twelve drummers drumming".Split('^').Take(i).Aggregate("",(t,s)=>s+' '+t));}}}

2

자바, 2062

나는 이것이 얼마 전에 게시되었음을 알고 있지만 시도 할 것이라고 생각했습니다. 나는 학생이며 여전히 이것에 익숙하지 않지만 작동하는 것 같습니다.

public class TwelveDaysOfChristmas 
{

    public static void main(String[] args) 
    {
        String[] days = new String[12];
        days[0] = "and a partriage in a pear tree.";
        days[1] = "Two turtle doves, ";
        days[2] = "Three french hens, ";
        days[3] = "Four callings birds, ";
        days[4] = "Five diamond rings, ";
        days[5] = "Six geese a-laying, ";
        days[6] = "Seven swans a-swimming, ";
        days[7] = "Eight maids a-milking, ";
        days[8] = "Nine ladies dancing, ";
        days[9] = "Ten lords a-leaping, ";
        days[10] = "Eleven pipers piping, ";
        days[11] = "Twelve twelve drummers drumming, ";


        System.out.println(chorus(0));
        System.out.println("a partriage in a pear tree");

        for(int i = 1; i<days.length; i++)
        {
            System.out.println(chorus(i));

            for(int x = i; x>=0; x--)
            {
                System.out.println(days[x]);
            }
            System.out.println();
        }
    }

    public static String chorus(int line)
    {
        String chorus = "On the " + getLine(line) + " day of Christmas my true " +
                "love gave to me, ";

        return chorus;
    }

    public static String getLine(int line)
    {
        int num = line;
        String result = "first";
        switch (num)
        {
        case 1:  result = "second";
                 break;
        case 2:  result = "third";
                 break;
        case 3:  result = "fourth";
                 break;
        case 4:  result = "fifth";
                 break;
        case 5:  result = "sixth";
                 break;
        case 6:  result = "seventh";
                 break;
        case 7:  result = "eighth";
                 break;
        case 8:  result = "ninth";
                 break;
        case 9: result = "tenth";
                 break;
        case 10: result = "eleventh";
                 break;
        case 11: result = "twelfth";
                 break;
        }

        return result;
    }

}

안녕하세요지나, 사이트에 오신 것을 환영합니다!
Tynam

3
첫 번째 솔루션을 축하합니다. 잘 작동합니다. 코드 골프와의 경연 대회는 '가장 짧은 코드'이므로이 사이트에서는 표준 코드에서 절대로하지 말아야 할 몇 가지 작업을 수행하는 것이 표준입니다. (여기서 접근 방식을보다 명확하게하기 위해 여기에서 한 것처럼 전체 길이 버전도 포함시키는 것이 좋습니다.) 그런 다음, "어떻게 더 짧게 만들 수 있습니까?"
Tynam

2

스위프트, 577

import UIKit
let f=NSNumberFormatter()
f.numberStyle = .SpellOutStyle
for i in 0...11{
let w = split("first-second-third-four-fif-six-seven-eigh-nin-ten-eleven-twelf"){$0=="-"}[i]+(i<3 ?"":"th")
println("On the \(w) day of Christmas\nmy true love gave to me")
for m in reverse(0...i){
if m==0{break}
let v = split("turtle doves and*french hens*calling birds*golden rings*geese-a-lay*swans-a-swimm*maids-a-milk*ladies danc*lords-a-leap*pipers pip*drummers drumm"){$0=="*"}[m-1]+(m<5 ?"":"ing")
println("\(f.stringFromNumber(m+1)!) \(v)")}
println("a partridge in a pear tree.")}

이것을 운동장에 붙여 넣을 수 있습니다.

v인쇄 명령으로 이동하려고 시도했지만 다음 을 얻었습니다.

Playground execution failed: <EXPR>:20:1: error: expression was too complex to be solved in reasonable time; consider breaking up the expression into distinct sub-expressions

1

Ruby 1.9.3, 압축, 321 자

코드에는 인쇄 할 수없는 문자가 포함되어 있으므로 코드의 16 진수 덤프를 대신 게시합니다.

0000000: 2363 6f64 696e 673a 6269 6e61 7279 0a72  #coding:binary.r
0000010: 6571 7569 7265 277a 6c69 6227 3b65 7661  equire'zlib';eva
0000020: 6c20 5a6c 6962 2e69 6e66 6c61 7465 2778  l Zlib.inflate'x
0000030: da2d 90db 6ac3 300c 86ef f714 a163 b042  .-..j.0......c.B
0000040: 15e8 5ea7 f442 8be5 58cc 8720 39cd 42db  ..^..B..X.. 9.B.
0000050: 3dfb e4a4 3792 f559 c7ff fcd5 574e a4f7  =...7..Y....WN..
0000060: 073f a6b9 eaa1 64a8 81e0 fdfe b17c 7a16  .?....d......|z.
0000070: ad9d d250 b2eb 6a60 719d 2fb3 d4d0 79f6  ...P..j`q./...y.
0000080: 6695 7f9b a51b 65f3 c463 3097 b905 7547  f.....e..c0...uG
0000090: f1f5 5717 8a56 71bc f0f5 090e 5728 1e86  ..W..Vq.....W(..
00000a0: 20ac 35a1 bea5 15aa cc04 b1dc 0846 3453   .5..........F4S
00000b0: 0b24 3a9c 6c87 5669 c0c9 9c12 89ee 0fce  .$:.l.Vi........
00000c0: e3ab 374c 3c35 6cae 411b 6b5d c429 2044  ..7L<5l.A.k].) D
00000d0: c28d d942 d61a 1d93 5563 1eb6 e2b6 2b24  ...B....Uc....+$
00000e0: e42d 3371 fc69 74bb 0474 c1dc a82e bc4f  .-3q.it..t.....O
00000f0: b233 6124 526a 4d71 6dc8 73db b444 67f9  .3a$RjMqm.s..Dg.
0000100: 6240 3761 60c0 182d 826f 934a 4d31 2102  b@7a`..-.o.JM1!.
0000110: 2f94 8700 81b2 91a5 4035 01a3 1d64 b7da  /.......@5...d..
0000120: 1413 1661 42a9 c26e 24e0 6c33 2642 3141  ...aB..n$.l3&B1A
0000130: 888e 973f ee7b 385f 4fd3 f31f be35 9d6f  ...?.{8_O....5.o
0000140: 27                                       '

16 진 덤프에서 실제 코드를 작성하려면 파일에 넣고 실행하십시오 xxd -r hexdump > 12days.rb. 그런 다음 실행 ruby1.9.3 12.days.rb하면 코드가 실행되고 가사가 인쇄됩니다. 이 코드는 Ruby 1.9.3을 필요로합니다.Zlib.inflate 하므로 Ruby 1.8.x, 1.9.1 및 1.9.2에서는 작동하지 않습니다.

압축되지 않은 코드의 길이는 425 자입니다.

12.times{|i|puts"on-the-#{%w(first second third fourth fifth sixth seventh eighth ninth tenth eleventh twelfth)[i]}-day-of-christmas
my-true-love-gave-to-me",%w(twelve-drummers-drumming eleven-pipers-piping ten-lords-a-leaping nine-ladies-dancing eight-maids-a-milking seven-swans-a-swimming six-geese-a-laying five-golden-rings four-calling-birds three-french-hens two-turtle-doves-and a-partridge-in-a-pear-tree)[~i..-1],p}

1

펄, 319/313

아이디어 : JB의 Lingua :: EN :: Numbers 솔루션을 압축 해제하고 평가하십시오.

먼저이 텍스트 블록을 명령에 붙여 넣습니다 perl -e 'use MIME::Base64; print decode_base64 $_ while <>;' >12days.pl. 그런 다음 명령을 실행하십시오 perl -M5.01 12days.pl.

dXNlIENvbXByZXNzOjpabGliOyRfPSd4nCWOwW7CMAyG730K
q8oBNIUOjq2QxmG3iT3AhJBpTBsRu12cgqpp776UXWx/v63/96QEH166Cev6/VjXx4kvFLWspCqb
N91/P1YHO2JM0buOrBeLdiSMNkUiSFNMgawb7qRwjSRtb3sShRZDyK724qNT6IbgSGzMSgYipewS
cM4M+kDRjPrwzIvA6N0isA+3hQM6T2odSvvEIT7XgXBcePRj/tfmtpCLE/PCzyEr68ac90a/Xk/N
dYiGV9vNZrtb/xjZy8Q7knP284LBcKM4l58CqVwnMAIOZxiu0PbRa2LUgmdIcaL8wZ2gw1zSAEyF
ORdlo9WhQnGA1RL4b70y/LJdb0rI+YZP+bD8Lf4A5ut+sic7ZXZhbCB1bmNvbXByZXNzJF87Cg==

스크립트 자체가 형태 얻어 명령 및 탈출 압축 후의 JB의 368 숯 용액이다 .use Compress::Zlib;$_='...';eval uncompress$_;...'

perl -M5.01 -e 'use Compress::Zlib; $_ .= <> while !eof; say compress($_);' <12days_JB.pl

Ilmari의 스크립트는 추가 $_=...;문자 없이 읽기 전용 값을 수정하는 것에 대해 불평 하지만 아마도 그는 이것을 313으로 만들 것 입니다. Ilmari가 전에했던 것처럼 수동으로 압축을 조정하여 몇 바이트를 더 절약 할 수 있지만 310 정도를 달성 할 는 있지만 귀찮게하지 않았습니다.


Perl, 376 (다른 제출을 부정함) [나의 원본 제출]

먼저 다음을 12days.pl포함 하는 perl 스크립트를 작성하십시오 .

use IO::Uncompress::Inflate qw(inflate);inflate\*DATA=>'-';
__DATA__

다음으로, 다른 제출 자료의 출력을 파이프하고 다음 12days.txt명령을 실행하십시오.

perl -e 'use IO::Compress::Deflate qw(deflate); deflate "-" => "-";' <12days.txt >>12days.pl

Vola 12days.pl는 약 376 바이트이며 노래를 인쇄합니다. ;) rawinflate를 사용하면 데이터 문서에서 Ilmari의 출력으로 시작하는 코드로 정확히 6 바이트가 이동합니다.

나는 원래 허프만 코딩 모듈을 직접 찾는 것에 대해 설정했습니다. 그러나 슬프게도 CPAN에는 영어의 문자 엔트로피 테이블이있는 모듈이 없으므로 매우 짧은 문자열을 압축 할 때 실제로 원하는 것입니다.

fortune -m Days\ of\ Christmas유감스럽게도 작동하지 않는다는 것을 알았습니다 .


1

PHP, 548

$n=explode('|','first|second|third|fourth|fifth|sixth|seventh|eighth|ninth|tenth|eleventh|twelfth');$w=explode('|','and a partridge in a pear tree.|two turtle doves|three french hens|four calling birds|five golden rings|six geese a-laying|seven swans a-swimming|eight maids a-milking|nine ladies dancing|ten lords a-leaping|eleven pipers piping|twelve drummers drumming');foreach($n as $i=>$j)echo "on the $n[$i] day of christmas,\nmy true love sent to me\n".str_replace($i?'':'and ','',implode(",\n",array_reverse(array_slice($w,0,$i+1))))."\n\n";

압축시 길이 감소, 502

eval(gzuncompress(base64_decode('eNpVkE1u3DAMhfc+BWEI8AzqDtJtg7QHCYKCsWiLrX4MUjPOAD58KE829UIyP5Hge8/lF/pYY/F0GvZhHGYWrbvSVLLfa2Dx+1yuUsM+82yn8kc76UbZbuIl2JW5FfWB4tdb3SjaxHB+dtv/OzB7QFhRqrBfCDi3klCgCtHFJgtU2xkJfLmRmg7jMAvlKUCgrIcmmDBGzgu8m0pDfCNYSvSUQQxr0woLkRLg94h3Yw/hoBtmNagbp9Tw4QMSsm84cfzXqNkiiOiZFDzmqTEzCbHI0RcJ12P6sAwrryTarqPR7JsgL9eUGj5+7MHymIsQTuHkzLeC45df7u+ZplCgLxlqIHD51fGbLb1DmWEKwloT6tilu2V0NVWWC6jlDLVAoq6/aJU/QmvEiU6Ofw/DzyNni3sYOT3S78euH1EE79Z6M1V0elQauY1t49Po+NuPs32Xvuv650+BSMT/')));

내가 읽고 싶은 해결책은 아니지만 (아직 base-64 / gzip, 훌륭합니다), 나는 혼자서 그 점수에 부정적인 답을 얻을만한 이유가 없습니다. 균형을 잡도록 공감했다. 다운 보트 된 사람은 이유를 알려달라고 요청합니다.
JB

많은 사람들이 압축 솔루션을 제공했기 때문에 재미를 위해 압축 솔루션을 제공하기로 결정했습니다. 그러나 내 원래 코드도 게시되어 있으므로 문제가 무엇인지 알 수 없습니다. gzipped를 무시하십시오. 또한 제가 왜 downvoted되고 있는지 알고 싶습니다.
Vladimir

1

발라, 584 , 574

void main(){int i=0;string[] d={"first","second","thrid","fourth","fifth","sixth","seventh","eighth","ninth","tenth","eleventh","twelfth"};string[] p={"Twelve drummers drumming","Eleven pipers piping","Ten lords-a-leaping","Nine ladies dancing","Eight maids-a-milking","Seven swans-a-swimming","Six geese-a-laying","Five golden rings","Four calling birds","Three french hens","Two turtle doves","A"};while(i<12){stdout.printf("On the %s day of Christmas,\nmy true love gave to me,\n%s partridge in a pear tree.\n\n",d[i],string.joinv(",\n",p[11-i:12]));p[11]="And a";i++;}}

컴파일시 더 이상 경고가 없습니다.


1

자바, 608

스택 교환에 대한 첫 번째 게시물,이 문제에 대한 두 번째 시도.

class T{public static void main(String[]args){String Z=" partridge in a pear tree.\n";String[] B=(" day of Christmas,\nMy true love gave to me0first0second0third0fourth0fifth0sixth0seventh0eighth0ninth0tenth0eleventh0twelfth0A"+Z+"0Two turtle doves,0Three french hens,0Four calling birds,0Five golden rings,0Six geese-a-laying,0Seven swans-a-swimming,0Eight maids-a-milking,0Nine ladies dancing,0Ten lords-a-leaping,0Eleven pipers piping,0Twelve drummers drumming,").split("0");for(int i=1;i<13;i++){System.out.println("On the "+B[i]+B[0]);for(int j=i+12;j>12;j--)System.out.println(B[j]);B[13]="And a"+Z;}}}

Java는 이와 같은 작업에 약간 번거롭지 만 split을 사용하면 문자열 오버 헤드가 줄어 들었습니다.


1

/// , 439 바이트

/|/\/\///^/on the |%/ day of christmas
my true love gave to me
|=/-a-|&/ing|*/even|+/th%|:/

^|A/el* pipers pip&
B|B/ten lords=leap&
C|C/nine ladies danc&
D|D/eight maids=milk&
E|E/s* swans=swimm&
F|F/six geese=lay&
G|G/five golden r&s
H|H/four call& birds
I|I/three french hens
J|J/two turtle doves
and K|K/a partridge in a pear tree/^first%K:second%J:+ird%I:four+H:fif+G:six+F:s*+E:eigh+D:nin+C:ten+B:el*+A:twelf+twelve drummers drumm&
A

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

후행 줄 바꿈이 허용되면 4 바이트를 절약 할 수 있습니다.

/|/\/\///^/on the |%/ day of christmas
my true love gave to me
|=/-a-|&/ing|*/even|+/th%|A/el* pipers pip&
B|B/ten lords=leap&
C|C/nine ladies danc&
D|D/eight maids=milk&
E|E/s* swans=swimm&
F|F/six geese=lay&
G|G/five golden r&s
H|H/four call& birds
I|I/three french hens
J|J/two turtle doves
and K|K/a partridge in a pear tree

/^first%K^second%J^+ird%I^four+H^fif+G^six+F^s*+E^eigh+D^nin+C^ten+B^el*+A^twelf+twelve drummers drumm&
A

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

설명

///는 유일한 조작이 자체 수정 대체 인 언어입니다. 특히이 명령 /abc/xyz/은의 모든 인스턴스 abcxyz 다른 대체를 포함하여 소스 코드의 나머지 부분에서 .. 다른 문자는 단순히 STDOUT로 출력됩니다.

이것은 Turing-completeness에 충분하지만 ///에서 골프는 일반적으로 의도 된 출력으로 시작하고 단일 문자 바로 가기로 대체 할 수있는 반복되는 하위 문자열을 식별하는 것으로 구성됩니다.

\패턴, 대체 및 리터럴 문자에서 이스케이프 문자로 사용하여 리터럴 /또는 을 의미 할 수 \있습니다.


첫 번째 명령은입니다 /|/\/\//. 이 의미는 "모든 교체 |와 함께 //프로그램의 나머지 부분에서." 이것은 프로그램에서 모든 후속 대체에 대한 바이트를 저장합니다.


그런 다음 텍스트 자체를 압축하기 위해 일련의 교체가 이루어집니다.

  • on the 됩니다 ^.
  • day of christmas \n my true love gave to me \n됩니다 %.
  • -a-됩니다 =.
  • ing됩니다 &.
  • even됩니다 *.
  • th%됩니다 +.
  • ^앞에는 두 개의 줄 바꿈이옵니다 (모든 구절에 나타나지만 첫 번째 구절) :.

다음으로 우리는 가사 자체를 씁니다. 이는를 A통해 대체품 을 사용하여 수행 됩니다 K. 각 문자 교체는 교체 후 줄을 추가합니다. 예를 들어, K대표 a partridge in a pear treeJ나타낸다 two turtle doves \n and K.

이런 식으로 노래의 각 구절은 다음과 같이 구성됩니다.

  • ^ 또는 :
  • 올바른 순서를 나타내는 문자열 (말 el*th)
  • %
  • 편지 A를 통해 K그 정확한 가사를 나타냅니다.

서수 대부분의 끝 때문에, th우리는 대체를 사용 th%+일부 바이트를 저장합니다.


0

가장 확실한 해결책이 가장 짧은 경우도 있습니다. 즉, 더 이상이 충동에 저항 할 수 없습니다.

Mac OS X의 배쉬, 26

open http://tiny.cc/kavxf

펄, 111

use LWP::Simple;get("http://tiny.cc/n230t")=~/On.*tree!/;
$_=$&;s/<br>/\n/g;s/(<.+?>)|(&\w+;)/ /g;print "$_\n";

가독성을 위해 하나의 줄 바꿈이 추가되었습니다.


3
이것이 유효한 해결책이라면, HQ9 + C로 작성된 더 짧은 해결책이 있습니다. (이것은 하나의 추가 명령으로 HQ9 +입니다. 그 기능을 추측 할 수 있습니다.)
Ilmari Karonen

1
나는 eval compress정말로 잘 압축하는 정규식을 찾았지만 200 자 정도 팽창했다고 주장하기 위해 트릭을 사용하여 perl을 난독 화하는 것을 고려했습니다 . lol
Jeff Burdges

비디오가 작동하지 않습니다 ... 또한 x.co를 사용 하십시오 . 제가 알고있는 가장 짧은 URL 단축 프로그램

0

자바-1329 자

class x{public static void main(String[] args){for(int i=1;i<=12;i++){System.out.print("On the ");switch(i){case 1:System.out.print("first");break;case 2:System.out.print("second");break;case 3:System.out.print("third");break;case 4:System.out.print("fourth");break;case 5:System.out.print("fifth");break;case 6:System.out.print("sixth");break;case 7:System.out.print("seventh");break;case 8:System.out.print("eighth");break;case 9:System.out.print("ninth");break;case 10:System.out.print("tenth");break;case 11:System.out.print("eleventh");break;case 12:System.out.print("twelfth");break;}System.out.println(" day of Christmas\nmy true love gave to me");switch(i){case 12:System.out.println("Twelve drummers drumming");case 11:System.out.println("Eleven pipers piping");case 10:System.out.println("Ten lords-a-leaping");case 9:System.out.println("Nine ladies dancing");case 8:System.out.println("Eight maids-a-milking");case 7:System.out.println("Seven swans-a-swimming");case 6:System.out.println("Six geese-a-laying");case 5:System.out.println("Five golden rings");case 4:System.out.println("Four calling birds");case 3:System.out.println("Three french hens");default:if(i>=2)System.out.print("Two turtle doves\nAnd a");else System.out.print("A");System.out.println(" partridge in a pear tree");break;}System.out.println();}}}

나는 그것을 풀기에는 너무 게으르지 만 여기에 있습니다 : http://ideone.com/MU9IcP .


-2

단순 , 1 바이트

a

노트 :

이 언어는 도전 이후에 설계되었으며 여전히 WIP입니다.

어떻게 :

모든 문자는 12 일의 크리스마스를 출력합니다.

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