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%,
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:
Does anybody have a shorter solution? For simplicity's sake, I've limited the challenge to digits rather
than written numbers.