WeixiangYan/CodeTransOcean huggingface dataset:
Task: The Twelve Days of Christmas





Java: 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]);
        }
    }
}






Fortran:       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
Task: The Twelve Days of Christmas







Python: gifts = .split('\n')

days = .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()))




Fortran:       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
Task: The Twelve Days of Christmas








VB: 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



Fortran:       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
Task: The Twelve Days of Christmas






PHP: <?php

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

$days = array(
    'first', 'second', 'third', 'fourth', 'fifth', 'sixth', 'seventh', 'eighth', 'ninth',
    'tenth', 'eleventh', 'twelfth',
);

$gifts = array(
    "A partridge in a pear tree",
    "Two turtle doves",
    "Three french hens",
    "Four calling birds",
    "Five golden rings",
    "Six geese a-laying",
    "Seven swans a-swimming",
    "Eight maids a-milking",
    "Nine ladies dancing",
    "Ten lords a-leaping",
    "Eleven pipers piping",
    "Twelve drummers drumming"
);

$verses = [];

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

echo implode(PHP_EOL . PHP_EOL, $verses);

?>





Fortran:       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
Task: The Twelve Days of Christmas

C: #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;
}









COBOL:        >>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.
Task: The Twelve Days of Christmas



C#: 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";
        }

    }

}







COBOL:        >>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.
Task: The Twelve Days of Christmas


C++: #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;
}








COBOL:        >>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.
Task: The Twelve Days of Christmas





Java: 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]);
        }
    }
}





COBOL:        >>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.
Task: The Twelve Days of Christmas







Python: gifts = .split('\n')

days = .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()))



COBOL:        >>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.
Task: The Twelve Days of Christmas








VB: 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


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