#include<stdio.h>

int main()
{
    int i,j;

    char days[12][10] =
    {
        "First",
        "Second",
        "Third",
        "Fourth",
        "Fifth",
        "Sixth",
        "Seventh",
        "Eighth",
        "Ninth",
        "Tenth",
        "Eleventh",
        "Twelfth"
    };

    char gifts[12][33] =
    {
        "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."
    };

    for(i=0;i<12;i++)
    {
        printf("\n\nOn the %s day of Christmas\nMy true love gave to me:",days[i]);

        for(j=i;j>=0;j--)
        {
            (i==0)?printf("\nA partridge in a pear tree."):printf("\n%s%c",gifts[11-j],(j!=0)?',':' ');
        }
    }

    return 0;
}


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

    }

}


#include <iostream>
#include <array>
#include <string>
using namespace std;

int main()
{
    const array<string, 12> days
    {
        "first",
        "second",
        "third",
        "fourth",
        "fifth",
        "sixth",
        "seventh",
        "eighth",
        "ninth",
        "tenth",
        "eleventh",
        "twelfth"
    };

    const array<string, 12> gifts
    {
        "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"
    };

    for(int i = 0; i < days.size(); ++i)
    {
        cout << "On the " << days[i] << " day of christmas, my true love gave to me\n";

        if(i == 0)
        {
            cout << "A partridge in a pear tree\n";
        }
        else
        {
            int j = i + 1;
            while(j-- > 0) cout << gifts[j] << '\n';
        }

        cout << '\n';
    }

    return 0;
}


(let
  [numbers '(first second third fourth fifth sixth
             seventh eighth ninth tenth eleventh twelfth)

   gifts   ["And a partridge in a pear tree",   "Two turtle doves",
            "Three French hens",                "Four calling birds",
            "Five gold 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"]

   day     (fn [n]
               (printf "On the %s day of Christmas, my true love sent to me\n"
                       (nth numbers n)))]

  (day 0)
  (println  (clojure.string/replace (first gifts) "And a" "A"))
  (dorun (for [d (range 1 12)] (do
    (println)
    (day d)
    (dorun (for [n (range d -1 -1)]
      (println (nth gifts n))))))))


christmas = cluster is carol
    rep = null

    own ordinals: array[string] := array[string]$[
        "first", "second", "third", "fourth", "fifth",
        "sixth", "seventh", "eighth", "ninth", "tenth",
        "eleventh", "twelfth"
    ]

    own gifts: array[string] := array[string]$[
        "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,"
    ]

    verse = proc (s: stream, n: int)
        stream$putl(s, "On the " || ordinals[n] || " day of Christmas,")
        stream$putl(s, "My true love gave to me:")
        for gift: int in int$from_to_by(n, 1, -1) do
            stream$putl(s, gifts[gift])
        end
        stream$putl(s, "")
    end verse

    carol = proc (s: stream)
        for n: int in int$from_to(1, 12) do
            verse(s, n)
        end
    end carol
end christmas

start_up = proc ()
    christmas$carol(stream$primary_output())
end start_up


       >>SOURCE FREE
PROGRAM-ID. twelve-days-of-christmas.

DATA DIVISION.
WORKING-STORAGE SECTION.
01  gifts-area VALUE "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      ".
    03  gifts                           PIC X(30) OCCURS 12 TIMES
                                        INDEXED BY gift-idx.

01  ordinals-area VALUE "first     second    third     fourth    fifth     "
    & "sixth     seventh   eighth    ninth     tenth     eleventh  twelfth   ".
    03  ordinals                        PIC X(10) OCCURS 12 TIMES.

01  day-num                             PIC 99 COMP.

PROCEDURE DIVISION.
    PERFORM VARYING day-num FROM 1 BY 1 UNTIL day-num > 12
        DISPLAY "On the " FUNCTION TRIM(ordinals (day-num)) " day of Christmas,"
            " my true love gave to me"

        IF day-num = 1
            DISPLAY "A " gifts (1)
        ELSE
            PERFORM VARYING gift-idx FROM day-num BY -1 UNTIL gift-idx = 1
                DISPLAY gifts (gift-idx)
            END-PERFORM
            DISPLAY "And a " gifts (1)
        END-IF

        DISPLAY SPACE
    END-PERFORM
    .
END PROGRAM twelve-days-of-christmas.


let
  ((gifts '("A partridge in a pear tree." "Two turtle doves, and"
            "Three French hens,"          "Four calling birds,"
            "Five gold 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," )))

   (loop for day from 1 to 12 doing
     (format t "On the ~:r day of Christmas, my true love sent to me:~%" day)
     (loop for gift from (1- day) downto 0 doing
        (format t "~a~%" (nth gift gifts)))
     (format t "~%")))


include "cowgol.coh";

var ordinals: [uint8][] := {
    "first","second","third","fourth","fifth",
    "sixth","seventh","eighth","ninth","tenth",
    "eleventh","twelfth"
};

var gifts: [uint8][] := {
    "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."
};

var verse: @indexof ordinals := 0;
var gift: @indexof gifts;
while verse < 12 loop
    print("On the ");
    print(ordinals[verse]);
    print(" day of Christmas, my true love gave to me:\n");
    gift := 11 - verse;
    while gift < 12 loop
        print(gifts[gift]);
        print_nl();
        gift := gift + 1;
    end loop;
    print_nl();
    verse := verse + 1;
end loop;


days = "first second third fourth fifth sixth seventh eighth ninth tenth eleventh twelfth".split " "
gifts = "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 "\n"

days.each_with_index do |day, i|
    puts "On the #{day} day of Christmas\nMy true love gave to me:"
    gifts[0, i + 1].reverse.each &->puts(String)
    puts
end


immutable 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() @safe {
    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');
    }
}


0

d [first]                       r :n
d [A partridge in a pear tree.] r :g 1 +

d [second]                      r :n
d [Two turtle doves and]        r :g 1 +

d [third]                       r :n
d [Three French hens,]          r :g 1 +

d [fourth]                      r :n
d [Four calling birds,]         r :g 1 +

d [fifth]                       r :n
d [Five gold rings,]            r :g 1 +

d [sixth]                       r :n
d [Six geese a-laying,]         r :g 1 +

d [seventh]                     r :n
d [Seven swans a-swimming,]     r :g 1 +

d [eighth]                      r :n
d [Eight maids a-milking,]      r :g 1 +

d [ninth]                       r :n
d [Nine ladies dancing,]        r :g 1 +

d [tenth]                       r :n
d [Ten lords a-leaping,]        r :g 1 +

d [eleventh]                    r :n
d [Eleven pipers piping,]       r :g 1 +

d [twelfth]                     r :n
  [Twelve drummers drumming,]   r :g

[
  d
  ;g n
  10 P
] sp

[
  d
  0 r !<p
  1 -
  d
  0 r !<r
] sr

[
  [On the ] n
  d ;n n
  [ day of Christmas, my true love sent to me:] n
  10 P
  d
  lr x s_
  10 P
  1 +
  d
  12 r <l
] sl

0 ll x


let days = [
    "first", "second", "third", "fourth", "fifth", "sixth", "seventh", "eighth", "ninth",
    "tenth", "eleventh", "twelfth"
]
let 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"
]

for i in 0..11 {
    print("On the \(days[i]) day of Christmas, my true love gave to me.")
    for j in i^-1..0 {
        print(gifts[j])
    }
    print()
}


class
	APPLICATION

create
	make

feature

	make
		do
			twelve_days_of_christmas
		end

feature {NONE}

	twelve_days_of_christmas
			-- Christmas carol: Twelve days of christmas.
		local
			i, j: INTEGER
		do
			create gifts.make_empty
			create days.make_empty
			gifts := <<"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", "And a partridge in a pear tree.", "Two turtle doves">>
			days := <<"first", "second", "third", "fourth", "fifth", "sixth", "seventh", "eighth", "ninth", "tenth", "eleventh", "Twelfth">>
			from
				i := 1
			until
				i > days.count
			loop
				io.put_string ("On the " + days [i] + " day of Christmas.%N")
				io.put_string ("My true love gave to me:%N")
				from
					j := i
				until
					j <= 0
				loop
					if i = 12 and j = 2 then
						io.put_string (gifts [14] + "%N")
						io.put_string (gifts [13] + "%N")
						j := j - 1
					else
						io.put_string (gifts [j] + "%N")
					end
					j := j - 1
				end
				io.new_line
				i := i + 1
			end
		end

	gifts: ARRAY [STRING]

	days: ARRAY [STRING]

end


import extensions;

public program()
{
    var days := new string[]{
            "first", "second", "third", "fourth", "fifth", "sixth", "seventh", "eighth", "ninth",
            "tenth", "eleventh", "twelfth"
            };

    var gifts := new string[]{
            "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"
        };

    for(int i := 0, i < 12, i += 1)
    {
        console.printLine("On the ", days[i], " day of Christmas, my true love gave to me");

        if (i == 0)
        {
            console.printLine("A partridge in a pear tree")
        }
        else
        {
            for(int j := i, j >= 0, j -= 1)
            {
                console.printLine(gifts[j])
            }
        };

        console.printLine()
    }
}


gifts = """
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
""" |> String.split("\n", trim: true)

days = ~w(first second third fourth fifth sixth seventh eighth ninth tenth eleventh twelfth)

Enum.with_index(days) |> Enum.each(fn {day, i} ->
  IO.puts "On the #{day} day of Christmas"
  IO.puts "My true love gave to me:"
  Enum.take(gifts, i+1) |> Enum.reverse |> Enum.each(&IO.puts &1)
  IO.puts ""
end)


-module(twelve_days).
-export([gifts_for_day/1]).

names(N) -> lists:nth(N,
              ["first",   "second", "third", "fourth", "fifth",    "sixth",
               "seventh", "eighth", "ninth", "tenth",  "eleventh", "twelfth" ]).

gifts() -> [ "A partridge in a pear tree.", "Two turtle doves and",
             "Three French hens,",          "Four calling birds,",
             "Five gold 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," ].

gifts_for_day(N) ->
  "On the " ++ names(N) ++ " day of Christmas, my true love sent to me:\n" ++
  string:join(lists:reverse(lists:sublist(gifts(), N)), "\n").

main(_) -> lists:map(fun(N) -> io:fwrite("~s~n~n", [gifts_for_day(N)]) end,
                     lists:seq(1,12)).


let gifts = [
    "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"
]

let days = [
    "first"; "second"; "third"; "fourth"; "fifth"; "sixth"; "seventh"; "eighth";
    "ninth"; "tenth"; "eleventh"; "twelfth"
]

let displayGifts day =
    printfn "On the %s day of Christmas, my true love gave to me" days.[day]
    if day = 0 then
        printfn "A partridge in a pear tree"
    else
        List.iter (fun i -> printfn "%s" gifts.[i]) [day..(-1)..0]
    printf "\n"

List.iter displayGifts [0..11]


USING: formatting io kernel math math.ranges qw sequences ;
IN: rosetta-code.twelve-days-of-christmas

CONSTANT: opener
    "On the %s day of Christmas, my true love sent to me:\n"

CONSTANT: ordinals qw{
    first second third fourth fifth sixth seventh eighth ninth
    tenth eleventh twelfth
}

CONSTANT: gifts {
    "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,"
}

: descend ( n -- ) 0 [a,b] [ gifts nth print ] each nl ;

: verse ( n -- )
    1 - [ ordinals nth opener printf ] [ descend ] bi ;

: twelve-days-of-christmas ( -- ) 12 [1,b] [ verse ] each ;

MAIN: twelve-days-of-christmas


create ordinals s" first" 2, s" second" 2, s" third"    2, s" fourth" 2,
                s" fifth" 2, s" sixth"  2, s" seventh"  2, s" eighth" 2,
                s" ninth" 2, s" tenth"  2, s" eleventh" 2, s" twelfth" 2,
: ordinal ordinals swap 2 * cells + [email protected] ;

create gifts s" A partridge in a pear tree." 2,
             s" Two turtle doves and" 2,
             s" Three French hens," 2,
             s" Four calling birds," 2,
             s" Five gold rings," 2,
             s" Six geese a-laying," 2,
             s" Seven swans a-swimming," 2,
             s" Eight maids a-milking," 2,
             s" Nine ladies dancing," 2,
             s" Ten lords a-leaping," 2,
             s" Eleven pipers piping," 2,
             s" Twelve drummers drumming," 2,
: gift gifts swap 2 * cells + [email protected] ;

: day
  s" On the " type
  dup ordinal type
  s"  day of Christmas, my true love sent to me:" type
  cr
  -1 swap -do
    i gift type cr
  1 -loop
  cr
  ;

: main
  12 0 do i day loop
;

main
bye


      program twelve_days

      character days(12)*8
      data days/'first', 'second', 'third',    'fourth',
     c          'fifth', 'sixth',  'seventh',  'eighth',
     c          'ninth', 'tenth',  'eleventh', 'twelfth'/

      character gifts(12)*27
      data gifts/'A partridge in a pear tree.',
     c           'Two turtle doves and',
     c           'Three French hens,',
     c           'Four calling birds,',
     c           'Five gold rings,',
     c           'Six geese a-laying,',
     c           'Seven swans a-swimming,',
     c           'Eight maids a-milking,',
     c           'Nine ladies dancing,',
     c           'Ten lords a-leaping,',
     c           'Eleven pipers piping,',
     c           'Twelve drummers drumming,'/

      integer day, gift

      do 10 day=1,12
        write (*,'(a)') 'On the ', trim(days(day)),
     c              ' day of Christmas, my true love sent to me:'
        do 20 gift=day,1,-1
          write (*,'(a)') trim(gifts(gift))
  20    continue
        write(*,*)
  10  continue
      end


' version 10-01-2017
' compile with: fbc -s console

Dim As ULong d, r

Dim As String days(1 To ...) = { "first", "second", "third", "fourth", _
                                "fifth", "sixth", "seventh", "eighth", _
                              "ninth", "tenth", "eleventh", "twelfth" }

Dim As String gifts(1 To ...) = { "", " 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 d = 1 To 12
    Print " On the " + days(d) + " day of Christmas"
    Print " My true love gave to me:"
    For r = d To 3 Step -1
        Print gifts(r)
    Next
    ' print " Two turtle doves" for the twelfth day and add "and" for the other days
    If d > 1 Then
        Print gifts(2); iif(d = 12, "", " and")
    End If
    ' print "A partridge...", on the twelfth day print "And a partrige..."
    Print " A" & IIf(d = 12, "nd a", "" ) & " partridge in a pear tree"
    Print
Next

' empty keyboard buffer
While Inkey <> "" : Wend
Print : 'Print "hit any key to end program"
Sleep
End


package main

import (
	"fmt"
)

func main() {
	days := []string{"first", "second", "third", "fourth", "fifth", "sixth",
		"seventh", "eighth", "ninth", "tenth", "eleventh", "twelfth"}

	gifts := []string{"A Partridge in a Pear Tree", "Two Turtle Doves and", "Three French Hens",
		"Four Calling Birds", "Five Gold 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 i := 0; i < 12; i++ {
		fmt.Printf("On the %s day of Christmas,\n", days[i])
		fmt.Println("My true love sent to me:")

		for j := i; j >= 0; j-- {
			fmt.Println(gifts[j])
		}
		fmt.Println()
	}
}


def presents = ['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']
['first', 'second', 'third', 'forth', 'fifth', 'sixth', 'seventh', 'eight', 'ninth', 'tenth', 'eleventh', 'Twelfth'].eachWithIndex{ day, dayIndex ->
    println "On the $day day of Christmas"
    println 'My true love gave to me:'
    (dayIndex..0).each { p ->
        print presents[p]
        println p == 1 ? ' and' : ''
    }
    println()
}


gifts :: [String]
gifts =
  [ "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,"
  ]

days :: [String]
days =
  [ "first",
    "second",
    "third",
    "fourth",
    "fifth",
    "sixth",
    "seventh",
    "eighth",
    "ninth",
    "tenth",
    "eleventh",
    "twelfth"
  ]

verseOfTheDay :: Int -> IO ()
verseOfTheDay day = do
  putStrLn $
    "On the " <> days !! day
      <> " day of Christmas my true love gave to me... "
  mapM_ putStrLn [dayGift day d | d <- [day, day -1 .. 0]]
  putStrLn ""
  where
    dayGift 0 _ = "A partridge in a pear tree!"
    dayGift _ gift = gifts !! gift

main :: IO ()
main = mapM_ verseOfTheDay [0 .. 11]


procedure main()
    days := ["first","second","third","fourth","fifth","sixth","seventh",
             "eighth","ninth","tenth","eleventh","twelveth"]
    gifts := ["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,"]

    every write("\nOn the ",days[day := 1 to 12]," day of Christmas my true love gave to me:") do
        every write(" ",gifts[day to 1 by -1])
end


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


public class TwelveDaysOfChristmas {

    final static String[] gifts = {
        "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",
        "And a partridge in a pear tree.", "Two turtle doves"
    };

    final static String[] days = {
        "first", "second", "third", "fourth", "fifth", "sixth", "seventh",
        "eighth", "ninth", "tenth", "eleventh", "Twelfth"
    };

    public static void main(String[] args) {
        for (int i = 0; i < days.length; i++) {
            System.out.printf("%nOn the %s day of Christmas%n", days[i]);
            System.out.println("My true love gave to me:");
            for (int j = i; j >= 0; j--)
                System.out.println(gifts[i == 11 && j < 2 ? j + 12 : j]);
        }
    }
}


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);


[ "one", "two", "three", "four", "five", "six",
    "seven", "eight", "nine", "ten", "eleven", "twelve"] as $cardinals
| [ "first", "second", "third", "fourth", "fifth", "sixth",
    "seventh", "eighth", "ninth", "tenth", "eleventh", "twelfth"] as $ordinals
| [ "a partridge in a pear tree.", "turtle doves", "French hens",
    "calling birds", "gold rings", "geese a-laying", "swans a-swimming",
    "maids a-milking", "ladies dancing", "lords a-leaping", "pipers piping",
    "drummers drumming" ] as $gifts
| range(12) | . as $i | $ordinals[$i] as $nth
| "On the " + $nth + " day of Christmas, my true love sent to me:\n" +
  ([[range($i+1)]|reverse[]|. as $j|$cardinals[$j] as $count|
     if $j > 0 then $count else if $i > 0 then "and" else "" end end +
      " " + $gifts[$j] + if $j > 0 then "," else "\n" end]
  | join("\n"))


#!/usr/bin/env jsish
"use strict";

/* Twelve Days Of Christmas, in Jsish */
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');
;song;

/*
=!EXPECTSTART!=
song ==> 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
=!EXPECTEND!=
*/


# v0.6.0

function printlyrics()
    const gifts = split("""
    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
    """, '\n')
    const days = split("""
    first second third fourth fifth
    sixth seventh eighth ninth tenth
    eleventh twelfth""")
    for (n, day) in enumerate(days)
        g = gifts[n:-1:1]
        print("\nOn the $day day of Christmas\nMy true love gave to me:\n")
        if n == 1
            print(join(g[1:end], '\n'), '\n')
        else
            print(join(g[1:end-1], '\n'), " and\n", g[end], '\n')
        end
    end
end

printlyrics()


enum class Day {
    first, second, third, fourth, fifth, sixth, seventh, eighth, ninth, tenth, eleventh, twelfth;
    val header = "On the " + this + " day of Christmas, my true love sent to me\n\t"
}

fun main(x: Array<String>) {
    val gifts = listOf("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")

    Day.values().forEachIndexed { i, d -> println(d.header + gifts.slice(0..i).asReversed().joinToString("\n\t")) }
}


{def days
   first second third fourth fifth sixth
   seventh eight ninth tenth eleventh twelfth}
-> days

{def texts
   {quote A partridge in a pear tree.}
   {quote Two turtle doves and}
   {quote Three french hens}
   {quote Four calling birds}
   {quote Five golden rings}
   {quote Six geese a-laying}
   {quote Seven swans a-swimming}
   {quote Eight maids a-milking}
   {quote Nine ladies dancing}
   {quote Ten lords a-leaping}
   {quote Eleven pipers piping}
   {quote Twelve drummers drumming}}
-> texts

{S.map {lambda {:i} {hr}On the {S.get :i {days}} day of Christmas
                    {br}My true love gave to me
                    {S.map {lambda {:i} {br}{S.get :i {texts}}}
                           {S.serie :i 0 -1}}
       } {S.serie 0 {- {S.length {days}} 1}}}
->
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.


make "numbers [first second third fourth fifth sixth seventh eighth ninth tenth eleventh twelfth]
make "gifts   [[And a partridge in a pear tree] [Two turtle doves]     [Three French hens]
               [Four calling birds]             [Five gold rings]      [Six geese a-laying]
               [Seven swans a-swimming]         [Eight maids a-miling] [Nine ladies dancing]
               [Ten lords a-leaping]            [Eleven pipers piping] [Twelve drummers drumming]]

to nth :n
  print (sentence [On the] (item :n :numbers) [day of Christmas, my true love sent to me])
end

nth 1
print [A partridge in a pear tree]

for [d 2 12] [
  print []
  nth :d
  for [g :d 1] [
    print item :g gifts
  ]
]
bye


CAN HAS STDIO?
HAI 1.2

I HAS A Dayz ITZ A BUKKIT
Dayz HAS A SRS  1 ITZ "first"
Dayz HAS A SRS  2 ITZ "second"
Dayz HAS A SRS  3 ITZ "third"
Dayz HAS A SRS  4 ITZ "fourth"
Dayz HAS A SRS  5 ITZ "fifth"
Dayz HAS A SRS  6 ITZ "sixth"
Dayz HAS A SRS  7 ITZ "seventh"
Dayz HAS A SRS  8 ITZ "eighth"
Dayz HAS A SRS  9 ITZ "ninth"
Dayz HAS A SRS 10 ITZ "tenth"
Dayz HAS A SRS 11 ITZ "eleventh"
Dayz HAS A SRS 12 ITZ "twelfth"

I HAS A Prezents ITZ A BUKKIT
Prezents HAS A SRS  1 ITZ "A partridge in a pear tree"
Prezents HAS A SRS  2 ITZ "Two turtle doves"
Prezents HAS A SRS  3 ITZ "Three French hens"
Prezents HAS A SRS  4 ITZ "Four calling birds"
Prezents HAS A SRS  5 ITZ "Five gold rings"
Prezents HAS A SRS  6 ITZ "Six geese a-laying"
Prezents HAS A SRS  7 ITZ "Seven swans a-swimming"
Prezents HAS A SRS  8 ITZ "Eight maids a-milking"
Prezents HAS A SRS  9 ITZ "Nine ladies dancing"
Prezents HAS A SRS 10 ITZ "Ten lords a-leaping"
Prezents HAS A SRS 11 ITZ "Eleven pipers piping"
Prezents HAS A SRS 12 ITZ "Twelve drummers drumming"

IM IN YR Outer UPPIN YR i WILE DIFFRINT i AN 12
  I HAS A Day ITZ SUM OF i AN 1
  VISIBLE "On the " !
  VISIBLE Dayz'Z SRS Day !
  VISIBLE " day of Christmas, my true love sent to me"
  IM IN YR Inner UPPIN YR j WILE DIFFRINT j AN  Day
    I HAS A Count ITZ DIFFERENCE OF Day AN j
    VISIBLE Prezents'Z SRS Count
  IM OUTTA YR Inner
  BOTH SAEM i AN 0
  O RLY?
    YA RLY
      Prezents'Z SRS 1 R "And a partridge in a pear tree"
  OIC
  DIFFRINT i AN 11
    O RLY?
      YA RLY
        VISIBLE ""
  OIC
IM OUTTA YR Outer

KTHXBYE


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'))


            NORMAL MODE IS INTEGER

            THROUGH VERSE, FOR I=1, 1, I.G.12
            PRINT FORMAT XMS,ORD(I)
            PRINT FORMAT TLV
            TRANSFER TO GIFT(13-I)
GIFT(1)     PRINT FORMAT G12
GIFT(2)     PRINT FORMAT G11
GIFT(3)     PRINT FORMAT G10
GIFT(4)     PRINT FORMAT G9
GIFT(5)     PRINT FORMAT G8
GIFT(6)     PRINT FORMAT G7
GIFT(7)     PRINT FORMAT G6
GIFT(8)     PRINT FORMAT G5
GIFT(9)     PRINT FORMAT G4
GIFT(10)    PRINT FORMAT G3
GIFT(11)    PRINT FORMAT G2
GIFT(12)    PRINT FORMAT G1
VERSE       PRINT FORMAT MT

            VECTOR VALUES XMS =
          0        $7HON THE ,C,S1,16HDAY OF CHRISTMAS*$
            VECTOR VALUES ORD = $*$, $FIRST$, $SECOND$, $THIRD$
          0 ,      $FOURTH$, $FIFTH$, $SIXTH$, $SEVENTH$, $EIGHTH$
          1 ,      $NINTH$, $TENTH$, $ELEVENTH$, $TWELFTH$
            VECTOR VALUES TLV = $23HMY TRUE LOVE GAVE TO ME*$
            VECTOR VALUES G12 = $24HTWELVE DRUMMERS DRUMMING*$
            VECTOR VALUES G11 = $20HELEVEN PIPERS PIPING*$
            VECTOR VALUES G10 = $19HTEN LORDS A-LEAPING*$
            VECTOR VALUES G9  = $19HNINE LADIES DANCING*$
            VECTOR VALUES G8  = $21HEIGHT MAIDS A-MILKING*$
            VECTOR VALUES G7  = $22HSEVEN SWANS A-SWIMMING*$
            VECTOR VALUES G6  = $18HSIX GEESE A-LAYING*$
            VECTOR VALUES G5  = $17HFIVE GOLDEN RINGS*$
            VECTOR VALUES G4  = $18HFOUR CALLING BIRDS*$
            VECTOR VALUES G3  = $17HTHREE FRENCH HENS*$
            VECTOR VALUES G2  = $20HTWO TURTLE DOVES AND*$
            VECTOR VALUES G1  = $26HA PARTRIDGE IN A PEAR TREE*$
            VECTOR VALUES MT  = $*$
            END OF PROGRAM


gifts := ["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"]:
days := ["first", "second", "third", "fourth", "fifth", "sixth",
		"seventh", "eighth", "ninth", "tenth", "eleventh", "twelfth"]:
for i to 12 do
	printf("On the %s day of Christmas\nMy true love gave to me:\n", days[i]);
	for j from 13-i to 12 do
		printf("%s\n", gifts[j]);
	end do;
	printf("\n");
end do;


daysarray = {"first", "second", "third", "fourth", "fifth", "sixth",
   "seventh", "eighth", "ninth", "tenth", "eleventh", "twelfth"};
giftsarray = {"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"};
Do[Print[StringForm[
   "On the `1` day of Christmas, my true love gave to me: `2`",
   daysarray[[i]],
   If[i == 1, "A partridge in a pear tree.",
    Row[Reverse[Take[giftsarray, i]], ","]]]], {i, 1, 12}]


days = ["first","second","third", "fourth","fifth","sixth",
        "seventh","eigth","nineth","tenth","eleventh","twelfth"]
gifts = ["A partridge in a pear tree.","Two turtle doves, and",
        "Three French hens,","Four calling birds,",
        "Five gold 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 i in range(0,11)
    print "On the " + days[i] + " day of Christmas,"
    print "my true love gave to me,"
    for j in range(i,0)
        print " " + gifts[j]
    end for
    print "     ----------"
end for


import strutils, algorithm

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

  Days = ["first", "second", "third", "fourth", "fifth", "sixth",
          "seventh", "eighth", "ninth", "tenth", "eleventh", "twelfth"]

for n, day in Days:
  var g = reversed(Gifts[0..n])
  echo "\nOn the ", day, " day of Christmas\nMy true love gave to me:\n",
       g[0..^2].join("\n"), if n > 0: " and\n" & g[^1] else: capitalizeAscii(g[^1])


class TwelveDaysOfChristmas  {
  function : Main(args : String[]) ~ Nil {
    days := ["first", "second", "third", "fourth", "fifth", "sixth", "seventh", "eighth", "ninth",
            "tenth", "eleventh", "twelfth"];

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

        for(i := 0; i < days->Size(); i+=1;) {
          IO.Console->Print("On the ")->Print(days[i])->PrintLine(" day of Christmas, my true love gave to me");

          j := i + 1;
          while(j > 0 ) {
            j -= 1;
            gifts[j]->PrintLine();
          };

           IO.Console->PrintLine();

           if (i = 0) {
             gifts[0] := "And a partridge in a pear tree";
           };
        };
    }
}


days=["first","second","third","fourth","fifth","sixth","seventh","eighth","ninth","tenth","eleventh","twelfth"];
gifts=["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"];
{
for(i=1,#days,
  print("On the "days[i]" day of Christmas, my true love gave to me:");
  forstep(j=i,2,-1,print("\t"gifts[j]", "));
  print(if(i==1,"\tA partridge in a pear tree.",Str("\t",gifts[1])))
)
}


program twelve_days(output);

const
  days:  array[1..12] of string =
    ( 'first',   'second', 'third', 'fourth', 'fifth',    'sixth',
      'seventh', 'eighth', 'ninth', 'tenth',  'eleventh', 'twelfth' );

  gifts: array[1..12] of string =
    ( 'A partridge in a pear tree.',
      'Two turtle doves and',
      'Three French hens,',
      'Four calling birds,',
      'Five gold 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
   day, gift: integer;

begin
   for day := 1 to 12 do begin
     writeln('On the ', days[day], ' day of Christmas, my true love sent to me:');
     for gift := day downto 1 do
       writeln(gifts[gift]);
     writeln
   end
end.


use v5.10;

my @days = qw{ first second third fourth fifth sixth seventh eighth ninth tenth eleventh twelfth };

chomp ( my @gifts = grep { /\S/ } <DATA> );

while ( my $day = shift @days ) {
    say "On the $day day of Christmas,\nMy true love gave to me:";
    say for map { $day eq 'first' ? s/And a/A/r : $_ } @gifts[@days .. @gifts-1];
    say "";
}

__DATA__
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.


constant days = {"first", "second", "third", "fourth", "fifth", "sixth",
                 "seventh", "eighth", "ninth", "tenth", "eleventh", "twelfth"},
         gifts = {"A partridge in a pear tree.\n",
                  "Two turtle doves, and\n",
                  "Three French hens,\n",
                  "Four calling birds,\n",
                  "Five gold rings,\n",
                  "Six geese a-laying,\n",
                  "Seven swans a-swimming,\n",
                  "Eight maids a-milking,\n",
                  "Nine ladies dancing,\n",
                  "Ten lords a-leaping,\n",
                  "Eleven pipers piping,\n",
                  "Twelve drummers drumming,\n"}
for i=1 to 12 do
    printf(1,"On the %s day of Christmas,\nmy true love gave to me:\n",{days[i]})
    for j=i to 1 by -1 do
        printf(1,gifts[j])
    end for
end for


include ..\Utilitys.pmt

( "A partridge in a pear tree."
  "Two turtle doves, and"
  "Three French hens,"
  "Four calling birds,"
  "Five gold 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," )

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

10 tochar var cr

12 for >ps
    tps get
    "On the " swap " day of Christmas," cr "my true love gave to me:" 5 tolist lprint nl
    swap
    ( ps> 1 -1 ) for
        get ?
    endfor
    swap
    nl
endfor


<?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);

?>


go =>
  Days = "first second third fourth fifth sixth seventh eighth ninth tenth eleventh twelfth".split(" "),
  Gifts =
"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("\n"),

  println([to_fstring("On the %s day of Christmas,\nMy true love gave to me:\n%w\n",
           Day, slice(Gifts,1,D).reverse().join("\n")) : {Day,D} in zip(Days,1..length(Days))]
           .join("\n")),
  nl.


(de days
   first second third fourth fifth sixth
   seventh eight ninth tenth eleventh twelfth )

(de texts
   "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" )

(for (X . Day) days
   (prinl "On the " Day " day of Christmas")
   (prinl "My true love game to me:")
   (for (Y X (gt0 Y) (dec Y))
      (prinl
         (if (and (= 12 X) (= 1 Y))
            "And a partridge in a pear tree."
            (get texts Y)) ) )
   (prinl) )

(bye)


int main() {
	array(string) days = ({"first", "second", "third", "fourth", "fifth", "sixth", "seventh", "eighth", "ninth", "tenth", "eleventh", "twelfth"});
	array(string) gifts = ({"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"});

	for (int i = 0; i < 12; i++) {
		write("On the " + (string)days[i] + " day of Christmas\n");
		write("My true love gave to me:\n");
		for (int j = 0; j < i + 1; j++) {
			write((string)gifts[i - j] + "\n");
		}
		if (i != 11) {
			write("\n");
		}
	}
	return 0;
}


$days = @{
    1 = "first";
    2 = "second";
    3 = "third";
    4 = "fourth";
    5 = "fifth";
    6 = "sixth";
    7 = "seventh";
    8 = "eight";
    9 = "ninth";
    10 = "tenth";
    11 = "eleventh";
    12 = "twelfth";
}

$gifts = @{
    1 = 'A partridge in a pear tree';
    2 = 'Two turtle doves';
    3 = 'Three french hens';
    4 = 'Four calling birds';
    5 = 'Five golden rings';
    6 = 'Six geese a-laying';
    7 = 'Seven swans a-swimming';
    8 = 'Eight maids a-milking';
    9 = 'Nine ladies dancing';
    10 = 'Ten lords a-leaping';
    11 = 'Eleven pipers piping';
    12 = 'Twelve drummers drumming';
}

1 .. 12 | % {
    "On the $($days[$_]) day of Christmas`nMy true love gave to me"
    $_ .. 1 | % {
        $gift = $gifts[$_]
        if ($_ -eq 2) { $gift += " and" }
        $gift
    }
    ""
}


day(1, 'first').
day(2, 'second').
day(3, 'third').
day(4, 'fourth').
day(5, 'fifth').
day(6, 'sixth').
day(7, 'seventh').
day(8, 'eighth').
day(9, 'ninth').
day(10, 'tenth').
day(11, 'eleventh').
day(12, 'twelfth').

gift(1, 'A partridge in a pear tree.').
gift(2, 'Two turtle doves and').
gift(3, 'Three French hens,').
gift(4, 'Four calling birds,').
gift(5, 'Five gold rings,').
gift(6, 'Six geese a-laying,').
gift(7, 'Seven swans a-swimming,').
gift(8, 'Eight maids a-milking,').
gift(9, 'Nine ladies dancing,').
gift(10, 'Ten lords a-leaping,').
gift(11, 'Eleven pipers piping,').
gift(12, 'Twelve drummers drumming,').

giftsFor(0, []) :- !.
giftsFor(N, [H|T]) :- gift(N, H), M is N-1, giftsFor(M,T).

writeln(S) :- write(S), write('\n').

writeList([])    :- writeln(''), !.
writeList([H|T]) :- writeln(H), writeList(T).

writeGifts(N) :- day(N, Nth), write('On the '), write(Nth),
    writeln(' day of Christmas, my true love sent to me:'),
    giftsFor(N,L), writeList(L).

writeLoop(0) :- !.
writeLoop(N) :- Day is 13 - N, writeGifts(Day), M is N - 1, writeLoop(M).

main :- writeLoop(12), halt.


#TXT$ = "On the * day of Christmas, my true love sent to me:"
days$ = ~"first\nsecond\nthird\nfourth\nfifth\nsixth\nseventh\neighth\nninth\ntenth\neleventh\ntwelfth\n"
gifts$= ~"Twelve drummers drumming,\nEleven pipers piping,\nTen lords a-leaping,\nNine ladies dancing,\n"+
        ~"Eight maids a-milking,\nSeven swans a-swimming,\nSix geese a-laying,\nFive golden rings,\n"+
        ~"Four calling birds,\nThree french hens,\nTwo turtle doves,\nA partridge in a pear tree.\n"
Define  I.i, J.i

If OpenConsole("The twelve days of Christmas")
  For I = 1 To 12
    PrintN(ReplaceString(#TXT$,"*",StringField(days$,I,~"\n")))
    For J = 13-I To 12
      PrintN(" -> "+StringField(gifts$,J,~"\n"))
    Next J
  Next I
  Input()
EndIf


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()))


days:" "vs"first second third fourth fifth sixth seventh eighth ninth tenth eleventh twelfth"

gifts:(
  "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.";
  "")

verses:stanza 0 1,/:{(reverse x)+2+til each 2+x}til 12
lyric:raze .[;0 2;{"A",5_x}] verses{@[x;0;ssr[;"twelfth";y]]}'days

1 "\n"sv lyric;  // print


  [ [ table
      $ "first" $ "second" $ "third"    $ "fourth"
      $ "fifth" $ "sixth"  $ "seventh"  $ "eighth"
      $ "ninth" $ "tenth"  $ "eleventh" $ "twelfth" ]
    do echo$ ]                                        is day   ( n --> )

  [ [ table
      $ "A partridge in a pear tree."
      $ "Two turtle doves and"
      $ "Three French hens,"
      $ "Four calling birds,"
      $ "Five gold 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," ] do echo$ ]      is gift  ( n --> )

  [ say "On the " dup day say " day of Christmas," cr
    say "My true love gave to me," cr
    1+ times [ i gift cr ] cr ]                       is verse ( n --> )

  [  12 times [ i^ verse ] ]                          is song  (   --> )

  song


gifts <- c("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")
days <- c("first", "second", "third", "fourth", "fifth", "sixth", "seventh", "eighth", "ninth", "tenth", "eleventh", "twelfth")

for (i in seq_along(days)) {
  cat("On the", days[i], "day of Christmas\n")
  cat("My true love gave to me:\n")
  cat(paste(gifts[i:1], collapse = "\n"), "\n\n")
}


#lang racket
(define (ordinal-text d)
  (vector-ref
   (vector
    "zeroth" "first" "second" "third" "fourth"
    "fifth" "sixth" "seventh" "eighth" "ninth"
    "tenth" "eleventh" "twelfth")
   d))

(define (on-the... day)
  (printf "On the ~a day of Christmas,~%" (ordinal-text day))
  (printf "My True Love gave to me,~%"))

(define (prezzy prezzy-line day)
  (match prezzy-line
    [1 (string-append (if (= day 1) "A " "And a")" partridge in a pear tree")]
    [2 "Two turtle doves"]
    [3 "Three French hens"]
    [4 "Four calling birds"]
    [5 "FIVE GO-OLD RINGS"]
    [6 "Six geese a-laying"]
    [7 "Seven swans a-swimming"]
    [8 "Eight maids a-milking"]
    [9 "Nine ladies dancing"]
    [10 "Ten lords a-leaping"]
    [11 "Eleven pipers piping"]
    [12 "Twelve drummers drumming"]))

(define (line-end prezzy-line day)
  (match* (day prezzy-line) [(12 1) "."] [(x 1) ".\n"] [(_ _) ","]))

(for ((day (sequence-map add1 (in-range 12)))
      #:when (on-the... day)
      (prezzy-line (in-range day 0 -1)))
  (printf "~a~a~%" (prezzy prezzy-line day) (line-end prezzy-line day)))


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

my @gifts = lines q:to/END/;
  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,
END

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;
}


/*REXX program displays the verses of the song:    "The 12 days of Christmas".          */
ordD= 'first second third fourth fifth sixth seventh eighth ninth tenth eleventh twelfth'
pad= left('', 20)                                /*used for indenting the shown verses. */
                   @.1= 'A partridge in a pear-tree.';   @.7 = "Seven swans a-swimming,"
                   @.2= 'Two Turtle Doves, and'      ;   @.8 = "Eight maids a-milking,"
                   @.3= 'Three French Hens,'         ;   @.9 = "Nine ladies dancing,"
                   @.4= 'Four Calling Birds,'        ;   @.10= "Ten lords a-leaping,"
                   @.5= 'Five Golden Rings,'         ;   @.11= "Eleven pipers piping,"
                   @.6= 'Six geese a-laying,'        ;   @.12= "Twelve drummers drumming,"
  do day=1  for 12
  say pad  'On the'   word(ordD, day)   "day of Christmas"    /*display line 1 prologue.*/
  say pad  'My True Love gave to me:'                         /*   "      "  2     "    */
              do j=day  by -1  to 1;       say pad @.j        /*   "    the daily gifts.*/
              end   /*j*/
  say                                            /*add a blank line between the verses. */
  end               /*day*/                      /*stick a fork in it,  we're all done. */


# Project : The Twelve Days of Christmas

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"
days = "first second third fourth fifth sixth seventh eighth ninth tenth eleventh twelfth"
lstgifts = str2list(substr(gifts,",", nl))
lstdays = str2list(substr(days, " ", nl))
for i = 1 to 12
     see "On the "+ lstdays[i]+ " day of Christmas" + nl
     see "My true love gave to me:" + nl
     for j = i to 1 step -1
          if i > 1 and j = 1
             see "and " + nl
          ok
          see "" + lstgifts[j] + nl
     next
     see nl
next


gifts = "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("\n")

days = %w(first second third fourth fifth sixth
seventh eighth ninth tenth eleventh twelfth)

days.each_with_index do |day, i|
  puts "On the #{day} day of Christmas"
  puts "My true love gave to me:"
  puts gifts[0, i+1].reverse
  puts
end


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"

days$ = "first second third fourth fifth sixth seventh eighth ninth tenth eleventh twelfth"

for i = 1 to 12
    print "On the ";word$(days$,i," ");" day of Christmas"
    print "My true love gave to me:"
    for j = i to 1 step -1
    if i > 1 and j = 1 then print "and ";
    print mid$(word$(gifts$,j,","),2)
    next j
    print
next i


fn main() {
    let days = ["first", "second", "third", "fourth", "fifth", "sixth", "seventh", "eighth",
                "ninth", "tenth", "eleventh", "twelfth"];

    let gifts = ["A Patridge 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"];

    for i in 0..12 {
        println!("On the {} day of Christmas,", days[i]);
        println!("My true love gave to me:");

        for j in (0..i + 1).rev() {
            println!("{}", gifts[j]);
        }
        println!()
    }
}


val gifts = Array(
    "A partridge in a pear tree.",
    "Two turtle doves and",
    "Three French hens,",
    "Four calling birds,",
    "Five gold 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,"
  )

val days = Array(
    "first",   "second", "third", "fourth", "fifth",    "sixth",
    "seventh", "eighth", "ninth", "tenth",  "eleventh", "twelfth"
  )

val giftsForDay = (day: Int) =>
    "On the %s day of Christmas, my true love sent to me:\n".format(days(day)) +
      gifts.take(day+1).reverse.mkString("\n") + "\n"

(0 until 12).map(giftsForDay andThen println)


; Racket has this built in, but it's not standard
(define (take lst n)
  (if (or (null? lst) (<= n 0))
      '()
      (cons (car lst) (take (cdr lst) (- n 1)))))

(let
  ((days  '("first" "second" "third" "fourth" "fifth" "sixth" "seventh"
            "eighth" "ninth" "tenth" "eleventh" "twelfth"))

   (gifts '("A partridge in a pear tree." "Two turtle doves, and"
            "Three French hens,"          "Four calling birds,"
            "Five gold 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,")))

  (do ((left days (cdr left))
       ; No universal predefined (+ 1) function, sadly. Implementations
       ; are divided between (add1) and (1+).
       (day  1    (+ 1 day)))
      ((null? left) #t)

    (display "On the ")
    (display (car left))
    (display " day of Christmas, my true love sent to me:")
    (newline)

    (do ((daily (reverse (take gifts day)) (cdr daily)))
        ((null? daily) #t)

      (display (car daily))
      (newline))
      (newline)))

(exit)


$ include "seed7_05.s7i";

const proc: main is func
  local
    const array string: gifts is [] (
        "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");
    const array string: days is [] (
        "first", "second", "third", "fourth", "fifth", "sixth",
        "seventh", "eighth", "ninth", "tenth", "eleventh", "Twelfth");
    var integer: day is 0;
    var integer: gift is 0;
  begin
    for day range 1 to length(days) do
      writeln;
      writeln("On the " <& days[day] <& " day of Christmas,");
      writeln("My true love gave to me:");
      for gift range day downto 1 do
        writeln(gifts[gift]);
      end for;
    end for;
  end func;


(|
parent* = traits oddball.

gifts = (
   'And a partridge in a pear tree' &
   'Two turtle doves' &
   'Three french hens' &
   'Four calling birds' &
   'FIVE GO-OLD 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'
) asSequence.

days = (
   'first' & 'second' & 'third'    & 'fourth'  &
   'fifth' & 'sixth'  & 'seventh'  & 'eighth'  &
   'ninth' & 'tenth'  & 'eleventh' & 'twelfth'
) asSequence.

intro: i = ( 'On the ', (days at: i), ' day of Christmas, my true love gave to me:').
gifts: i = (  i = 0 ifTrue: [sequence copyAddFirst: 'A partridge in a pear tree' ]
                     False: [(gifts slice: [email protected](i + 1)) reverse ]).
verse: i = ( ((sequence copyAddFirst: intro: i) addAll: gifts: i) addLast: '' ).
value    = ( (days gather: [|:d. :i| verse: i ]) asSequence joinUsing: '\n' )

|) value printLine


put [
	"partridge in a pear tree.",
	"turtle doves and",
	"french hens",
	"calling birds",
	"golden rings",
	"geese a-laying",
	"swans a-swimming",
	"maids a-milking",
	"ladies dancing",
	"lords a-leaping",
	"pipers piping",
	"drummers drumming"
] into gifts

repeat with each item d1 of 1 .. 12
	put "On the" && ordinalwords of d1 && "day of Christmas,"
	put "My true love gave to me:"
	repeat with each item d2 of d1 .. 1
		if d2 is 1
			put "A" into number
		else
			put capitalized(numberwords of d2) into number
		end if
		put number && item d2 of gifts
	end repeat
	put ""
end repeat


var days = <first second third fourth fifth sixth seventh eighth ninth tenth eleventh twelfth>;

var gifts = <<'EOT'.lines;
  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,
EOT

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

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

range(1, 11).each { |d|
    say '';
    nth(d);
    d.downto(0).each { |i|
        say gifts[i];
    }
}


Begin
  Text Array days(1:12), gifts(1:12);
  Integer day, gift;

  days(1)  :- "first";
  days(2)  :- "second";
  days(3)  :- "third";
  days(4)  :- "fourth";
  days(5)  :- "fifth";
  days(6)  :- "sixth";
  days(7)  :- "seventh";
  days(8)  :- "eighth";
  days(9)  :- "ninth";
  days(10) :- "tenth";
  days(11) :- "eleventh";
  days(12) :- "twelfth";

  gifts(1)  :- "A partridge in a pear tree.";
  gifts(2)  :- "Two turtle doves and";
  gifts(3)  :- "Three French hens,";
  gifts(4)  :- "Four calling birds,";
  gifts(5)  :- "Five gold rings,";
  gifts(6)  :- "Six geese a-laying,";
  gifts(7)  :- "Seven swans a-swimming,";
  gifts(8)  :- "Eight maids a-milking,";
  gifts(9)  :- "Nine ladies dancing,";
  gifts(10) :- "Ten lords a-leaping,";
  gifts(11) :- "Eleven pipers piping,";
  gifts(12) :- "Twelve drummers drumming,";

  For day := 1 Step 1 Until 12 Do Begin
    outtext("On the "); outtext(days(day));
    outtext(" day of Christmas, my true love sent to me:"); outimage;
    For gift := day Step -1 Until 1 Do Begin
      outtext(gifts(gift)); outimage
    End;
    outimage
  End
End


Object subclass: TwelveDays [
  Ordinals := #('first'   'second' 'third' 'fourth' 'fifth'    'sixth'
                'seventh' 'eighth' 'ninth' 'tenth'  'eleventh' 'twelfth').

  Gifts := #( 'A partridge in a pear tree.' 'Two turtle doves and'
              'Three French hens,'          'Four calling birds,'
              'Five gold 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,' ).
]

TwelveDays class extend [
  giftsFor: day [
    |newLine ordinal giftList|
    newLine := $<10> asString.
    ordinal := Ordinals at: day.
    giftList := (Gifts first: day) reverse.

    ^'On the ', ordinal, ' day of Christmas, my true love sent to me:',
      newLine, (giftList join: newLine), newLine.
  ]
]

1 to: 12 do: [:i |
  Transcript show: (TwelveDays giftsFor: i); cr.
].


' by rbytes
dim d$(12),x$(15)!s=15
for t=0 to 11!read d$(t)!next t
for t=0 to 14!read x$(t)!next t
for u=0 to 11!s-=1
print x$(0)&d$(u)&x$(1)&chr$(10)&x$(2)
for t=s to 14!print x$(t)!next t
print!next u!data "first","second","third","fourth","fifth","sixth","seventh","eight","ninth","tenth","eleventh","Twelfth","On the "," 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."


	DAYS = ARRAY('12')
	DAYS<1> = 'first'
	DAYS<2> = 'second'
	DAYS<3> = 'third'
	DAYS<4> = 'fourth'
	DAYS<5> = 'fifth'
	DAYS<6> = 'sixth'
	DAYS<7> = 'seventh'
	DAYS<8> = 'eighth'
	DAYS<9> = 'ninth'
	DAYS<10> = 'tenth'
	DAYS<11> = 'eleventh'
	DAYS<12> = 'twelfth'

	GIFTS = ARRAY('12')
	GIFTS<1> = 'A partridge in a pear tree.'
	GIFTS<2> = 'Two turtle doves and'
	GIFTS<3> = 'Three French hens,'
	GIFTS<4> = 'Four calling birds,'
	GIFTS<5> = 'Five gold rings,'
	GIFTS<6> = 'Six geese a-laying,'
	GIFTS<7> = 'Seven swans a-swimming,'
	GIFTS<8> = 'Eight maids a-milking,'
	GIFTS<9> = 'Nine ladies dancing,'
	GIFTS<10> = 'Ten lords a-leaping,'
	GIFTS<11> = 'Eleven pipers piping,'
	GIFTS<12> = 'Twelve drummers drumming,'

       DAY = 1
OUTER  LE(DAY,12)            :F(END)
       INTRO = 'On the NTH day of Christmas, my true love sent to me:'
       INTRO 'NTH' = DAYS<DAY>
       OUTPUT = INTRO
       GIFT = DAY
INNER  GE(GIFT,1)            :F(NEXT)
       OUTPUT = GIFTS<GIFT>
       GIFT = GIFT - 1       :(INNER)
NEXT   OUTPUT = ''
       DAY = DAY + 1         :(OUTER)
END


WITH
FUNCTION nl ( s IN varchar2 )
RETURN varchar2
IS
BEGIN
        RETURN chr(10) || s;
END nl;
FUNCTION v ( d NUMBER, x NUMBER, g IN varchar2 )
RETURN varchar2
IS
BEGIN
        RETURN
        CASE WHEN d >= x THEN nl (g) END;
END v;
SELECT 'On the '
        || to_char(to_date(level,'j'),'jspth' )
        || ' day of Christmas,'
        || nl( 'my true love sent to me:')
        || v ( level, 12, 'Twelve drummers drumming,' )
        || v ( level, 11, 'Eleven pipers piping,' )
        || v ( level, 10, 'Ten lords a-leaping,' )
        || v ( level, 9, 'Nine ladies dancing,' )
        || v ( level, 8, 'Eight maids a-milking,' )
        || v ( level, 7, 'Seven swans a-swimming,' )
        || v ( level, 6, 'Six geese a-laying,' )
        || v ( level, 5, 'Five golden rings!' )
        || v ( level, 4, 'Four calling birds,' )
        || v ( level, 3, 'Three French hens,' )
        || v ( level, 2, 'Two turtle doves,' )
        || v ( level, 1, CASE level WHEN 1 THEN 'A' ELSE 'And a' END || ' partridge in a pear tree.' )
        || nl(NULL)
        "The Twelve Days of Christmas"
FROM dual
CONNECT BY level <= 12
/


let gifts = [ "partridge in a pear tree", "Two turtle doves",
              "Three French hens",        "Four calling birds",
              "Five gold 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" ]

let nth = [ "first",   "second", "third", "fourth", "fifth",    "sixth",
            "seventh", "eighth", "ninth", "tenth",  "eleventh", "twelfth" ]

func giftsForDay(day: Int) -> String {
  var result = "On the \(nth[day-1]) day of Christmas, my true love sent to me:\n"
  if day > 1 {
    for again in 1...day-1 {
      let n = day - again
      result += gifts[n]
      if n > 1 { result += "," }
      result += "\n"
    }
    result += "And a "
  } else {
    result += "A "
  }
  return result + gifts[0] + ".\n";
}

for day in 1...12 {
  print(giftsForDay(day))
}


def ordinal: ['first', 'second', 'third', 'fourth', 'fifth', 'sixth', 'seventh', 'eighth', 'ninth', 'tenth', 'eleventh', 'twelfth'];
def gift: [
  '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'
];
templates punctuation
  <=1> '.' !
  <=2> ' and' !
  <=5> ';' !
  <> ',' !
end punctuation

1..12 -> \singVerse(
  'On the $ordinal($); day of Christmas,
my true love gave to me:
' !
  $..1:-1 -> '$gift($);$->punctuation;
' !
'
' !
\singVerse) -> !OUT::write


locals {
  days = [ "first",   "second", "third", "fourth", "fifth",    "sixth",
           "seventh", "eighth", "ninth", "tenth",  "eleventh", "twelfth" ]
  gifts = [
    "A partridge in a pear tree.",
    "Two turtle doves, and",
    "Three French hens,",
    "Four calling birds,",
    "Five gold 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,"
  ]
}

data "template_file" "days" {
  count = 12
  template = "On the ${local.days[count.index]} day of Christmas, my true love sent to me:\n${join("\n",[for g in range(count.index,-1,-1): local.gifts[g]])}"
}

output "lyrics" {
  value = join("\n\n",[for t in data.template_file.days: t.rendered])
}


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]


DATA "first","second","third","fourth","fifth","sixth"
DATA "seventh","eighth","ninth","tenth","eleventh","twelfth"
DATA "A partridge in a pear tree."
DATA "Two turtle doves and"
DATA "Three french hens"
DATA "Four calling birds"
DATA "Five golden rings"
DATA "Six geese a-laying"
DATA "Seven swans a-swimming"
DATA "Eight maids a-milking"
DATA "Nine ladies dancing"
DATA "Ten lords a-leaping"
DATA "Eleven pipers piping"
DATA "Twelve drummers drumming"

DIM day$(12), gift$(12)
FOR i = 1 TO 12
    READ day$(i)
NEXT i
FOR i = 1 TO 12
    READ gift$(i)
NEXT i

FOR i = 1 TO 12
    PRINT "On the "; day$(i); " day of Christmas,"
    PRINT "My true love gave TO me:"
    FOR j = i TO 1 STEP -1
        PRINT gift$(j)
    NEXT j
    PRINT
NEXT i
END


Dim @n(12) : Dim @v(12)                ' define both arrays

Proc _DataDays                         ' put data on the stack

For i=11 To 0 Step -1                  ' read them in
  @n(i) = Pop()
Next

Proc _DataGifts                        ' put data on the stack

For i=11 To 0 Step -1                  ' read them in
  @v(i) = Pop()
Next

For i=0 To 11                          ' print all twelve verses
  Print "On the ";Show(@n(i));" day of Christmas"
  Print "My true love gave to me:"

  For j=i To 0 Step -1                 ' show list of gifts
    Print Show(@v(j))
  Next

  Print                                ' next verse
Next
End

_DataDays
  Push Dup("first"), Dup("second"), Dup("third"), Dup ("fourth")
  Push Dup("fifth"), Dup("sixth"), Dup("seventh"), Dup("eighth")
  Push Dup("ninth"), Dup("tenth"), Dup("eleventh"), Dup("twelfth")
Return

_DataGifts
  Push Dup("A partridge in a pear tree.")
  Push Dup("Two turtle doves and")
  Push Dup("Three french hens")
  Push Dup("Four calling birds")
  Push Dup("Five golden rings")
  Push Dup("Six geese a-laying")
  Push Dup("Seven swans a-swimming")
  Push Dup("Eight maids a-milking")
  Push Dup("Nine ladies dancing")
  Push Dup("Ten lords a-leaping")
  Push Dup("Eleven pipers piping")
  Push Dup("Twelve drummers drumming")
Return


#!/usr/bin/env bash
ordinals=(first   second third fourth fifth    sixth
          seventh eighth ninth tenth  eleventh twelfth)

gifts=( "A partridge in a pear tree." "Two turtle doves and"
        "Three French hens,"          "Four calling birds,"
        "Five gold 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," )

echo_gifts() {
  local i day=$1
  echo "On the ${ordinals[day]} day of Christmas, my true love sent to me:"
  for (( i=day; i >=0; --i )); do
    echo "${gifts[i]}"
  done
  echo
}

for (( day=0; day < 12; ++day )); do
  echo_gifts $day
done


Sub Main()
Dim i As Integer, c As Integer, j As Integer, strReturn() As String
Dim s, n
   s = Split(SING_, "$")
   n = Split(NUMBERS_, " ")
   ReDim strReturn(UBound(s))
   For i = LBound(s) To UBound(s)
      strReturn(i) = Replace(BASE_, "(X)", n(i))
      For j = c To 0 Step -1
         strReturn(i) = strReturn(i) & s(j) & vbCrLf
      Next
      c = c + 1
   Next i
   strReturn(UBound(strReturn)) = Replace(strReturn(UBound(strReturn)), "and" & vbCrLf & "A", vbCrLf & "And a")
   Debug.Print Join(strReturn, vbCrLf)
End Sub


days = Array("first","second","third","fourth","fifth","sixth",_
		"seventh","eight","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")

For i = 0 To 11
	WScript.StdOut.Write "On the " & days(i) & " day of Christmas"
	WScript.StdOut.WriteLine
	WScript.StdOut.Write "My true love sent to me:"
	WScript.StdOut.WriteLine
	If i = 0 Then
		WScript.StdOut.Write gifts(i)
	Else
		For j = i To 0 Step - 1
			If j = 0 Then
				WScript.StdOut.Write "and " & gifts(0)
			Else
				WScript.StdOut.Write gifts(j)
				WScript.StdOut.WriteLine
			End If
		Next
	End If
		WScript.StdOut.WriteBlankLines(2)
Next


for (#1 = 1; #1 <= 12; #1++) {
    Num_Str(#1, 9, LEFT)
    IT("On the ")
    Call("day |@(9)")
    IT(" day of Christmas, my true love sent to me:") IN
    Call("gift |@(9)")
    IN
}
return

:day 1:  IT("first")    return
:day 2:  IT("second")   return
:day 3:  IT("third")    return
:day 4:  IT("fourth")   return
:day 5:  IT("fifth")    return
:day 6:  IT("sixth")    return
:day 7:  IT("seventh")  return
:day 8:  IT("eighth")   return
:day 9:  IT("ninth")    return
:day 10: IT("tenth")    return
:day 11: IT("eleventh") return
:day 12: IT("twelfth")  return

:gift 12: IT("Twelve drummers drumming,") IN
:gift 11: IT("Eleven pipers piping,") IN
:gift 10: IT("Ten lords a-leaping,") IN
:gift 9:  IT("Nine ladies dancing,") IN
:gift 8:  IT("Eight maids a-milking,") IN
:gift 7:  IT("Seven swans a-swimming,") IN
:gift 6:  IT("Six geese a-laying,") IN
:gift 5:  IT("Five gold rings,") IN
:gift 4:  IT("Four calling birds,") IN
:gift 3:  IT("Three French hens,") IN
:gift 2:  IT("Two turtle doves, and") IN
:gift 1:  IT("A partridge in a pear tree.") IN
return


let b:days=["first",   "second", "third", "fourth", "fifth",    "sixth",
  \         "seventh", "eighth", "ninth", "tenth",  "eleventh", "twelfth"]

let b:gifts=[
  \ "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,"
\ ]

function Nth(n)
  echom "On the " . b:days[a:n] . " day of Christmas, my true love gave to me:"
endfunction

call Nth(0)
echom toupper(strpart(b:gifts[0], 4, 1)) . strpart(b:gifts[0], 5)

let b:day = 1
while (b:day < 12)
  echom " "
  call Nth(b:day)
  let b:gift = b:day
  while (b:gift >= 0)
    echom b:gifts[b:gift]
    let b:gift = b:gift - 1
  endwhile
  let b:day = b:day + 1
endwhile


Module Program
    Sub Main()
        Dim days = New String(11) {"first", "second", "third", "fourth", "fifth", "sixth", "seventh", "eighth", "ninth", "tenth", "eleventh", "twelfth"}
        Dim gifts = New String(11) {
            "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 i = 0 To 11
            Console.WriteLine($"On the {days(i)} day of Christmas, my true love gave to me")

            For j = i To 0 Step -1
                Console.WriteLine(gifts(j))
            Next

            Console.WriteLine()

            If i = 0 Then gifts(0) = "And a partridge in a pear tree"
        Next
    End Sub
End Module


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

for (i in 0..11) {
    System.print("On the %(days[i]) day of Christmas,")
    System.print("My true love gave to me:")
    for (j in i..0) System.print(gifts[j])
    System.print()
}


int     Day, Gift, D, G;
[Day:= [0, "first", "second", "third", "forth", "fifth", "sixth",
        "seventh", "eighth", "ninth", "tenth", "eleventh", "twelfth"];
Gift:= [0,
        "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,"];
for D:= 1 to 12 do
        [Text(0, "On the ");  Text(0, Day(D));
         Text(0, " day of Christmas
My true love gave to me:
");     for G:= D downto 1 do
                [Text(0, Gift(G));  CrLf(0)];
        CrLf(0);
        ];
]


dim day$(12), gift$(12)
for i = 1 to 12: read day$(i): next i
for i = 1 to 12: read gift$(i): next i
for i = 1 to 12
    print "On the ", day$(i), " day of Christmas,"
    print "My true love gave to me:"
    for j = i to 1 step -1: print gift$(j): next j
    print
next i
end

data "first","second","third","fourth","fifth","sixth"
data "seventh","eighth","ninth","tenth","eleventh","twelfth"
data "A partridge in a pear tree."
data "Two turtle doves and"
data "Three french hens"
data "Four calling birds"
data "Five golden rings"
data "Six geese a-laying"
data "Seven swans a-swimming"
data "Eight maids a-milking"
data "Nine ladies dancing"
data "Ten lords a-leaping"
data "Eleven pipers piping"
data "Twelve drummers drumming"


waitChar equ &BB06   ;wait for a key press
PrintChar equ &BB5A   ;print accumulator to screen

org &8000

	ld ix,VerseTable
	inc ix
	inc ix
	ld iy,SongLookup

	ld b,12          ;12 verses total
outerloop_song:
	push af          ;new line
		ld a,13
		call PrintChar
		ld a,10
		call PrintChar
	pop af
	push bc
		push ix
			ld ix,VerseTable
			ld a,(ix+0)
			ld c,a        ;get the low byte of verse ptr
			ld a,(ix+1)
			ld b,a        ;get the high byte
		pop ix
		;bc = the memory location of Verse1
		call loop_meta_PrintString
		push ix
		push iy

			ld iy,Verse0
			inc (IY+1)
			inc (IY+1)

			ld a,(IX+2)
			ld (IY+7),a
			ld a,(IX+3)
			ld (IY+8),a
		pop iy
		pop ix
		inc ix
		inc ix
	pop bc

	call WaitChar   ;wait for user to press any key before
	;continuing so they have time to read it.

	djnz outerloop_song

ReturnToBasic:
		ret

loop_meta_PrintString:
		ld a,(bc)
		or a		;compare A to 0. 0 is the null terminator for verses.
		ret z
		cp 255		;255 means "goto the verse specified after the 255"
		jr z,GotoPreviousVerse
		ld (smc_loop_meta_PrintString_alpha+2),a
		;use self modifying code to point IY's offset to the correct
		;	song line, without changing IY itself.
		inc a
		ld (smc_loop_meta_PrintString_beta+2),a
smc_loop_meta_PrintString_alpha:
		ld a,(iy+0)	;the "+0" gets clobbered with the desired lyric low byte
		ld L,a
smc_loop_meta_PrintString_beta:
		ld a,(iy+0)	;the "+0" gets clobbered with the desired lyric high byte
		ld H,a
		call PrintString	;now print the string in HL.
		inc bc
		jp loop_meta_PrintString

GotoPreviousVerse:
	inc bc		;advance past &FF opcode
	ld a,(bc)   ;get low byte
	ld e,a
	inc bc		;advance to high byte
	ld a,(bc)
	ld d,a
	push de
	pop bc
	jp loop_meta_PrintString

PrintString:
	ld a,(hl)
	or a
	ret z
	call PrintChar
	inc hl
	jr PrintString

;;;; data
VerseTable:
	word Verse0
	word Verse1
	word Verse2
	word Verse3
	word Verse4
	word Verse5
	word Verse6
	word Verse7
	word Verse8
	word Verse9
	word Verse10
	word Verse11
	word Verse12

Verse0:
	byte 2
	byte 32			;increment this by 2 after each verse.
	byte 4,56,6,56
	byte 255
	word Verse1		;look up next verse and write that here too.
					;repeat until a hardcoded 12 verses are "sung"

Verse1:
	byte 8,56,0
Verse2:
	byte 10,56,255
	word Verse1
Verse3:
	byte 12,56,255
	word Verse2
Verse4:
	byte 14,56,255
	word Verse3
Verse5:
	byte 16,56,255
	word Verse4
Verse6:
	byte 18,56,255
	word Verse5
Verse7:
	byte 20,56,255
	word Verse6
Verse8:
	byte 22,56,255
	word Verse7
Verse9:
	byte 24,56,255
	word Verse8
Verse10:
	byte 26,56,255
	word Verse9
Verse11:
	byte 28,56,255
	word Verse10
Verse12:
	byte 30,56,255
	word Verse11

SongLookup:
		word null		;0
		word Day_Part1	;2
		word Day_Part2	;4
		word Day_Part3	;6
		word Day1		;8

		word Day2		;10
		word Day3		;12
		word Day4		;14
		word Day5		;16
		word Day6		;18

		word Day7		;20
		word Day8		;22
		word Day9		;24
		word Day10		;26
		word Day11		;28

		word Day12		;30
		word First		;32
		word Second		;34
		word Third		;36
		word Fourth		;38

		word Fifth		;40
		word Sixth		;42
		word Seventh	;44
		word Eighth		;46
		word Ninth		;48
		word Tenth		;50

		word Eleventh	;52
		word Twelfth	;54

		word Song_NewLine	;56

null:
		byte 0
Day_Part1:
		byte "On the",0
Day_Part2:
		byte "day of Christmas,",0
Day_Part3:
		byte "my true love gave to me",0
Day1:
		byte "a partridge in a pear tree.",0
Day2:
		byte "two turtle doves, and",0
Day3:
		byte "three french hens",0
Day4:
		byte "four calling birds",0
Day5:
		byte "five golden rings",0
Day6:
		byte "six geese a-laying",0
Day7:
		byte "seven swans a-swimming",0
Day8:
		byte "eight maids a-milking",0
Day9:
		byte "nine ladies dancing",0
Day10:
		byte "ten lords a-leaping",0
Day11:
		byte "eleven pipers piping",0
Day12:
		byte "twelve drummers drumming",0
First:
		byte " first ",0
Second:
		byte " second ",0
Third:
		byte " third ",0
Fourth:
		byte " fourth ",0
Fifth:
		byte " fifth ",0
Sixth:
		byte " sixth ",0
Seventh:
		byte " seventh ",0
Eighth:
		byte " eighth ",0
Ninth:
		byte " ninth ",0
Tenth:
		byte " tenth ",0
Eleventh:
		byte " eleventh ",0
Twelfth:
		byte " twelfth ",0

Song_NewLine:
		byte 13,10,0		;control codes for a new line.


gifts:=
#<<<
"A beer, in a tree.; Two turtlenecks; Three french toast;
Four pounds of backbacon; Five golden touques; Six packs of two-four;
Seven packs of smokes; Eight comic books; Nine back up singers;
Ten feet of snow; Eleven hosers hosing; Twelve dozen donuts"
#<<<
.split(";").apply("strip");

days:=("first second third fourth fifth sixth seventh eighth ninth tenth "
      "eleventh twelfth").split();

foreach n,day in (days.enumerate()){ n+=1;
   g:=gifts[0,n].reverse();
   println("On the %s day of Christmas\nMy true love gave to me:\n".fmt(day),
         g[0,-1].concat("\n"), (n>1) and " and\n" or "", g[-1], "\n");
}


V out = 0
V max_out = -1
[String] max_times
L(job) File(‘mlijobs.txt’).read_lines()
   out += I ‘OUT’ C job {1} E -1
   I out > max_out
      max_out = out
      max_times.clear()
   I out == max_out
      max_times.append(job.split(‘ ’)[3])

print(‘Maximum simultaneous license use is #. at the following times:’.format(max_out))
print(‘  ’max_times.join("\n  "))


-- licenselist.adb --
-- run under GPS 4.3-5 (Sidux/Debian)
-- process rosetta.org text_processing/3 example
-- uses linked-list to hold times
with Ada.Text_IO, Ada.Integer_Text_IO, Ada.Strings.Unbounded,
     Ada.Strings.Unbounded.Text_IO,
     Ada.Containers.Doubly_Linked_Lists;
use Ada.Text_IO, Ada.Integer_Text_IO,
    Ada.Strings.Unbounded, Ada.Strings.Unbounded.Text_IO,
    Ada.Containers;

procedure licenselist is

 type logrec is record  -- define a record 'logrec' to place in a list
    logtext : String(1..19);
 end record;

 package dblist is new Doubly_Linked_Lists(logrec);
 use dblist;
       -- declare dblist as a list of logrec's
 licenselog : list;
 logtime    : logrec;
  -- to record the time of max OUT licenses

 infile : File_Type;           -- file handle
 str    : Unbounded_String;        -- input string buffer of unknown length
 outcnt, maxoutcnt : integer := 0;
 infilename : string := "license.log";

  procedure trace_times  is
  -- loop thru times list and print
     pntr : cursor := licenselog.first;
  -- pntr is of system type cursor reference to local list 'licenselog'
  begin
       new_line;
       while has_element(pntr) loop
        put(element(pntr).logtext); new_line;
        next(pntr);
       end loop;
  end trace_times;

begin -- main program --
   open ( infile,
         mode=> in_file,
         name=> infilename );

  loop
    exit when End_of_file ( infile );
    str := get_line( infile );
    if index( str, "OUT" ) > 0 then -- test if OUT record
      outcnt := outcnt +1;
    else                            -- else assume IN record
      outcnt := outcnt -1;
    end if;
    if outcnt > maxoutcnt then
         maxoutcnt := outcnt;
     logtime.logtext := slice(str,15,33); -- date_time field
         licenselog.clear;             -- reset list for new time(s)
         licenselog.append (logtime);  -- put current time into list
    elsif outcnt = maxoutcnt then
         logtime.logtext := slice(str,15,33);  -- date_time field
         licenselog.append (logtime);   -- add current time into list
    end if;  -- have to account for possibility of equal number of OUT's
  end loop;
   put("The max. number of licenses OUT is ");put(maxoutcnt,5); new_line;
   put(" at these times ");

  trace_times;
  close ( infile );
end licenselist;


PROC report = (REF FILE file in)INT: (

  MODE TIME = [19]CHAR;
  STRUCT ([3]CHAR inout, TIME time, INT jobnum) record;
  FORMAT record fmt = $"License "g" @ "g" for job "g(0)l$;

  FLEX[1]TIME max time;

  INT lic out := 0, max out := LWB max time-1, max count := LWB max time-1;
  BOOL file in ended := FALSE;
  on logical file end(file in, (REF FILE file in)BOOL: file in ended := TRUE);
  WHILE
    getf(file in, (record fmt, record));
# WHILE # NOT file in ended DO
    IF inout OF record = "OUT" THEN
      lic out +:= 1
    ELIF lic out > 0 THEN # incase license already "OUT" #
      lic out -:= 1
    FI;

    IF lic out > max out THEN
      max out := lic out;
      max count := LWB max time-1
    FI;
    IF lic out = max out THEN
      IF max count = UPB max time THEN
        [UPB max time*2]TIME new max time;
        new max time[:UPB max time] := max time;
        max time := new max time
        # ;putf(stand error, ($"increasing UPB max time (now it is "g(0)")"l$, UPB max time)); #
      FI;
      max time[max count +:= 1] := time OF record
    FI
  OD;

  printf(($"Maximum simultaneous license use is "g(0)" at the following times:"l$, max out));
  FOR lic out FROM LWB max time TO max count DO
    printf(($gl$, max time[lic out]))
  OD;

  0 EXIT
  exit report error: errno
);

INT errno;

COMMENT
  Usage:
    a68g Text_processing_3.a68 --exit Text_processing_3.dat
    a68g Text_processing_3.a68 < Text_processing_3.dat
END COMMENT

main:
(
  INT argv1 := 4;
  IF argc >= argv1 THEN
    FOR i FROM argv1 TO argc DO
      FILE file in;
      errno := open(file in, argv(i), stand in channel);
      IF errno /= 0 THEN
        putf(stand error, ($"cannot read "gl$, argv(1)));
        exit main error
      ELSE
        report(file in)
      FI;
      close(file in)
    OD
  ELSE
    report(stand in)
  FI;
  exit main error: SKIP
)


⍝  Copy/paste file's contents into TXT (easiest), or TXT ← ⎕NREAD
       I  ←  TXT[;8+⎕IO]
       D  ←  TXT[;⎕IO+14+⍳19]
       lu ←  +\ ¯1 * 'OI' ⍳ I
       mx ←  (⎕IO+⍳⍴lu)/⍨lu= max ← ⌈/ lu
       ⎕  ←  'Maximum simultaneous license use is ' , ' at the following times:' ,⍨ ⍕max ⋄ ⎕←D[mx;]


IfNotExist, mlijobs.txt
  UrlDownloadToFile, http://rosettacode.org/mlijobs.txt, mlijobs.txt

out := 0, max_out := -1, max_times := ""

Loop, Read, mlijobs.txt
{
  If InStr(A_LoopReadLine, "OUT")
    out++
  Else
    out--
  If (out > max_out)
    max_out := out, max_times := ""
  If (out = max_out)
  {
    StringSplit, lineArr, A_LoopReadLine, %A_Space%
    max_times .= lineArr4 . "`n"
  }
}

MsgBox Maximum use is %max_out% at:`n`n%max_times%


$2=="OUT" {
    count = count + 1
    time = $4
    if ( count > maxcount ) {
        maxcount = count
        maxtimes = time
    } else {
        if ( count == maxcount ) {
            maxtimes = maxtimes " and " time
        }
    }
}
$2=="IN" { count = count - 1 }
END {print "The biggest number of licenses is " maxcount " at " maxtimes " !"}


      max% = 0
      nlicence% = 0
      file% = OPENIN("mlijobs.txt")

      WHILE NOT EOF#file%
        a$ = GET$#file%
        stamp$ = MID$(a$, 15, 19)
        IF INSTR(a$, "OUT") THEN
          nlicence% += 1
          IF nlicence% > max% THEN
            max% = nlicence%
            start$ = stamp$
          ENDIF
        ENDIF
        IF INSTR(a$, "IN") THEN
          IF nlicence% = max% THEN
            finish$ = previous$
          ENDIF
          nlicence% -= 1
        ENDIF
        previous$ = stamp$
      ENDWHILE
      CLOSE #file%

      PRINT "Maximum licences checked out = " ; max%
      PRINT "From " start$ " to " finish$
      END


#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <sys/types.h>

#define INOUT_LEN 4
#define TIME_LEN 20
#define MAX_MAXOUT 1000

char inout[INOUT_LEN];
char time[TIME_LEN];
uint jobnum;

char maxtime[MAX_MAXOUT][TIME_LEN];

int main(int argc, char **argv)
{
  FILE *in = NULL;
  int l_out = 0, maxout=-1, maxcount=0;

  if ( argc > 1 ) {
    in = fopen(argv[1], "r");
    if ( in == NULL ) {
      fprintf(stderr, "cannot read %s\n", argv[1]);
      exit(1);
    }
  } else {
    in = stdin;
  }

  while( fscanf(in, "License %s @ %s for job %u\n", inout, time, &jobnum) != EOF ) {

    if ( strcmp(inout, "OUT") == 0 )
      l_out++;
    else
      l_out--;

    if ( l_out > maxout ) {
      maxout = l_out;
      maxcount=0; maxtime[0][0] = '\0';
    }
    if ( l_out == maxout ) {
      if ( maxcount < MAX_MAXOUT ) {
    strncpy(maxtime[maxcount], time, TIME_LEN);
    maxcount++;
      } else {
    fprintf(stderr, "increase MAX_MAXOUT (now it is %u)\n", MAX_MAXOUT);
    exit(1);
      }
    }
  }

  printf("Maximum simultaneous license use is %d at the following times:\n", maxout);
  for(l_out=0; l_out < maxcount; l_out++) {
    printf("%s\n", maxtime[l_out]);
  }

  if ( in != stdin ) fclose(in);
  exit(0);
}


using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.IO;

namespace TextProc3
{
    class Program
    {
        static void Main(string[] args)
        {
            string line;
            int count = 0, maxcount = 0;
            List<string> times = new List<string>();
            System.IO.StreamReader file = new StreamReader("mlijobs.txt");
            while ((line = file.ReadLine()) != null)
            {
                string[] lineelements = line.Split(' ');
                switch (lineelements[1])
                {
                    case "IN":
                        count--;
                        break;
                    case "OUT":
                        count++;
                        if (count > maxcount)
                        {
                            maxcount = count;
                            times.Clear();
                            times.Add(lineelements[3]);
                        }else if(count == maxcount){
                            times.Add(lineelements[3]);
                        }
                        break;
                }
            }
            file.Close();
            Console.WriteLine(maxcount);
            foreach (string time in times)
            {
                Console.WriteLine(time);
            }
        }
    }
}


#include <fstream>
#include <iostream>
#include <iterator>
#include <string>
#include <vector>

int main()
{
    const char logfilename[] = "mlijobs.txt";
    std::ifstream logfile(logfilename);

    if (!logfile.is_open())
    {
        std::cerr << "Error opening: " << logfilename << "\n";
        return -1;
    }

    int license = 0, max_license = 0;
    std::vector<std::string> max_timestamp;

    for (std::string logline; std::getline(logfile, logline); )
    {
        std::string action(logline.substr(8,3));

        if (action == "OUT")
        {
            if (++license >= max_license)
            {
                if (license > max_license)
                {
                    max_license = license;
                    max_timestamp.clear();
                }
                max_timestamp.push_back(logline.substr(14, 19));
            }
        }
        else if (action == "IN ")
        {
            --license;
        }
    }

    std::cout << "License count at log end: " << license
        << "\nMaximum simultaneous license: " << max_license
        << "\nMaximum license time(s):\n";

    std::copy(max_timestamp.begin(), max_timestamp.end(),
        std::ostream_iterator<std::string>(std::cout, "\n"));
}


(defn delta [entry]
  (case (second (re-find #"\ (.*)\ @" entry))
    "IN " -1
    "OUT" 1
    (throw (Exception. (str "Invalid entry:" entry)))))

(defn t [entry]
  (second (re-find #"@\ (.*)\ f" entry)))

(let [entries (clojure.string/split (slurp "mlijobs.txt") #"\n")
      in-use (reductions + (map delta entries))
      m (apply max in-use)
      times (map #(nth (map t entries) %)
                 (keep-indexed #(when (= m %2) %1) in-use))]
  (println "Maximum simultaneous license use is" m "at the following times:")
  (map println times))