I've been working on an exercise to generate the English "Twelve days of Christmas song". So far, I've come up with the following:
for(<DATA>){s/%/ing/;$_=($i++?$i-1+print" ":a)." $_";print"On the $i",(st,nd,rd)[$i-1]||th," day of Christmas, my true love gave to me: ",$t=$_.$t}__DATA__ partridge in a pear tree. turtle doves and French hens, call% birds, golden rings, geese a-lay%, swans a-swimm%, maids a-milk%, ladies danc%, lords a-leap%, pipers pip%, drummers drumm%,
That generates the following text:
On the 1st day of Christmas, my true love gave to me: a partridge in a pear tree. On the 2nd day of Christmas, my true love gave to me: 2 turtle doves and a partridge in a pear tree. On the 3rd day of Christmas, my true love gave to me: 3 French hens, 2 turtle doves and a partridge in a pear tree. On the 4th day of Christmas, my true love gave to me: 4 calling birds, 3 French hens, 2 turtle doves and a partridge in a pear tree. On the 5th day of Christmas, my true love gave to me: 5 golden rings, 4 calling birds, 3 French hens, 2 turtle doves and a partridge in a pear tree. On the 6th day of Christmas, my true love gave to me: 6 geese a-laying, 5 golden rings, 4 calling birds, 3 French hens, 2 turtle doves and a partridge in a pear tree. On the 7th day of Christmas, my true love gave to me: 7 swans a-swimming, 6 geese a-laying, 5 golden rings, 4 calling birds, 3 French hens, 2 turtle doves and a partridge in a pear tree. On the 8th day of Christmas, my true love gave to me: 8 maids a-milking, 7 swans a-swimming, 6 geese a-laying, 5 golden rings, 4 calling birds, 3 French hens, 2 turtle doves and a partridge in a pear tree. On the 9th day of Christmas, my true love gave to me: 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 and a partridge in a pear tree. On the 10th day of Christmas, my true love gave to me: 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 and a partridge in a pear tree. On the 11th day of Christmas, my true love gave to me: 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 and a partridge in a pear tree. On the 12th day of Christmas, my true love gave to me: 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 and a partridge in a pear tree.
My script is 343 bytes, which is better than zip and tar+gzip but worse than gzip:
-rw-r--r-- 1 john john 294 May 1 13:29 12days.gz -rw-r--r-- 1 john john 343 Apr 30 04:00 12days.pl -rw-r--r-- 1 john john 370 May 1 13:30 12days.tar.gz -rw-r--r-- 1 john john 2169 May 1 13:29 12days.txt -rw-r--r-- 1 john john 439 May 1 13:30 12days.zip
Does anybody have a shorter solution? For simplicity's sake, I've limited the challenge to digits rather than written numbers.
|
---|
Replies are listed 'Best First'. | |
---|---|
Re: 12 days of Perl?
by choroba (Cardinal) on Apr 30, 2021 at 18:31 UTC | |
by johnaj (Sexton) on Apr 30, 2021 at 22:00 UTC | |
by WithABeard (Sexton) on May 09, 2023 at 12:07 UTC | |
Re: 12 days of Perl?
by choroba (Cardinal) on Apr 30, 2021 at 09:16 UTC | |
Re: 12 days of Perl?
by eyepopslikeamosquito (Archbishop) on May 01, 2021 at 10:36 UTC | |
by johnaj (Sexton) on May 01, 2021 at 11:27 UTC | |
by eyepopslikeamosquito (Archbishop) on May 01, 2021 at 12:17 UTC | |
Re: 12 days of Perl?
by jdporter (Paladin) on Apr 30, 2021 at 15:49 UTC | |
by johnaj (Sexton) on Apr 30, 2021 at 18:05 UTC |
Back to
Perl Poetry