The Twelve Days of Christmas: Difference between revisions

From Rosetta Code
Content added Content deleted
m (→‎{{header|REXX}}: simplified the REXX program, eliminated some statements. -- ~~~~)
m (→‎{{header|REXX}}: reverted "and" back to penultimate line in verse. -- ~~~~)
Line 495: Line 495:
=={{header|REXX}}==
=={{header|REXX}}==
This version:
This version:
* capitalizes the first word of each verse line
* adds a comma after each item in the list
* doesn't capitalize the word '''Twelfth'''
* doesn't capitalize the word '''Twelfth'''
* capitalizes the '''French''' word (French hen)
* capitalizes the '''French'''   (in French hen)
* capitalized '''True Love''' as it refers to a deity
* capitalized '''True Love''' as it (may) refer to a deity
* added indentation to make verses look like a song
* moved the '''and''' (for the last gift) to the last line (as that's the way it's sung)
* added indentation to make verses look like a song or poem
<lang rexx>/*REXX program displays the verses of song "The 12 days of Christmas". */
<lang rexx>/*REXX program displays the verses of song "The 12 days of Christmas". */
Nth='first second third fourth fifth sixth seventh eighth ninth tenth eleventh twelfth'
Nth='first second third fourth fifth sixth seventh eighth ninth tenth eleventh twelfth'
pad=left('',20)
pad=left('',20)
d.1 = 'a partridge in a pear-tree.'
d.1 = 'A partridge in a pear-tree.'
d.2 = 'two Turtle Doves,'
d.2 = 'Two Turtle Doves, and'
d.3 = 'three French Hens,'
d.3 = 'Three French Hens,'
d.4 = 'four Calling Birds,'
d.4 = 'Four Calling Birds,'
d.5 = 'five Golden Rings,'
d.5 = 'Five Golden Rings,'
d.6 = 'six geese a-laying,'
d.6 = 'Six geese a-laying,'
d.7 = 'seven swans a-swimming,'
d.7 = 'Seven swans a-swimming,'
d.8 = 'eight maids a-milking,'
d.8 = 'Eight maids a-milking,'
d.9 = 'nine ladies dancing,'
d.9 = 'Nine ladies dancing,'
d.10 = 'ten lords a-leaping,'
d.10 = 'Ten lords a-leaping,'
d.11 = 'eleven pipers piping,'
d.11 = 'Eleven pipers piping,'
d.12 = 'twelve drummers drumming,'
d.12 = 'Twelve drummers drumming,'
do day=1 for 12
do day=1 for 12
say pad 'On the' word(Nth,day) 'day of Christmas' /*prologue, line 1.*/
say pad 'On the' word(Nth,day) 'day of Christmas' /*prologue, line 1.*/
say pad 'My True Love gave to me:' /*prologue, line 2.*/
say pad 'My True Love gave to me:' /*prologue, line 2.*/
do j=day to 1 by -1; say pad d.j; end /*display the gifts*/

do j=day to 1 by -1; txt=strip(word('and', 1+(j\==1|day==1)) d.j)
say pad translate(left(txt,1)) || substr(txt,2)
end /*j*/
say /*add a blank line between verses*/
say /*add a blank line between verses*/
end /*day*/ /*stick a fork in it, we're done.*/</lang>
end /*day*/ /*stick a fork in it, we're done.*/</lang>
Line 534: Line 528:
On the second day of Christmas
On the second day of Christmas
My True Love gave to me:
My True Love gave to me:
Two Turtle Doves,
Two Turtle Doves, and
And a partridge in a pear-tree.
A partridge in a pear-tree.


On the third day of Christmas
On the third day of Christmas
My True Love gave to me:
My True Love gave to me:
Three French Hens,
Three French Hens,
Two Turtle Doves,
Two Turtle Doves, and
And a partridge in a pear-tree.
A partridge in a pear-tree.


On the fourth day of Christmas
On the fourth day of Christmas
Line 547: Line 541:
Four Calling Birds,
Four Calling Birds,
Three French Hens,
Three French Hens,
Two Turtle Doves,
Two Turtle Doves, and
And a partridge in a pear-tree.
A partridge in a pear-tree.


On the fifth day of Christmas
On the fifth day of Christmas
Line 555: Line 549:
Four Calling Birds,
Four Calling Birds,
Three French Hens,
Three French Hens,
Two Turtle Doves,
Two Turtle Doves, and
And a partridge in a pear-tree.
A partridge in a pear-tree.


On the sixth day of Christmas
On the sixth day of Christmas
Line 564: Line 558:
Four Calling Birds,
Four Calling Birds,
Three French Hens,
Three French Hens,
Two Turtle Doves,
Two Turtle Doves, and
And a partridge in a pear-tree.
A partridge in a pear-tree.


On the seventh day of Christmas
On the seventh day of Christmas
Line 574: Line 568:
Four Calling Birds,
Four Calling Birds,
Three French Hens,
Three French Hens,
Two Turtle Doves,
Two Turtle Doves, and
And a partridge in a pear-tree.
A partridge in a pear-tree.


On the eighth day of Christmas
On the eighth day of Christmas
Line 585: Line 579:
Four Calling Birds,
Four Calling Birds,
Three French Hens,
Three French Hens,
Two Turtle Doves,
Two Turtle Doves, and
And a partridge in a pear-tree.
A partridge in a pear-tree.


On the ninth day of Christmas
On the ninth day of Christmas
Line 597: Line 591:
Four Calling Birds,
Four Calling Birds,
Three French Hens,
Three French Hens,
Two Turtle Doves,
Two Turtle Doves, and
And a partridge in a pear-tree.
A partridge in a pear-tree.


On the tenth day of Christmas
On the tenth day of Christmas
Line 610: Line 604:
Four Calling Birds,
Four Calling Birds,
Three French Hens,
Three French Hens,
Two Turtle Doves,
Two Turtle Doves, and
And a partridge in a pear-tree.
A partridge in a pear-tree.


On the eleventh day of Christmas
On the eleventh day of Christmas
Line 624: Line 618:
Four Calling Birds,
Four Calling Birds,
Three French Hens,
Three French Hens,
Two Turtle Doves,
Two Turtle Doves, and
And a partridge in a pear-tree.
A partridge in a pear-tree.


On the twelfth day of Christmas
On the twelfth day of Christmas
Line 639: Line 633:
Four Calling Birds,
Four Calling Birds,
Three French Hens,
Three French Hens,
Two Turtle Doves,
Two Turtle Doves, and
And a partridge in a pear-tree.
A partridge in a pear-tree.
</pre>
</pre>



Revision as of 20:03, 21 December 2013

Task
The Twelve Days of Christmas
You are encouraged to solve this task according to the task description, using any language you may know.

Write a program that outputs the lyrics of the Christmas carol The Twelve Days of Christmas. The lyrics can be found here. (You must reproduce the words in the correct order, but case, format, and punctuation are left to your discretion.)

Cf

ActionScript

This program outputs the lyrics to a TextField object. The text field can be scrolled using the mouse wheel (Windows only) or by using the up/down arrow keys on the keyboard.

Works with: Flash Player version 10
Works with: AIR version 1.5

(Although the code can work in Flash Player 9 by replacing the Vectors with Arrays)

<lang ActionScript>package {

   import flash.display.Sprite;
   import flash.events.Event;
   import flash.events.KeyboardEvent;
   import flash.events.MouseEvent;
   import flash.text.TextField;
   import flash.text.TextFieldAutoSize;
   import flash.text.TextFormat;
   import flash.ui.Keyboard;
   
   public class TwelveDaysOfChristmas extends Sprite {
       
       private var _textArea:TextField = new TextField();
       
       public function TwelveDaysOfChristmas() {
           if ( stage ) _init();
           else addEventListener(Event.ADDED_TO_STAGE, _init);
       }
       
       private function _init(e:Event = null):void {
           
           removeEventListener(Event.ADDED_TO_STAGE, _init);
           
           _textArea = new TextField();
           _textArea.x = 10;
           _textArea.y = 10;
           _textArea.autoSize = TextFieldAutoSize.LEFT;
           _textArea.wordWrap = true;
           _textArea.width = stage.stageWidth - 20;
           _textArea.height = stage.stageHeight - 10;
           _textArea.multiline = true;
           
           var format:TextFormat = new TextFormat();
           format.size = 14;
           _textArea.defaultTextFormat = format;
           
           var verses:Vector.<String> = new Vector.<String>(12, true);
           var lines:Vector.<String>;
           
           var days:Vector.<String> = new Vector.<String>(12, true);
           var gifts:Vector.<String> = new Vector.<String>(12, true);
           
           days[0] = 'first';
           days[1] = 'second';
           days[2] = 'third';
           days[3] = 'fourth';
           days[4] = 'fifth';
           days[5] = 'sixth';
           days[6] = 'seventh';
           days[7] = 'eighth';
           days[8] = 'ninth';
           days[9] = 'tenth';
           days[10] = 'eleventh';
           days[11] = 'twelfth';
           
           gifts[0] = 'A partridge in a pear tree';
           gifts[1] = 'Two turtle doves';
           gifts[2] = 'Three french hens';
           gifts[3] = 'Four calling birds';
           gifts[4] = 'Five golden rings';
           gifts[5] = 'Six geese a-laying';
           gifts[6] = 'Seven swans a-swimming';
           gifts[7] = 'Eight maids a-milking';
           gifts[8] = 'Nine ladies dancing';
           gifts[9] = 'Ten lords a-leaping';
           gifts[10] = 'Eleven pipers piping';
           gifts[11] = 'Twelve drummers drumming';
           
           var i:uint, j:uint, k:uint, line:String;
           
           for ( i = 0; i < 12; i++ ) {
               
               lines = new Vector.<String>(i + 2, true);
               lines[0] = "On the " + days[i] + " day of Christmas, my true love gave to me";
               
               j = i + 1;
               k = 0;
               while ( j-- > 0 )
                   lines[++k] = gifts[j];
               
               verses[i] = lines.join('\n');
               
               if ( i == 0 )
                   gifts[0] = 'And a partridge in a pear tree';
               
           }
           
           var song:String = verses.join('\n\n');
           _textArea.text = song;
           addChild(_textArea);
           
           _textArea.addEventListener(MouseEvent.MOUSE_WHEEL, _onMouseWheel);
           stage.addEventListener(KeyboardEvent.KEY_DOWN, _onKeyDown);
           
       }
       
       private function _onKeyDown(e:KeyboardEvent):void {
           if ( e.keyCode == Keyboard.DOWN )
               _textArea.y -= 40;
           else if ( e.keyCode == Keyboard.UP )
               _textArea.y += 40;
       }
       
       private function _onMouseWheel(e:MouseEvent):void {
           _textArea.y += 20 * e.delta;
       }
       
   }
   

}</lang>

C#

<lang csharp>using System;

public class TwelveDaysOfChristmas {

   public static void Main() {
       string[] days = new string[12] {
           "first", "second", "third", "fourth", "fifth", "sixth", "seventh", "eighth", "ninth",
           "tenth", "eleventh", "twelfth",
       };
       string[] gifts = new string[12] {
           "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"
       };
       for ( int i = 0; i < 12; i++ ) {
           Console.WriteLine("On the " + days[i] + " day of Christmas, my true love gave to me");
           int j = i + 1;
           while ( j-- > 0 )
               Console.WriteLine(gifts[j]);
           Console.WriteLine();
           if ( i == 0 )
               gifts[0] = "And a partridge in a pear tree";
       }
   }

}</lang>

D

Translation of: Python

<lang d>/*immutable*/ auto gifts = "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";

immutable days = "first second third fourth fifth

                 sixth seventh eighth ninth tenth
                 eleventh twelfth";

void main() {

   import std.stdio, std.string, std.range;
   foreach (immutable n, immutable day; days.split) {
       auto g = gifts.splitLines.take(n + 1).retro;
       writeln("On the ", day,
               " day of Christmas\nMy true love gave to me:\n",
               g[0 .. $ - 1].join("\n"),
               (n > 0 ? " and\n" ~ g.back : g.back.capitalize), '\n');
   }

}</lang>

J

<lang j>require 'strings' NB. not necessary for versions > j6

days=: ;:'first second third fourth fifth sixth seventh eighth ninth tenth eleventh twelfth'

gifts=: <;.2 ] 0 : 0 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, )

firstline=: 'On the ' , ,&(' day of Christmas, my true love gave to me',LF)

chgFirstVerse=: rplc&('nd a';)&.>@{. , }.

makeVerses=: [: chgFirstVerse (firstline&.> days) ,&.> [: <@;@|.\ gifts"_

singCarol=: LF joinstring makeVerses</lang>

JavaScript

<lang JavaScript> var days = [

   'first', 'second', 'third', 'fourth', 'fifth', 'sixth', 'seventh', 'eighth', 'ninth',
   'tenth', 'eleventh', 'twelfth',

];

var gifts = [

   "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"

];

var lines, verses = [], song;

for ( var i = 0; i < 12; i++ ) {

   lines = [];
   lines[0] = "On the " + days[i] + " day of Christmas, my true love gave to me";
   
   var j = i + 1;
   var k = 0;
   while ( j-- > 0 )
       lines[++k] = gifts[j];


   verses[i] = lines.join('\n');
   
   if ( i == 0 )
       gifts[0] = "And a partridge in a pear tree";
   

}

song = verses.join('\n\n'); document.write(song); </lang>

Lua

<lang Lua> local days = {

   'first', 'second', 'third', 'fourth', 'fifth', 'sixth', 'seventh', 'eighth', 'ninth',
   'tenth', 'eleventh', 'twelfth',

}

local gifts = {

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

}

local verses = {}

for i = 1, 12 do

   local lines = {}
   lines[1] = "On the " .. days[i] .. " day of Christmas, my true love gave to me"
   
   local j = i
   local k = 2
   repeat
       lines[k] = gifts[j]
       k = k + 1
       j = j - 1
   until j == 0
   
   verses[i] = table.concat(lines, '\n')

end

print(table.concat(verses, '\n\n')) </lang>

Perl 6

<lang perl6>my @days = <first second third fourth fifth sixth seventh eighth ninth tenth eleventh twelfth>;

my @gifts = lines q:to//;

 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,

sub nth($n) { say "On the @days[$n] day of Christmas, my true love gave to me:" }

nth(0); say @gifts[0].subst('And a','A');

for 1 ... 11 -> $d {

   say ;
   nth($d);
   say @gifts[$_] for $d ... 0;

}</lang>

Output:
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.

On the fourth day of Christmas, my true love gave to me:
  Four calling birds,
  Three french hens,
  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.

PHP

<lang PHP> <?php

header("Content-Type: text/plain; charset=UTF-8");

$days = array(

   'first', 'second', 'third', 'fourth', 'fifth', 'sixth', 'seventh', 'eighth', 'ninth',
   'tenth', 'eleventh', 'twelfth',

);

$gifts = array(

   "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"

);

$verses = [];

for ( $i = 0; $i < 12; $i++ ) {

   $lines = [];
   $lines[0] = "On the {$days[$i]} day of Christmas, my true love gave to me";
   
   $j = $i;
   $k = 0;
   while ( $j >= 0 ) {
       $lines[++$k] = $gifts[$j];
       $j--;
   }
       
   $verses[$i] = implode(PHP_EOL, $lines);
       
   if ( $i == 0 )
       $gifts[0] = "And a partridge in a pear tree";

}

echo implode(PHP_EOL . PHP_EOL, $verses);

?> </lang>

Python

<lang python>gifts = \ 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.split('\n')

days = first second third fourth fifth

         sixth seventh eighth ninth tenth
         eleventh twelfth.split()

for n, day in enumerate(days, 1):

   g = gifts[:n][::-1]
   print(('\nOn the %s day of Christmas\nMy true love gave to me:\n' % day) +
         '\n'.join(g[:-1]) +
         (' and\n' + g[-1] if n > 1 else g[-1].capitalize()))</lang>
Output:
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.

On the fourth day of Christmas
My true love gave to me:
Four calling birds
Three french hens
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.

REXX

This version:

  • doesn't capitalize the word Twelfth
  • capitalizes the French   (in French hen)
  • capitalized True Love as it (may) refer to a deity
  • added indentation to make verses look like a song

<lang rexx>/*REXX program displays the verses of song "The 12 days of Christmas". */ Nth='first second third fourth fifth sixth seventh eighth ninth tenth eleventh twelfth' pad=left(,20)

                    d.1  = 'A partridge in a pear-tree.'
                    d.2  = 'Two Turtle Doves, and'
                    d.3  = 'Three French Hens,'
                    d.4  = 'Four Calling Birds,'
                    d.5  = 'Five Golden Rings,'
                    d.6  = 'Six geese a-laying,'
                    d.7  = 'Seven swans a-swimming,'
                    d.8  = 'Eight maids a-milking,'
                    d.9  = 'Nine ladies dancing,'
                    d.10 = 'Ten lords a-leaping,'
                    d.11 = 'Eleven pipers piping,'
                    d.12 = 'Twelve drummers drumming,'
 do day=1  for 12
 say pad 'On the' word(Nth,day) 'day of Christmas'  /*prologue, line 1.*/
 say pad 'My True Love gave to me:'                 /*prologue, line 2.*/
         do j=day  to 1  by -1;  say pad d.j;  end  /*display the gifts*/
 say                                  /*add a blank line between verses*/
 end       /*day*/                    /*stick a fork in it, we're done.*/</lang>

output

                     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.

                     On the fourth day of Christmas
                     My True Love gave to me:
                     Four Calling Birds,
                     Three French Hens,
                     Two Turtle Doves, and
                     A partridge in a pear-tree.

                     On the fifth day of Christmas
                     My True Love gave to me:
                     Five Golden Rings,
                     Four Calling Birds,
                     Three French Hens,
                     Two Turtle Doves, and
                     A partridge in a pear-tree.

                     On the sixth day of Christmas
                     My True Love gave to me:
                     Six geese a-laying,
                     Five Golden Rings,
                     Four Calling Birds,
                     Three French Hens,
                     Two Turtle Doves, and
                     A partridge in a pear-tree.

                     On the seventh day of Christmas
                     My True Love gave to me:
                     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.

                     On the eighth day of Christmas
                     My True Love gave to me:
                     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.

                     On the ninth day of Christmas
                     My True Love gave to me:
                     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.

                     On the tenth day of Christmas
                     My True Love gave to me:
                     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.

                     On the eleventh day of Christmas
                     My True Love gave to me:
                     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.

                     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.

Tcl

Works with: Tcl version 8.6

<lang tcl>set days {

   first second third fourth fifth sixth
   seventh eighth ninth tenth eleventh twelfth

} set gifts [lreverse {

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

}]

set n -1;puts [join [lmap day $days {

   format "On the $day day of Christmas,\nMy true love gave to me:\n%s" \

[join [lrange $gifts end-[incr n] end] \n] }] \n\n]</lang>

Output:
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.

On the fourth day of Christmas,
My true love gave to me:
Four calling birds,
Three french hens,
Two turtle doves, and
A partridge in a pear tree.

On the fifth day of Christmas,
My true love gave to me:
Five golden rings,
Four calling birds,
Three french hens,
Two turtle doves, and
A partridge in a pear tree.

On the sixth day of Christmas,
My true love gave to me:
Six geese a-laying,
Five golden rings,
Four calling birds,
Three french hens,
Two turtle doves, and
A partridge in a pear tree.

On the seventh day of Christmas,
My true love gave to me:
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.

On the eighth day of Christmas,
My true love gave to me:
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.

On the ninth day of Christmas,
My true love gave to me:
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.

On the tenth day of Christmas,
My true love gave to me:
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.

On the eleventh day of Christmas,
My true love gave to me:
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.

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.