The Twelve Days of Christmas: Difference between revisions

→‎{{header|q}}: removed redundant iteration and variable
(Added solution for Action!)
(→‎{{header|q}}: removed redundant iteration and variable)
 
(31 intermediate revisions by 16 users not shown)
Line 14:
{{trans|Python}}
 
<langsyntaxhighlight lang="11l">V gifts = |‘A partridge in a pear tree.
Two turtle doves
Three french hens
Line 32:
V n = L.index + 1
V g = reversed(gifts[0 .< n])
print("\nOn the #. day of Christmas\nMy true love gave to me:\n".format(day)‘’g[0 .< (len)-1].join("\n")‘’(I n > 1 {" and\n"g.last} E g.last))</langsyntaxhighlight>
 
=={{header|8080 Assembly}}==
 
<langsyntaxhighlight lang="8080asm">CR: equ 13
LF: equ 10
puts: equ 9 ; CP/M function to write a string to the console
Line 109:
two: db 'Two turtle doves and',CR,LF
one: db 'A partridge in a pear tree.',CR,LF
db CR,LF,'$'</langsyntaxhighlight>
 
=={{header|8086 Assembly}}==
{{trans|8080 Assembly}}
 
<langsyntaxhighlight lang="asm">CR: equ 10
LF: equ 13
puts: equ 9 ; MS-DOS syscall to print string
Line 176:
db CR,LF,'$'
.tab: dw .n1,.n2,.n3,.n4,.n5,.n6
dw .n7,.n8,.n9,.n10,.n11,.n12</langsyntaxhighlight>
 
=={{header|Action!}}==
<langsyntaxhighlight Actionlang="action!">PROC Wait(BYTE frames)
BYTE RTCLOK=$14
frames==+RTCLOK
Line 225:
Wait(50)
OD
RETURN</langsyntaxhighlight>
{{out}}
[https://gitlab.com/amarok8bit/action-rosetta-code/-/raw/master/images/The_Twelve_Days_of_Christmas.png Screenshot from Atari 8-bit computer]
Line 262:
{{works with|Flash Player|Flash Player|10}}
{{works with|Adobe AIR|AIR|1.5}} (Although the code can work in Flash Player 9 by replacing the Vectors with Arrays)
<langsyntaxhighlight ActionScriptlang="actionscript">package {
import flash.display.Sprite;
Line 372:
}
}</langsyntaxhighlight>
 
=={{header|Ada}}==
<langsyntaxhighlight Adalang="ada">with Ada.Text_IO; use Ada.Text_IO;
with Ada.Strings.Unbounded; use Ada.Strings.Unbounded;
 
Line 411:
end loop;
end Twelve_Days_Of_Christmas;
</syntaxhighlight>
</lang>
 
=={{header|ALGOL 68}}==
{{Works with|ALGOL 68 Genie}}
<langsyntaxhighlight lang="algol68">BEGIN
[]STRING labels = ("first", "second", "third", "fourth",
"fifth", "sixth", "seventh", "eighth",
Line 440:
print(newline)
OD
END</langsyntaxhighlight>
 
{{Out}}
Line 465:
Two turtle doves, and
A partridge in a pear tree.</pre>
 
=={{header|APL}}==
{{works with|Dyalog APL}}
{{trans|Forth}}
<syntaxhighlight lang="apl">ord ← { ⍵ ⌷ 'first' 'second' 'third' 'fourth' 'fifth' 'sixth' 'seventh' 'eighth' 'ninth' 'tenth' 'eleventh' 'twelfth' }
 
gift ← { ⍵ ⌷ '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,' }
 
day ← { ⎕ ← (⎕ucs 10),'On the',(ord ⍵),'day of Christmas, my true love sent to me:' ⋄ { ⎕ ← gift ⍵ } ¨ ⌽⍳⍵ }
 
day ¨ ⍳12</syntaxhighlight>
 
{{Out}}
<pre>
On the first day of Christmas, my true love sent to me:
A partridge in a pear tree.
 
 
On the second day of Christmas, my true love sent to me:
Two turtle doves, and
A partridge in a pear tree.
 
 
On the third day of Christmas, my true love sent to me:
Three French hens,
Two turtle doves, and
A partridge in a pear tree.
 
[...]
 
On the twelfth day of Christmas, my true love sent 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 gold rings,
Four calling birds,
Three French hens,
Two turtle doves, and
A partridge in a pear tree.</pre>
 
=={{header|AppleScript}}==
===Iterative===
<langsyntaxhighlight lang="applescript">set gifts to {"A partridge in a pear tree.", "Two turtle doves, and", ¬
"Three French hens,", "Four calling birds,", ¬
"Five gold rings,", "Six geese a-laying,", ¬
Line 484 ⟶ 527:
end repeat
log ""
end repeat</langsyntaxhighlight>
 
{{Out}}
Line 515 ⟶ 558:
Drawing on some functional primitives, and post-Yosemite AppleScript's ability to import Foundation classes:
 
<langsyntaxhighlight AppleScriptlang="applescript">use framework "Foundation"
 
property pstrGifts : "A partridge in a pear tree, Two turtle doves, Three French hens, " & ¬
Line 650 ⟶ 693:
((ca's NSString's stringWithString:(str))'s ¬
uppercaseStringWithLocale:(ca's NSLocale's currentLocale())) as text
end toUpper</langsyntaxhighlight>
 
{{Out}}
Line 678 ⟶ 721:
=={{header|Arturo}}==
 
<langsyntaxhighlight lang="rebol">gifts: [
"A partridge in a pear tree."
"Two turtle doves"
Line 704 ⟶ 747:
-> capitalize last g
print ""
]</langsyntaxhighlight>
 
{{out}}
Line 823 ⟶ 866:
 
=={{header|AutoHotkey}}==
<langsyntaxhighlight AutoHotkeylang="autohotkey">nth := ["first","second","third","fourth","fifth","sixth","seventh","eighth","ninth","tenth","eleventh","twelfth"]
lines := ["A partridge in a pear tree."
,"Two turtle doves and"
Line 844 ⟶ 887:
full:= full . top . "`n" . mid . ((A_Index<lines.MaxIndex())?"`n":"")
}
MsgBox % full</langsyntaxhighlight>
 
=={{header|AWK}}==
<syntaxhighlight lang="awk">
<lang AWK>
# syntax: GAWK -f THE_TWELVE_DAYS_OF_CHRISTMAS.AWK
BEGIN {
Line 873 ⟶ 916:
exit(0)
}
</syntaxhighlight>
</lang>
{{out}}
<pre>
Line 904 ⟶ 947:
 
=={{header|Batch File}}==
<langsyntaxhighlight lang="dos">:: The Twelve Days of Christmas
:: Batch File Implementation
 
Line 953 ⟶ 996:
echo(
)
exit /b</langsyntaxhighlight>
 
=={{header|BASIC}}==
<syntaxhighlight lang="basic">10 DEFINT I,J: DEFSTR N,V: DIM N(12),V(12)
 
<lang basic>10 DEFINT I,J: DEFSTR N,V: DIM N(12),V(12)
20 FOR I=1 TO 12: READ N(I): NEXT
30 FOR I=1 TO 12: READ V(I): NEXT
Line 980 ⟶ 1,022:
210 DATA "Ten lords a-leaping"
220 DATA "Eleven pipers piping"
230 DATA "Twelve drummers drumming"</langsyntaxhighlight>
 
==={{header|Applesoft BASIC}}===
The [[#GW-BASIC|GW-BASIC]] solution works without any changes.
 
==={{header|BASIC256}}===
<syntaxhighlight lang="qbasic">dim dia$ = {"first","second","third","fourth","fifth","sixth","seventh","eighth","ninth","tenth","eleventh","twelfth"}
 
dim gift$ = {"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 = 0 to 11
print "On the "; dia$[i]; " dia of Christmas,"
print "My true love gave to me:"
for j = i to 1 step -1
print gift$[j]
next j
print
next i</syntaxhighlight>
 
==={{header|Chipmunk Basic}}===
{{works with|Chipmunk Basic|3.6.4}}
The [[#GW-BASIC|GW-BASIC]] solution works without any changes.
 
==={{header|Commodore BASIC}}===
Similar to other 8-bit BASICs shown here. This adds a delay and grammar adjustments. Color coding specific to Commodore 64/128.
<syntaxhighlight lang="gwbasic">1 rem rosetta code
2 rem twelve days of christmas
5 print chr$(14):poke 53280,13:poke 53281,1
10 dim a$(12),ex$(12):a=1
15 for i=1 to 12:read a$(i),ex$(i):next i
20 for c=1 to 12
25 print chr$(147):print chr$(30);" The Twelve Days of Christmas":print
30 print chr$(28);" On the ";a$(c);" day of Christmas":gosub 200
35 print " my true love gave to me: ":print:gosub 200
40 for bc=c to 1 step -1
45 print tab(4);
50 if c=1 then print "A ";
55 if c>1 and bc=1 then print "And a ";
60 print ex$(bc);
65 if bc=1 or bc=5 then print "!":gosub 200:gosub 200:goto 75
70 print ","
75 gosub 200
80 next bc
85 rem pause for verse change
90 print:for t=1 to 500:next t
95 next c
100 end
 
200 for t=1 to 750:next t:return:rem generic delay
 
1000 rem lyrics
1010 data "first","partridge in a pear tree"
1020 data "second","Two turtle doves"
1030 data "third","Three french hens"
1040 data "fourth","Four calling birds"
1050 data "fifth","Five golden rings"
1060 data "sixth","Six geese a-laying"
1070 data "seventh","Seven swans a-swimming"
1080 data "eighth","Eight maids a-milking"
1090 data "ninth","Nine ladies dancing"
1100 data "tenth","Ten lords a-leaping"
1110 data "eleventh","Eleven pipers piping"
1120 data "twelfth","Twelve drummers drumming"</syntaxhighlight>
 
==={{header|GW-BASIC}}===
{{works with|PC-BASIC|any}}
{{works with|BASICA}}
{{works with|Applesoft BASIC}}
{{works with|Chipmunk Basic}}
{{works with|QBasic}}
{{works with|MSX BASIC}}
{{works with|Quite BASIC}}
<syntaxhighlight lang="qbasic">100 CLS : REM 100 HOME for Applesoft BASIC
110 DIM D$(12)
120 DIM G$(12)
130 FOR I = 1 TO 12 : READ D$(I) : NEXT I
140 FOR I = 1 TO 12 : READ G$(I) : NEXT I
150 FOR I = 1 TO 12
160 PRINT "On the ";D$(I);" day of Christmas,"
170 PRINT "My true love gave to me:"
180 FOR J = I TO 1 STEP -1 : PRINT G$(J) : NEXT J
190 PRINT
200 NEXT I
210 END
220 DATA "first","second","third","fourth","fifth","sixth"
230 DATA "seventh","eighth","ninth","tenth","eleventh","twelfth"
240 DATA "A partridge in a pear tree."
250 DATA "Two turtle doves and"
260 DATA "Three french hens"
270 DATA "Four calling birds"
280 DATA "Five golden rings"
290 DATA "Six geese a-laying"
300 DATA "Seven swans a-swimming"
310 DATA "Eight maids a-milking"
320 DATA "Nine ladies dancing"
330 DATA "Ten lords a-leaping"
340 DATA "Eleven pipers piping"
350 DATA "Twelve drummers drumming"</syntaxhighlight>
 
==={{header|MSX Basic}}===
{{works with|MSX BASIC|any}}
The [[#GW-BASIC|GW-BASIC]] solution works without any changes.
 
==={{header|Quite BASIC}}===
The [[#GW-BASIC|GW-BASIC]] solution works without any changes.
 
==={{header|True BASIC}}===
{{works with|QBasic|1.1}}
{{works with|QuickBasic|4.5}}
<syntaxhighlight lang="qbasic">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</syntaxhighlight>
 
==={{header|XBasic}}===
{{works with|Windows XBasic}}
<syntaxhighlight lang="qbasic">PROGRAM "The Twelve Days of Christmas"
VERSION "0.0000"
 
DECLARE FUNCTION Entry ()
 
FUNCTION Entry ()
DIM day$[11]
day$[0] = "first"
day$[1] = "second"
day$[2] = "third"
day$[3] = "fourth"
day$[4] = "fifth"
day$[5] = "sixth"
day$[6] = "seventh"
day$[7] = "eighth"
day$[8] = "ninth"
day$[9] = "tenth"
day$[10] = "eleventh"
day$[11] = "twelfth"
 
DIM gift$[11]
gift$[0] = "A partridge in a pear tree."
gift$[1] = "Two turtle doves and"
gift$[2] = "Three french hens"
gift$[3] = "Four calling birds"
gift$[4] = "Five golden rings"
gift$[5] = "Six geese a-laying"
gift$[6] = "Seven swans a-swimming"
gift$[7] = "Eight maids a-milking"
gift$[8] = "Nine ladies dancing"
gift$[9] = "Ten lords a-leaping"
gift$[10] = "Eleven pipers piping"
gift$[11] = "Twelve drummers drumming"
 
FOR i = 0 TO 11
PRINT "On the "; day$[i]; " day of Christmas,"
PRINT "My true love gave to me:"
FOR J = i TO 0 STEP -1
PRINT gift$[J]
NEXT J
PRINT
NEXT i
END FUNCTION
END PROGRAM</syntaxhighlight>
 
==={{header|Yabasic}}===
<syntaxhighlight lang="qbasic">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"</syntaxhighlight>
 
=={{header|BCPL}}==
<langsyntaxhighlight BCPLlang="bcpl">get "libhdr"
 
let ordinal(n) =
Line 1,014 ⟶ 1,270:
$)
 
let start() be for n=1 to 12 do verse(n)</langsyntaxhighlight>
 
=={{header|Befunge}}==
This is essentially the same algorithm as [[Old_lady_swallowed_a_fly#Befunge|Old lady swallowed a fly]] - just a different set of phrases and a simpler song pattern.
<langsyntaxhighlight lang="befunge">0246*+00p20#v_:#`2#g+#0:#0<>\#%"O"/#:3#:+#< g48*- >1-:!#v_\1+::"O"%\"O"/v
>-#11#\0#50#< g2-:00p4v >\#%"O"/#::$#<3#$+g48*-v^\,+*+ 55!:*!!-"|":g+3<
^02_>#`>#< 2 5 3 1 0 \1-:#^\_^#:-1\+<00_@#:>#<$<
Line 1,026 ⟶ 1,282:
-swimming(seventh7|Eight maids a-milking'eighth5|Nine ladies dancing&ninth5|Ten
lords a-leaping&tenth6|Eleven pipers piping)eleventh:|Twelve drummers drumming
(twelfth</langsyntaxhighlight>
 
=={{header|Bracmat}}==
<langsyntaxhighlight lang="bracmat">( first
second
third
Line 1,066 ⟶ 1,322:
)
)
);</langsyntaxhighlight>
 
=={{header|C}}==
<syntaxhighlight lang="c">
<lang C>
#include<stdio.h>
Line 1,119 ⟶ 1,375:
return 0;
}</langsyntaxhighlight>
 
=={{header|C sharp|C#}}==
<langsyntaxhighlight lang="csharp">using System;
 
public class TwelveDaysOfChristmas {
Line 1,164 ⟶ 1,420:
}
 
}</langsyntaxhighlight>
 
=={{header|C++}}==
<langsyntaxhighlight lang="cpp">#include <iostream>
#include <array>
#include <string>
Line 1,224 ⟶ 1,480:
 
return 0;
}</langsyntaxhighlight>
 
=={{header|Clojure}}==
{{trans|Raku}}
<langsyntaxhighlight lang="clojure">(let
[numbers '(first second third fourth fifth sixth
seventh eighth ninth tenth eleventh twelfth)
Line 1,250 ⟶ 1,506:
(dorun (for [n (range d -1 -1)]
(println (nth gifts n))))))))
</syntaxhighlight>
</lang>
{{Out}}
<pre>On the first day of Christmas, my true love sent to me:
Line 1,276 ⟶ 1,532:
 
=={{header|CLU}}==
<langsyntaxhighlight lang="clu">christmas = cluster is carol
rep = null
Line 1,318 ⟶ 1,574:
start_up = proc ()
christmas$carol(stream$primary_output())
end start_up</langsyntaxhighlight>
 
=={{header|COBOL}}==
{{works with|GNU Cobol|2.0}}
<langsyntaxhighlight lang="cobol"> >>SOURCE FREE
PROGRAM-ID. twelve-days-of-christmas.
 
Line 1,365 ⟶ 1,621:
END-PERFORM
.
END PROGRAM twelve-days-of-christmas.</langsyntaxhighlight>
 
=={{header|Common Lisp}}==
 
<langsyntaxhighlight lang="lisp">let
((gifts '("A partridge in a pear tree." "Two turtle doves, and"
"Three French hens," "Four calling birds,"
Line 1,382 ⟶ 1,638:
(format t "~a~%" (nth gift gifts)))
(format t "~%")))
</syntaxhighlight>
</lang>
 
{{Out}}
Line 1,409 ⟶ 1,665:
 
=={{header|Cowgol}}==
<langsyntaxhighlight lang="cowgol">include "cowgol.coh";
 
var ordinals: [uint8][] := {
Line 1,446 ⟶ 1,702:
print_nl();
verse := verse + 1;
end loop;</langsyntaxhighlight>
 
=={{header|Crystal}}==
{{trans|Ruby}}
<langsyntaxhighlight lang="ruby">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
Line 1,468 ⟶ 1,724:
gifts[0, i + 1].reverse.each &->puts(String)
puts
end</langsyntaxhighlight>
 
=={{header|D}}==
{{trans|Python}}
<langsyntaxhighlight lang="d">immutable gifts =
"A partridge in a pear tree.
Two turtle doves
Line 1,500 ⟶ 1,756:
(n > 0 ? " and\n" ~ g.back : g.back.capitalize), '\n');
}
}</langsyntaxhighlight>
 
=={{header|dc}}==
<langsyntaxhighlight lang="dc">0
 
d [first] r :n
Line 1,569 ⟶ 1,825:
 
0 ll x
</syntaxhighlight>
</lang>
 
{{Out}}
Line 1,594 ⟶ 1,850:
Two turtle doves and
A partridge in a pear tree.</pre>
 
=={{header|Delphi}}==
{{works with|Delphi|6.0}}
{{libheader|SysUtils,StdCtrls}}
 
 
<syntaxhighlight lang="Delphi">
 
 
const GiftList: array [0..11] of string =(
'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');
 
const Cardinals: array [0..11] of string =
('first','second','third','forth',
'fifth','sixth','seventh','eight',
'ninth','tenth','eleventh','twelfth');
 
procedure DoOneDay(Memo: TMemo; Day: integer);
var S: string;
var I: integer;
begin
S:='On the '+Cardinals[Day]+' of Christmas ';
S:=S+'my true love gave to me'+CRLF;
for I:=Day downto 0 do
begin
if (Day>0) and (I=0) then S:=S+'and ';
S:=S+GiftList[I]+CRLF;
end;
Memo.Lines.Add(S);
end;
 
procedure TwelveDaysOfChristmas(Memo: TMemo);
var I: integer;
begin
for I:=0 to 12-1 do DoOneDay(Memo,I);
end;
 
 
</syntaxhighlight>
{{out}}
<pre>
On the first of Christmas my true love gave to me
a partridge in a pear tree.
 
On the second of Christmas my true love gave to me
Two turtle doves
and a partridge in a pear tree.
 
On the third of Christmas my true love gave to me
Three french hens
Two turtle doves
and a partridge in a pear tree.
 
On the forth 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 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 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 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 eight 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 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 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 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 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.
Elapsed Time: 34.088 ms.
</pre>
 
 
=={{header|Dyalect}}==
<langsyntaxhighlight lang="dyalect">let days = [
"first", "second", "third", "fourth", "fifth", "sixth", "seventh", "eighth", "ninth",
"tenth", "eleventh", "twelfth"
Line 1,621 ⟶ 2,033:
}
print()
}</langsyntaxhighlight>
 
=={{header|EasyLang}}==
<syntaxhighlight lang="easylang">
days$[] = [ "first" "second" "third" "forth" "fifth" "sixth" "seventh" "eighth" "ninth" "tenth" "eleventh" "twelfth" ]
gifts$[] &= "Twelve drummers drumming"
gifts$[] &= "Eleven pipers piping"
gifts$[] &= "Ten lords a-leaping"
gifts$[] &= "Nine ladies dancing"
gifts$[] &= "Eight maids a-milking"
gifts$[] &= "Seven swans a-swimming"
gifts$[] &= "Six geese a-laying"
gifts$[] &= "Five golden rings"
gifts$[] &= "Four calling birds"
gifts$[] &= "Three french hens"
gifts$[] &= "Two turtle doves and"
gifts$[] &= "A partridge in a pear tree."
for i = 1 to 12
print "On the " & days$[i] & " day of Christmas,"
print "My true love gave to me:"
for j = 13 - i to 12
print gifts$[j]
.
print ""
.
</syntaxhighlight>
 
=={{header|Eiffel}}==
<syntaxhighlight lang="eiffel">
<lang Eiffel>
class
APPLICATION
Line 1,680 ⟶ 2,117:
 
end
</syntaxhighlight>
</lang>
 
=={{header|Elena}}==
{{trans|C++}}
ELENA 56.0x :
<langsyntaxhighlight lang="elena">import extensions;
public program()
Line 1,709 ⟶ 2,146:
};
for(int i := 0,; i < 12,; i += 1)
{
console.printLine("On the ", days[i], " day of Christmas, my true love gave to me");
Line 1,719 ⟶ 2,156:
else
{
for(int j := i,; j >= 0,; j -= 1)
{
console.printLine(gifts[j])
Line 1,727 ⟶ 2,164:
console.printLine()
}
}</langsyntaxhighlight>
 
=={{header|Elixir}}==
<langsyntaxhighlight lang="elixir">gifts = """
A partridge in a pear tree
Two turtle doves and
Line 1,752 ⟶ 2,189:
Enum.take(gifts, i+1) |> Enum.reverse |> Enum.each(&IO.puts &1)
IO.puts ""
end)</langsyntaxhighlight>
 
{{out}}
Line 1,783 ⟶ 2,220:
 
=={{header|Erlang}}==
<langsyntaxhighlight lang="erlang">-module(twelve_days).
-export([gifts_for_day/1]).
 
Line 1,803 ⟶ 2,240:
main(_) -> lists:map(fun(N) -> io:fwrite("~s~n~n", [gifts_for_day(N)]) end,
lists:seq(1,12)).
</syntaxhighlight>
</lang>
{{Out}}<pre>On the first day of Christmas, my true love sent to me:
A partridge in a pear tree.
Line 1,828 ⟶ 2,265:
 
=={{header|F Sharp|F#}}==
<langsyntaxhighlight lang="fsharp">let gifts = [
"And a partridge in a pear tree";
"Two turtle doves";
Line 1,856 ⟶ 2,293:
printf "\n"
List.iter displayGifts [0..11]</langsyntaxhighlight>
 
=={{header|Factor}}==
<langsyntaxhighlight lang="factor">USING: formatting io kernel math math.ranges qw sequences ;
IN: rosetta-code.twelve-days-of-christmas
 
Line 1,892 ⟶ 2,329:
: twelve-days-of-christmas ( -- ) 12 [1,b] [ verse ] each ;
 
MAIN: twelve-days-of-christmas</langsyntaxhighlight>
{{out}}
<pre>
Line 1,916 ⟶ 2,353:
Three french hens,
Two turtle doves, and
A partridge in a pear tree.
</pre>
 
=={{header|Fish}}==
<syntaxhighlight lang="fish">> 0 7 . (0,0): Vector. Jumps to main, then used for sub returns
> 0 f 5 + . (0,1): Print a NUL-terminated string
> 6 6 * 9 + f 8 + . (0,2): Pop N, push Nth (e.g. 1 -> "first")
> 0 f 8 + . (0,3): Pop N, push gift countdown starting from N.
> 0 f 1 + . (0,4): Jump to line in range 16-30
 
main:
> 1 \
/ a "On the " 0 <
\ "a" 4 0 p 0 1 .
> "b" 4 0 p : 0 2 .
> "c" 4 0 p 0 1 .
> \
/ " day of Christmas, my true love sent to me:" a 0 /
> "f" 4 0 p 0 1 .
> "1" 6 4 p "4" 4 0 p : 0 3 .
> "2" 6 4 p 0 1 .
> 1 + : c ) ?\ /
;
 
> : ?\ ~ 0 0 .
\ o / > 0 0 .
^ "first" 0 ~ \
> \ > 1 - : ?\ /
/ "A partridge in a pear tree." a 0 & < / / ^ "second" 0 ~ \
\ & 1 - : ?\ ~ 0 0 . \ 1 - : ?\ /
\ \ / / ^ "third" 0 ~ \
/ "Two turtle doves and" a & / \ 1 - : ?\ /
\ & 1 - : ?\ ~ 0 0 . / / ^ "fourth" 0 ~ \
\ \ \ 1 - : ?\ /
/ "Three French hens," a & / / / ^ "fifth" 0 ~ \
\ & 1 - : ?\ ~ 0 0 . \ 1 - : ?\ /
\ \ / / ^ "sixth" 0 ~ \
/ "Four calling birds," a & / \ 1 - : ?\ /
\ & 1 - : ?\ ~ 0 0 . / / ^ "seventh" 0 ~ \
\ \ \ 1 - : ?\ /
/ "Five gold rings," a & / / / ^ "eighth" 0 ~ \
\ & 1 - : ?\ ~ 0 0 . \ 1 - : ?\ /
\ \ / / ^ "ninth" 0 ~ \
/ "Six geese a-laying," a & / \ 1 - : ?\ /
\ & 1 - : ?\ ~ 0 0 . / / ^ "tenth" 0 ~ \
\ \ \ 1 - : ?\ /
/ "Seven swans a-swimming," a & / / / ^ "eleventh" 0 ~ \
\ & 1 - : ?\ ~ 0 0 . \ 1 - : ?\ /
\ \ \ \
/ "Eight maids a-milking," a & / ^ "twelfth" 0 ~ /
\ & 1 - : ?\ ~ 0 0 .
\ \
/ "Nine ladies dancing," a & /
\ & 1 - : ?\ ~ 0 0 .
\ \
/ "Ten lords a-leaping," a & /
\ & 1 - : ?\ ~ 0 0 .
\ \
/ "Eleven pipers piping," a & /
\ & 1 - : ?\ ~ 0 0 .
\ \
/ "Twelve drummers drumming," a & /
\ & ~ 0 0 .</syntaxhighlight>
{{Out}}
<pre>
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 gold rings,
Four calling birds,
Three French hens,
Two turtle doves and
A partridge in a pear tree.
</pre>
Line 1,921 ⟶ 2,445:
=={{header|Forth}}==
{{works with|GNU Forth}}
<langsyntaxhighlight lang="forth">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,
Line 1,957 ⟶ 2,481:
main
bye
</syntaxhighlight>
</lang>
 
{{Out}}
Line 1,985 ⟶ 2,509:
=={{header|Fortran}}==
{{works with|Fortran|FORTRAN|77}}
<langsyntaxhighlight lang="fortran"> program twelve_days
 
character days(12)*8
Line 2,017 ⟶ 2,541:
10 continue
end
</syntaxhighlight>
</lang>
 
{{Out}}
Line 2,044 ⟶ 2,568:
 
=={{header|FreeBASIC}}==
<langsyntaxhighlight lang="freebasic">' version 10-01-2017
' compile with: fbc -s console
 
Line 2,079 ⟶ 2,603:
Print : 'Print "hit any key to end program"
Sleep
End</langsyntaxhighlight>
{{out}}
<pre> On the first day of Christmas
Line 2,109 ⟶ 2,633:
=={{header|Go}}==
[https://play.golang.org/p/dnDyx8ee_G Go Playground]
<langsyntaxhighlight lang="go">package main
 
import (
Line 2,134 ⟶ 2,658:
}
}
</syntaxhighlight>
</lang>
 
=={{header|Groovy}}==
<langsyntaxhighlight lang="groovy">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']
Line 2,148 ⟶ 2,672:
}
println()
}</langsyntaxhighlight>
 
=={{header|Haskell}}==
{{trans|F#}}
<langsyntaxhighlight lang="haskell">gifts :: [String]
gifts =
[ "And a partridge in a pear tree!",
Line 2,196 ⟶ 2,720:
 
main :: IO ()
main = mapM_ verseOfTheDay [0 .. 11]</langsyntaxhighlight>
{{out}}
<pre style="font-size:80%">On the first day of Christmas my true love gave to me...
Line 2,303 ⟶ 2,827:
 
Works in both languages.
<langsyntaxhighlight lang="unicon">procedure main()
days := ["first","second","third","fourth","fifth","sixth","seventh",
"eighth","ninth","tenth","eleventh","twelveth"]
Line 2,315 ⟶ 2,839:
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</langsyntaxhighlight>
 
=={{header|J}}==
<langsyntaxhighlight lang="j">require 'strings' NB. not necessary for versions > j6
 
days=: ;:'first second third fourth fifth sixth seventh eighth ninth tenth eleventh twelfth'
Line 2,343 ⟶ 2,867:
makeVerses=: [: chgFirstVerse (firstline&.> days) ,&.> [: <@;@|.\ gifts"_
 
singCarol=: LF joinstring makeVerses</langsyntaxhighlight>
 
=={{header|Janet}}==
<syntaxhighlight lang="janet">(def days ["first" "second" "third"
"fourth" "fifth" "sixth"
"seventh" "eighth" "ninth"
"tenth" "eleventh" "twelfth"])
(def 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"])
(var v "")
(eachp [i d] days
(print "On the " d " day of Christmas")
(print "My true love gave to me")
(set v (string (in gifts i) "\n" v))
(print v))</syntaxhighlight>
 
=={{header|Java}}==
<langsyntaxhighlight lang="java">public class TwelveDaysOfChristmas {
 
final static String[] gifts = {
Line 2,371 ⟶ 2,919:
}
}
}</langsyntaxhighlight>
 
=={{header|JavaScript}}==
<syntaxhighlight lang="javascript">
<lang JavaScript>
var days = [
'first', 'second', 'third', 'fourth', 'fifth', 'sixth', 'seventh', 'eighth', 'ninth',
Line 2,417 ⟶ 2,965:
song = verses.join('\n\n');
document.write(song);
</syntaxhighlight>
</lang>
 
 
Alternatively, in a functional style of JavaScript, we can define the ancient song "strPrepn the lstOrdinal[i] strUnit of strHoliday" as an expression, and return that expression in a human-legible and machine-parseable JSON string translation, for further analysis and processing :-)
 
<langsyntaxhighlight JavaScriptlang="javascript">JSON.stringify(
(function (
strPrepn,
Line 2,496 ⟶ 3,044:
'On', 'Christmas', 'day', 'my true love', 'gave to', 'me'
), null, 2
);</langsyntaxhighlight>
 
Note that the Google Closure compiler's translation of this would be half the size, but rather less legible.
(It does make interesting suggestions though – the semi-colon segmentation of the verses below is a trick that might be worth remembering).
 
<langsyntaxhighlight JavaScriptlang="javascript">JSON.stringify(function (h, k, l, f, m, n) {
var c =
"first second third fourth fifth sixth seventh eighth ninth tenth eleventh twelfth"
Line 2,522 ⟶ 3,070:
0 : 1)))]);
}, []);
}("On", "Christmas", "day", "my true love", "gave to", "me"), null, 2);</langsyntaxhighlight>
 
Formatted JSON output (the expanded and Closure-compiled versions above both yield the same output).
 
<syntaxhighlight lang="javascript">[
<lang JavaScript>[
[
"On the first day of Christmas",
Line 2,565 ⟶ 3,113:
//... etc.
 
]</langsyntaxhighlight>
 
=={{header|jq}}==
<langsyntaxhighlight lang="jq">[ "one", "two", "three", "four", "five", "six",
"seven", "eight", "nine", "ten", "eleven", "twelve"] as $cardinals
| [ "first", "second", "third", "fourth", "fifth", "sixth",
Line 2,582 ⟶ 3,130:
" " + $gifts[$j] + if $j > 0 then "," else "\n" end]
| join("\n"))
</syntaxhighlight>
</lang>
 
Run with <pre>jq -rnf programfile.jq</pre> to yield this result:
Line 2,619 ⟶ 3,167:
=={{header|Jsish}}==
Based on Javascript entry, almost identical, added unitTest.
<langsyntaxhighlight lang="javascript">#!/usr/bin/env jsish
"use strict";
 
Line 2,767 ⟶ 3,315:
And a partridge in a pear tree
=!EXPECTEND!=
*/</langsyntaxhighlight>
 
{{out}}
Line 2,775 ⟶ 3,323:
 
=={{header|Julia}}==
<langsyntaxhighlight lang="julia"># v0.6.0
 
function printlyrics()
Line 2,807 ⟶ 3,355:
end
 
printlyrics()</langsyntaxhighlight>
 
{{out}}
Line 2,838 ⟶ 3,386:
=={{header|Kotlin}}==
{{trans|C#}}
<langsyntaxhighlight lang="scala">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"
Line 2,858 ⟶ 3,406:
 
Day.values().forEachIndexed { i, d -> println(d.header + gifts.slice(0..i).asReversed().joinToString("\n\t")) }
}</langsyntaxhighlight>
 
=={{header|Lambdatalk}}==
<langsyntaxhighlight lang="scheme">
{def days
first second third fourth fifth sixth
Line 2,913 ⟶ 3,461:
Two turtle doves and
A partridge in a pear tree.
</syntaxhighlight>
</lang>
 
=={{header|Logo}}==
 
<langsyntaxhighlight lang="logo">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]
Line 2,937 ⟶ 3,485:
]
]
bye</langsyntaxhighlight>
 
{{Out}}
Line 2,966 ⟶ 3,514:
=={{header|LOLCODE}}==
{{works with|LCI 0.10}}
<syntaxhighlight lang="text">HAI 1.2
<lang>CAN HAS STDIO?
CAN HAS STDIO?
HAI 1.2
 
I HAS A Dayz ITZ A BUKKIT
Line 3,018 ⟶ 3,566:
IM OUTTA YR Outer
KTHXBYE</langsyntaxhighlight>
 
{{Out}}
Line 3,046 ⟶ 3,594:
 
=={{header|Lua}}==
<syntaxhighlight lang="lua">
<lang Lua>
local days = {
'first', 'second', 'third', 'fourth', 'fifth', 'sixth', 'seventh', 'eighth', 'ninth',
Line 3,085 ⟶ 3,633:
 
print(table.concat(verses, '\n\n'))
</syntaxhighlight>
</lang>
 
=={{header|MADMACRO-11}}==
<syntaxhighlight lang="macro11"> .TITLE CAROL
.MCALL .TTYOUT,.EXIT
CAROL:: CLR R5
1$: MOV #ONTHE,R1
JSR PC,PRINT
MOV ORDTAB(R5),R1
JSR PC,PRINT
MOV #DAYOF,R1
JSR PC,PRINT
MOV VRSTAB(R5),R1
JSR PC,PRINT
ADD #2,R5
CMP R5,#^D24
BLT 1$
.EXIT
 
PRINT: MOVB (R1)+,R0
<lang MAD> NORMAL MODE IS INTEGER
.TTYOUT
BNE PRINT
RTS PC
 
ONTHE: .ASCIZ /On the /
ORDTAB: .WORD 1$,2$,3$,4$,5$,6$,7$,8$,9$,10$,11$,12$
1$: .ASCIZ /first/
2$: .ASCIZ /second/
3$: .ASCIZ /third/
4$: .ASCIZ /fourth/
5$: .ASCIZ /fifth/
6$: .ASCIZ /sixth/
7$: .ASCIZ /seventh/
8$: .ASCIZ /eighth/
9$: .ASCIZ /ninth/
10$: .ASCIZ /tenth/
11$: .ASCIZ /eleventh/
12$: .ASCIZ /twelfth/
DAYOF: .ASCIZ / day of Christmas, my true love gave to me:/<15><12>
VRSTAB: .WORD 1$,2$,3$,4$,5$,6$,7$,8$,9$,10$,11$,12$
12$: .ASCII /Twelve drummers drumming/<15><12>
11$: .ASCII /Eleven pipers piping/<15><12>
10$: .ASCII /Ten lords a-leaping/<15><12>
9$: .ASCII /Nine ladies dancing/<15><12>
8$: .ASCII /Eight maids a-milking/<15><12>
7$: .ASCII /Seven swans a-swimming/<15><12>
6$: .ASCII /Six geese a-laying/<15><12>
5$: .ASCII /Five golden rings/<15><12>
4$: .ASCII /Four calling birds/<15><12>
3$: .ASCII /Three French hens/<15><12>
2$: .ASCII /Two turtle doves, and/<15><12>
1$: .ASCIZ /A partridge in a pear tree./<15><12><15><12>
.END CAROL</syntaxhighlight>
 
 
=={{header|MAD}}==
<syntaxhighlight lang="mad"> NORMAL MODE IS INTEGER
THROUGH VERSE, FOR I=1, 1, I.G.12
Line 3,129 ⟶ 3,729:
VECTOR VALUES MT = $*$
END OF PROGRAM
</syntaxhighlight>
</lang>
 
=={{header|Maple}}==
<langsyntaxhighlight lang="maple">gifts := ["Twelve drummers drumming",
"Eleven pipers piping", "Ten lords a-leaping",
"Nine ladies dancing", "Eight maids a-milking",
Line 3,146 ⟶ 3,746:
end do;
printf("\n");
end do;</langsyntaxhighlight>
{{out}}
<pre>
Line 3,197 ⟶ 3,797:
 
=={{header|Mathematica}}/{{header|Wolfram Language}}==
<langsyntaxhighlight Mathematicalang="mathematica">daysarray = {"first", "second", "third", "fourth", "fifth", "sixth",
"seventh", "eighth", "ninth", "tenth", "eleventh", "twelfth"};
giftsarray = {"And a partridge in a pear tree.", "Two turtle doves",
Line 3,209 ⟶ 3,809:
daysarray[[i]],
If[i == 1, "A partridge in a pear tree.",
Row[Reverse[Take[giftsarray, i]], ","]]]], {i, 1, 12}]</langsyntaxhighlight>
{{out}}
<pre style="height:55ex;overflow:scroll">
Line 3,315 ⟶ 3,915:
 
=={{header|MiniScript}}==
<langsyntaxhighlight MiniScriptlang="miniscript">days = ["first","second","third", "fourth","fifth","sixth",
"seventh","eigth","nineth","tenth","eleventh","twelfth"]
gifts = ["A partridge in a pear tree.","Two turtle doves, and",
Line 3,332 ⟶ 3,932:
print " ----------"
end for
</syntaxhighlight>
</lang>
{{out}}
<pre>
Line 3,361 ⟶ 3,961:
=={{header|Nim}}==
{{trans|Python}}
<langsyntaxhighlight lang="nim">import strutils, algorithm
 
const
Line 3,383 ⟶ 3,983:
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])</langsyntaxhighlight>
 
{{out}}
Line 3,414 ⟶ 4,014:
=={{header|Objeck}}==
{{trans|C sharp|C#}}
<langsyntaxhighlight lang="objeck">
class TwelveDaysOfChristmas {
function : Main(args : String[]) ~ Nil {
Line 3,450 ⟶ 4,050:
}
}
</syntaxhighlight>
</lang>
 
=={{header|PARI/GP}}==
<langsyntaxhighlight lang="parigp">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"];
{
Line 3,461 ⟶ 4,061:
print(if(i==1,"\tA partridge in a pear tree.",Str("\t",gifts[1])))
)
}</langsyntaxhighlight>
{{out}}
<pre>On the first day of Christmas, my true love gave to me:
Line 3,486 ⟶ 4,086:
This should work with any modern Pascal implementation that has a '''string''' type, e.g. [[Free Pascal]].
 
<langsyntaxhighlight lang="pascal">program twelve_days(output);
 
const
Line 3,517 ⟶ 4,117:
writeln
end
end.</langsyntaxhighlight>
{{Out}}
<pre>On the first day of Christmas, my true love sent to me:
Line 3,544 ⟶ 4,144:
Here's a version that works in ISO Standard Pascal, albeit with extraneous spaces in the output:
 
<langsyntaxhighlight lang="pascal">program twelve_days_iso(output);
 
const
Line 3,576 ⟶ 4,176:
writeln
end
end.</langsyntaxhighlight>
 
{{Out}}
Line 3,603 ⟶ 4,203:
 
=={{header|Perl}}==
<langsyntaxhighlight lang="perl">use v5.10;
 
my @days = qw{ first second third fourth fifth sixth seventh eighth ninth tenth eleventh twelfth };
Line 3,627 ⟶ 4,227:
Three french hens
Two turtle doves
And a partridge in a pear tree.</langsyntaxhighlight>
{{out}}
<pre>On the first day of Christmas,
Line 3,656 ⟶ 4,256:
 
=={{header|Phix}}==
<!--<langsyntaxhighlight Phixlang="phix">(phixonline)-->
<span style="color: #008080;">constant</span> <span style="color: #000000;">days</span> <span style="color: #0000FF;">=</span> <span style="color: #0000FF;">{</span><span style="color: #008000;">"first"</span><span style="color: #0000FF;">,</span> <span style="color: #008000;">"second"</span><span style="color: #0000FF;">,</span> <span style="color: #008000;">"third"</span><span style="color: #0000FF;">,</span> <span style="color: #008000;">"fourth"</span><span style="color: #0000FF;">,</span> <span style="color: #008000;">"fifth"</span><span style="color: #0000FF;">,</span> <span style="color: #008000;">"sixth"</span><span style="color: #0000FF;">,</span>
<span style="color: #008000;">"seventh"</span><span style="color: #0000FF;">,</span> <span style="color: #008000;">"eighth"</span><span style="color: #0000FF;">,</span> <span style="color: #008000;">"ninth"</span><span style="color: #0000FF;">,</span> <span style="color: #008000;">"tenth"</span><span style="color: #0000FF;">,</span> <span style="color: #008000;">"eleventh"</span><span style="color: #0000FF;">,</span> <span style="color: #008000;">"twelfth"</span><span style="color: #0000FF;">},</span>
Line 3,677 ⟶ 4,277:
<span style="color: #008080;">end</span> <span style="color: #008080;">for</span>
<span style="color: #008080;">end</span> <span style="color: #008080;">for</span>
<!--</langsyntaxhighlight>-->
 
=={{header|Phixmonti}}==
<langsyntaxhighlight Phixmontilang="phixmonti">include ..\Utilitys.pmt
 
( "A partridge in a pear tree."
Line 3,709 ⟶ 4,309:
swap
nl
endfor</langsyntaxhighlight>
 
=={{header|PHP}}==
<syntaxhighlight lang="php">
<lang PHP>
<?php
 
Line 3,759 ⟶ 4,359:
 
?>
</syntaxhighlight>
</lang>
 
Or using recursion:
 
<langsyntaxhighlight PHPlang="php"><?php
 
$gifts = array(
Line 3,797 ⟶ 4,397:
twelve_days( array_reverse( $gifts, true ) );
 
</syntaxhighlight>
</lang>
{{Out}}
<pre style="font-size:84%;height:55ex">
Line 3,902 ⟶ 4,502:
A partridge in a pear tree
</pre>
 
=={{header|Picat}}==
===List comprehension===
<syntaxhighlight lang="picat">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.</syntaxhighlight>
 
===Definite clause grammars (DCG)===
<syntaxhighlight lang="picat">go2 ?=>
lyrics(Ls,[]),
println(Ls.flatten),
nl.
go2 => true.
 
lyrics -->
{ Days = findall(D, $day(D,_,[])) },
stanzas(Days, []).
 
stanzas([], _) --> [].
stanzas([Day|Days], Prevs) -->
"On the ", [Day.to_string], " day of Christmas\n", % convert atom day to string
"My true love gave to me:\n",
day(Day),
previous_days(Prevs),
"\n\n",
stanzas(Days, [Day|Prevs]).
 
previous_days([]) --> [].
previous_days([D|Ds]) --> previous_days_(Ds, D).
 
previous_days_([], D) --> " and\n", day(D).
previous_days_([D|Ds], Prev) --> "\n",
day(Prev),
previous_days_(Ds, D).
 
day(first) --> "A partridge in a pear tree.".
day(second) --> "Two turtle doves".
day(third) --> "Three french hens".
day(fourth) --> "Four calling birds".
day(fifth) --> "Five golden rings".
day(sixth) --> "Six geese a-laying".
day(seventh) --> "Seven swans a-swimming".
day(eight) --> "Eight maids a-milking".
day(ninth) --> "Nine ladies dancing".
day(tenth) --> "Ten lords a-leaping".
day(eleventh) --> "Eleven pipers piping".
day(twelth) --> "Twelve drummers drumming".</syntaxhighlight>
 
=={{header|PicoLisp}}==
<langsyntaxhighlight PicoLisplang="picolisp">(de days
first second third fourth fifth sixth
seventh eight ninth tenth eleventh twelfth )
Line 3,932 ⟶ 4,596:
(prinl) )
 
(bye)</langsyntaxhighlight>
 
=={{header|Pike}}==
<syntaxhighlight lang="pike">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;
}</syntaxhighlight>
{{out}}
<pre>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.</pre>
 
=={{header|Pointless}}==
<syntaxhighlight lang="pointless">
output =
range(1, 12)
|> map(makeVerse)
|> join("\n\n")
|> print
 
days = {
1: "first",
2: "second",
3: "third",
4: "fourth",
5: "fifth",
6: "sixth",
7: "seventh",
8: "eighth",
9: "ninth",
10: "tenth",
11: "eleventh",
12: "twelfth"
}
 
verseFormat = """On the {} day of Christmas
My true love gave to me:
{}"""
 
makeVerse(n) =
format(verseFormat,
[getDefault(days, "", n),
makeGifts(n)])
 
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",
]
 
makeGifts(n) =
gifts
|> take(n)
|> reverse
|> join("\n")
</syntaxhighlight>
 
=={{header|PowerShell}}==
<langsyntaxhighlight PowerShelllang="powershell">$days = @{
1 = "first";
2 = "second";
Line 3,973 ⟶ 4,735:
}
""
}</langsyntaxhighlight>
 
{{out}}
Line 4,002 ⟶ 4,764:
A partridge in a pear tree
</pre>
 
=={{header|Prog8}}==
<syntaxhighlight lang="prog8">%zeropage basicsafe
%import textio
 
main {
str[12] ordinals = [ "first", "second", "third", "fourth",
"fifth", "sixth", "seventh", "eighth",
"ninth", "tenth", "eleventh", "twelfth" ]
 
str[12] 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," ]
 
sub print_gifts(ubyte day) {
ubyte i
txt.print("On the ")
txt.print(ordinals[day])
txt.print(" day of Christmas, my true love sent to me:")
txt.nl()
for i in day to 0 step -1 {
txt.print(gifts[i])
txt.nl()
}
}
 
sub start() {
ubyte day
 
txt.lowercase()
for day in 0 to 11 {
txt.nl()
print_gifts(day)
}
}
}</syntaxhighlight>
 
{{Out}}
<pre>On the first day of Christmas, my true love sent to me:
A partridge in a pear tree.
 
On the second day of Christmas, my true love sent to me:
Two turtle doves and
A partridge in a pear tree.
 
[ ... ]
 
On the twelfth day of Christmas, my true love sent 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 gold rings,
Four calling birds,
Three French hens,
Two turtle doves and
A partridge in a pear tree.</pre>
 
=={{header|Prolog}}==
<langsyntaxhighlight lang="prolog">day(1, 'first').
day(2, 'second').
day(3, 'third').
Line 4,045 ⟶ 4,876:
writeLoop(N) :- Day is 13 - N, writeGifts(Day), M is N - 1, writeLoop(M).
 
main :- writeLoop(12), halt.</langsyntaxhighlight>
 
{{Out}}
Line 4,055 ⟶ 4,886:
A partridge in a pear tree.
 
[ ... ]
 
On the twelfth day of Christmas, my true love sent to me:
Line 4,072 ⟶ 4,903:
 
=={{header|PureBasic}}==
<langsyntaxhighlight PureBasiclang="purebasic">#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"+
Line 4,087 ⟶ 4,918:
Next I
Input()
EndIf</langsyntaxhighlight>
{{out}}
<pre>On the first day of Christmas, my true love sent to me:
Line 4,124 ⟶ 4,955:
 
=={{header|Python}}==
<langsyntaxhighlight lang="python">gifts = '''\
A partridge in a pear tree.
Two turtle doves
Line 4,146 ⟶ 4,977:
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()))</langsyntaxhighlight>
 
{{out}}
Line 4,190 ⟶ 5,021:
 
=={{header|q}}==
<syntaxhighlight lang="q">
<lang q>
daysDAYS:" "vs"first second third fourth fifth sixth seventh eighth ninth tenth eleventh twelfth",
" seventh eighth ninth tenth eleventh twelfth"
 
STANZA:( / final stanza
gifts:(
"On the twelfth day of Christmas";
"My true love gave to me:";
"Twelve drummers drumming";
"Eleven pipers piping";
Line 4,208 ⟶ 5,042:
"")
 
-1 raze
verses:stanza 0 1,/:{(reverse x)+2+til each 2+x}til 12
lyric:raze .[;0 2;{"A",5_x}5_] verses{@[x;0;ssr[;"twelfth";y]]}'days / tweak one line
.[;(::;0);ssr[;"twelfth";];DAYS] / number the verses
 
STANZA 0 1,/:#\:[;til 15] -2 -til 12; / compose 12 verses
1 "\n"sv lyric; // print
</syntaxhighlight>
</lang>
{{out}}
<pre>On the first day of Christmas
Line 4,240 ⟶ 5,074:
And a partridge in a pear tree.
</pre>
* [https://code.kx.com/q/ref/ Language Reference]
* [https://code.kx.com/q/learn/pb/xmas-days/ The Q Playbook: The Twelve Days of Christmas – analysis]
 
=={{header|Quackery}}==
 
<langsyntaxhighlight Quackerylang="quackery"> [ [ table
$ "first" $ "second" $ "third" $ "fourth"
$ "fifth" $ "sixth" $ "seventh" $ "eighth"
Line 4,271 ⟶ 5,104:
[ 12 times [ i^ verse ] ] is song ( --> )
song</langsyntaxhighlight>
 
{{out}}
Line 4,304 ⟶ 5,137:
 
=={{header|R}}==
<syntaxhighlight lang="r">
<lang R>
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")
Line 4,312 ⟶ 5,145:
cat("My true love gave to me:\n")
cat(paste(gifts[i:1], collapse = "\n"), "\n\n")
}</langsyntaxhighlight>
{{out}}
<pre>
Line 4,363 ⟶ 5,196:
* British Variant: capitalises '''FIVE GO-OLD RINGS''' since it needs to be sung at top volume. If you want to change this back; the source is there. But I guarantee you won't have as much fun singing it.
 
<langsyntaxhighlight lang="racket">#lang racket
(define (ordinal-text d)
(vector-ref
Line 4,397 ⟶ 5,230:
#:when (on-the... day)
(prezzy-line (in-range day 0 -1)))
(printf "~a~a~%" (prezzy prezzy-line day) (line-end prezzy-line day)))</langsyntaxhighlight>
 
{{out}}
Line 4,462 ⟶ 5,295:
=={{header|Raku}}==
(formerly Perl 6)
<syntaxhighlight lang="raku" perl6line>my @days = <first second third fourth fifth sixth seventh eighth ninth tenth eleventh twelfth>;
 
my @gifts = lines q:to/END/;
Line 4,488 ⟶ 5,321:
nth($d);
say @gifts[$_] for $d ... 0;
}</langsyntaxhighlight>
{{out}}
<pre>On the first day of Christmas, my true love gave to me:
Line 4,530 ⟶ 5,363:
::* &nbsp; capitalized &nbsp; '''True Love''' &nbsp; as it (may) refer to a deity
::* &nbsp; added indentation to make verses resemble song lyrics
<langsyntaxhighlight lang="rexx">/*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. */
Line 4,545 ⟶ 5,378:
end /*j*/
say /*add a blank line between the verses. */
end /*day*/ /*stick a fork in it, we're all done. */</langsyntaxhighlight>
{{out|output|:}}
 
Line 4,667 ⟶ 5,500:
 
=={{header|Ring}}==
<langsyntaxhighlight lang="ring">
# Project : The Twelve Days of Christmas
 
Line 4,686 ⟶ 5,519:
next
 
</syntaxhighlight>
</lang>
Output:
<pre>
Line 4,816 ⟶ 5,649:
 
=={{header|Ruby}}==
<langsyntaxhighlight lang="ruby">gifts = "A partridge in a pear tree
Two turtle doves and
Three french hens
Line 4,837 ⟶ 5,670:
puts gifts[0, i+1].reverse
puts
end</langsyntaxhighlight>
 
=={{header|Run BASIC}}==
<langsyntaxhighlight Runbasiclang="runbasic">gifts$ = "
A partridge in a pear tree.,
Two turtle doves,
Line 4,865 ⟶ 5,698:
print
next i
</langsyntaxhighlight>Output:
<pre>On the first day of Christmas
My true love gave to me:
Line 4,888 ⟶ 5,721:
=={{header|Rust}}==
[https://play.rust-lang.org/?gist=773d4af97e7c4b374574a3e1656b5029&version=stable&backtrace=0 Rust Playground]
<langsyntaxhighlight lang="rust">fn main() {
let days = ["first", "second", "third", "fourth", "fifth", "sixth", "seventh", "eighth",
"ninth", "tenth", "eleventh", "twelfth"];
 
let gifts = ["A PatridgePartridge in a Pear Tree",
"Two Turtle Doves and",
"Three French Hens",
Line 4,914 ⟶ 5,747:
println!()
}
}</langsyntaxhighlight>
 
=={{header|Scala}}==
<langsyntaxhighlight lang="scala">val gifts = Array(
"A partridge in a pear tree.",
"Two turtle doves and",
Line 4,942 ⟶ 5,775:
 
(0 until 12).map(giftsForDay andThen println)
</syntaxhighlight>
</lang>
 
{{Out}}
Line 4,971 ⟶ 5,804:
=={{header|Scheme}}==
Without Common Lisp's <tt>format</tt>, we sadly have to hard-code the list of ordinals.
<langsyntaxhighlight lang="scheme">; Racket has this built in, but it's not standard
(define (take lst n)
(if (or (null? lst) (<= n 0))
Line 5,006 ⟶ 5,839:
(newline)))
 
(exit)</langsyntaxhighlight>
 
{{Out}}
Line 5,033 ⟶ 5,866:
 
=={{header|Seed7}}==
<langsyntaxhighlight lang="seed7">$ include "seed7_05.s7i";
 
const proc: main is func
Line 5,058 ⟶ 5,891:
end for;
end for;
end func;</langsyntaxhighlight>
 
{{out}}
Line 5,097 ⟶ 5,930:
=={{header|Self}}==
Nicely factored:
<langsyntaxhighlight lang="self">(|
parent* = traits oddball.
 
Line 5,128 ⟶ 5,961:
 
|) value printLine
</syntaxhighlight>
</lang>
 
=={{header|SenseTalk}}==
<langsyntaxhighlight lang="sensetalk">put [
"partridge in a pear tree.",
"turtle doves and",
Line 5,158 ⟶ 5,991:
end repeat
put ""
end repeat</langsyntaxhighlight>
 
{{out}}
Line 5,195 ⟶ 6,028:
</pre>
 
=={{header|SETL}}==
<syntaxhighlight lang="setl">program christmas;
ordinals := [
"first", "second", "third", "fourth", "fifth",
"sixth", "seventh", "eight", "ninth", "tenth",
"eleventh", "twelfth"
];
verses := [
"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"
];
loop for i in [1..12] do
print("On the " + ordinals(i) + " day of Christmas,");
print("My true love gave to me");
loop for j in [i, i-1..1] do
print(verses(j));
end loop;
print;
end loop;
end program;</syntaxhighlight>
=={{header|Sidef}}==
{{trans|Raku}}
<langsyntaxhighlight lang="ruby">var days = <first second third fourth fifth sixth seventh eighth ninth tenth eleventh twelfth>;
 
var gifts = <<'EOT'.lines;
Line 5,225 ⟶ 6,090:
say gifts[i];
}
}</langsyntaxhighlight>
 
{{out}}
Line 5,266 ⟶ 6,131:
=={{header|Simula}}==
{{works with|GNU Cim}}
<langsyntaxhighlight lang="simula">Begin
Text Array days(1:12), gifts(1:12);
Integer day, gift;
Line 5,306 ⟶ 6,171:
End
End
</syntaxhighlight>
</lang>
 
{{Out}}
Line 5,334 ⟶ 6,199:
=={{header|Smalltalk}}==
{{works with|GNU Smalltalk}}
<langsyntaxhighlight lang="smalltalk">Object subclass: TwelveDays [
Ordinals := #('first' 'second' 'third' 'fourth' 'fifth' 'sixth'
'seventh' 'eighth' 'ninth' 'tenth' 'eleventh' 'twelfth').
Line 5,360 ⟶ 6,225:
1 to: 12 do: [:i |
Transcript show: (TwelveDays giftsFor: i); cr.
].</langsyntaxhighlight>
 
{{Out}}
Line 5,387 ⟶ 6,252:
 
=={{header|Smart BASIC}}==
<langsyntaxhighlight lang="smart BASICbasic">' by rbytes
dim d$(12),x$(15)!s=15
for t=0 to 11!read d$(t)!next t
Line 5,394 ⟶ 6,259:
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."</Langsyntaxhighlight>
<pre>On the first day of Christmas
My true love gave to me:
Line 5,443 ⟶ 6,308:
=={{header|Snobol}}==
{{Works with|CSNOBOL4}}
<langsyntaxhighlight lang="snobol"> DAYS = ARRAY('12')
DAYS<1> = 'first'
DAYS<2> = 'second'
Line 5,482 ⟶ 6,347:
NEXT OUTPUT = ''
DAY = DAY + 1 :(OUTER)
END</langsyntaxhighlight>
 
{{Out}}
Line 5,507 ⟶ 6,372:
Two turtle doves and
A partridge in a pear tree.</pre>
 
=={{header|SparForte}}==
As a structured script.
<syntaxhighlight lang="ada">#!/usr/local/bin/spar
pragma annotate( summary, "twelve_days" )
@( description, "Write a program that outputs the lyrics of the " )
@( description, "Christmas carol The Twelve Days of Christmas. " )
@( see_also, "http://rosettacode.org/wiki/The_Twelve_Days_of_Christmas" );
pragma annotate( author, "Ken O. Burtch" );
pragma license( unrestricted );
 
pragma restriction( no_external_commands );
 
procedure twelve_days is
type days is ( first, second, third, forth, fifth, sixth,seventh, eighth,
ninth, tenth, eleventh, twelfth );
gifts : array( first..twelfth ) of string := (
" 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"
);
begin
for day in first..twelfth loop
put( "On the " ) @ ( day ) @ ( " day of Christmas," );
new_line;
put_line( "My true love gave to me:" );
for subday in reverse first..day loop
put_line( gifts( subday ) );
end loop;
if day = first then
gifts( day ) := strings.replace_slice( gifts( day ), 2, 2, "And a" );
end if;
new_line;
end loop;
command_line.set_exit_status( 0 );
end twelve_days;
</syntaxhighlight>
 
=={{header|SQL}}==
Demonstration of Oracle 12c "with" clause enhancement.
 
<syntaxhighlight lang="sql">
<lang SQL>
with
function nl ( s in varchar2 )
Line 5,547 ⟶ 6,458:
connect by level <= 12
/
</syntaxhighlight>
</lang>
output:
<pre>
Line 5,576 ⟶ 6,487:
=={{header|Swift}}==
{{works with|Swift|2.1}}
<langsyntaxhighlight lang="swift">let gifts = [ "partridge in a pear tree", "Two turtle doves",
"Three French hens", "Four calling birds",
"Five gold rings", "Six geese a-laying",
Line 5,604 ⟶ 6,515:
for day in 1...12 {
print(giftsForDay(day))
}</langsyntaxhighlight>
 
{{out}}
Line 5,631 ⟶ 6,542:
 
=={{header|Tailspin}}==
<langsyntaxhighlight lang="tailspin">
def ordinal: ['first', 'second', 'third', 'fourth', 'fifth', 'sixth', 'seventh', 'eighth', 'ninth', 'tenth', 'eleventh', 'twelfth'];
def gift: [
Line 5,663 ⟶ 6,574:
' !
\singVerse) -> !OUT::write
</syntaxhighlight>
</lang>
{{out}}
<pre>
Line 5,695 ⟶ 6,606:
</pre>
=={{header|Terraform}}==
<langsyntaxhighlight lang="terraform">locals {
days = [ "first", "second", "third", "fourth", "fifth", "sixth",
"seventh", "eighth", "ninth", "tenth", "eleventh", "twelfth" ]
Line 5,721 ⟶ 6,632:
output "lyrics" {
value = join("\n\n",[for t in data.template_file.days: t.rendered])
}</langsyntaxhighlight>
 
 
Line 5,756 ⟶ 6,667:
=={{header|Tcl}}==
{{works with|Tcl|8.6}}
<langsyntaxhighlight lang="tcl">set days {
first second third fourth fifth sixth
seventh eighth ninth tenth eleventh twelfth
Line 5,778 ⟶ 6,689:
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]</langsyntaxhighlight>
{{out}}
<pre style="height:55ex;overflow:scroll">
Line 5,897 ⟶ 6,808:
 
=={{header|uBasic/4tH}}==
<syntaxhighlight lang="text">Dim @n(12) : Dim @v(12) ' define both arrays
 
Proc _DataDays ' put data on the stack
Line 5,922 ⟶ 6,833:
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</langsyntaxhighlight>
 
=={{header|UNIX Shell}}==
{{works with|Bourne Again SHell}}
{{works with|Korn Shell|93}}
<langsyntaxhighlight lang="bash">#!/usr/bin/env bash
ordinals=(first second third fourth fifth sixth
seventh eighth ninth tenth eleventh twelfth)
Line 5,970 ⟶ 6,880:
for (( day=0; day < 12; ++day )); do
echo_gifts $day
done</langsyntaxhighlight>
 
The above will also work in zsh if the index range is changed from 0..11 to 1..12.
Line 5,977 ⟶ 6,887:
(requires the '''seq''' command)
 
<langsyntaxhighlight lang="sh">#!/bin/sh
ordinal() {
n=$1
Line 6,009 ⟶ 6,919:
for day in `seq 0 11`; do
echo_gifts $day
done</langsyntaxhighlight>
 
{{Out}}
Line 6,036 ⟶ 6,946:
 
=={{header|VBA}}==
<langsyntaxhighlight lang="vb">Sub Main()
Dim i As Integer, c As Integer, j As Integer, strReturn() As String
Dim s, n
Line 6,051 ⟶ 6,961:
strReturn(UBound(strReturn)) = Replace(strReturn(UBound(strReturn)), "and" & vbCrLf & "A", vbCrLf & "And a")
Debug.Print Join(strReturn, vbCrLf)
End Sub</langsyntaxhighlight>
{{out}}
<pre>On the first day of Christmas,
Line 6,084 ⟶ 6,994:
 
=={{header|VBScript}}==
<langsyntaxhighlight lang="vb">days = Array("first","second","third","fourth","fifth","sixth",_
"seventh","eight","ninth","tenth","eleventh","twelfth")
Line 6,110 ⟶ 7,020:
End If
WScript.StdOut.WriteBlankLines(2)
Next</langsyntaxhighlight>
 
 
Line 6,116 ⟶ 7,026:
This example uses calculated call targets.
Note that in the gift subroutines, the execution falls through all the following subroutines and returns only after the gift 1 routine.
<langsyntaxhighlight lang="vedit">for (#1 = 1; #1 <= 12; #1++) {
Num_Str(#1, 9, LEFT)
IT("On the ")
Line 6,151 ⟶ 7,061:
:gift 2: IT("Two turtle doves, and") IN
:gift 1: IT("A partridge in a pear tree.") IN
return </langsyntaxhighlight>
 
=={{header|Vim Script}}==
{{trans|Raku}}
<langsyntaxhighlight lang="vimscript">
let b:days=["first", "second", "third", "fourth", "fifth", "sixth",
\ "seventh", "eighth", "ninth", "tenth", "eleventh", "twelfth"]
Line 6,191 ⟶ 7,101:
endwhile
let b:day = b:day + 1
endwhile</langsyntaxhighlight>
 
{{Out}}
Line 6,221 ⟶ 7,131:
'''Compiler:''' Roslyn Visual Basic (language version >= 14, e.g. with Visual Studio 2015)
 
<langsyntaxhighlight lang="vbnet">Module Program
Sub Main()
Dim days = New String(11) {"first", "second", "third", "fourth", "fifth", "sixth", "seventh", "eighth", "ninth", "tenth", "eleventh", "twelfth"}
Line 6,251 ⟶ 7,161:
Next
End Sub
End Module</langsyntaxhighlight>
 
=={{header|Wren}}==
<langsyntaxhighlight ecmascriptlang="wren">var days = [
"first", "second", "third", "fourth", "fifth", "sixth",
"seventh", "eighth", "ninth", "tenth", "eleventh", "twelfth"
Line 6,271 ⟶ 7,181:
for (j in i..0) System.print(gifts[j])
System.print()
}</langsyntaxhighlight>
 
=={{header|XPL0}}==
<langsyntaxhighlight XPL0lang="xpl0">int Day, Gift, D, G;
[Day:= [0, "first", "second", "third", "forth", "fifth", "sixth",
"seventh", "eighth", "ninth", "tenth", "eleventh", "twelfth"];
Line 6,298 ⟶ 7,208:
CrLf(0);
];
]</langsyntaxhighlight>
 
{{out}}
Line 6,331 ⟶ 7,241:
 
 
<langsyntaxhighlight lang="z80">waitChar equ &BB06 ;wait for a key press
PrintChar equ &BB5A ;print accumulator to screen
 
Line 6,584 ⟶ 7,494:
 
Song_NewLine:
byte 13,10,0 ;control codes for a new line.</langsyntaxhighlight>
 
=={{header|zkl}}==
{{trans|Python}}
<langsyntaxhighlight lang="zkl">gifts:=
#<<<
"A beer, in a tree.; Two turtlenecks; Three french toast;
Line 6,604 ⟶ 7,514:
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");
}</langsyntaxhighlight>
 
{{out}}
38

edits