The Twelve Days of Christmas: Difference between revisions
→{{header|q}}: removed redundant iteration and variable
Alextretyak (talk | contribs) m (→{{header|11l}}: Indented multi-line string literals) |
(→{{header|q}}: removed redundant iteration and variable) |
||
(37 intermediate revisions by 20 users not shown) | |||
Line 14:
{{trans|Python}}
<
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))</
=={{header|8080 Assembly}}==
<
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,'$'</
=={{header|8086 Assembly}}==
{{trans|8080 Assembly}}
<
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</
=={{header|Action!}}==
<syntaxhighlight lang="action!">PROC Wait(BYTE frames)
BYTE RTCLOK=$14
frames==+RTCLOK
WHILE frames#RTCLOK DO OD
RETURN
PROC Main()
DEFINE PTR="CARD"
PTR ARRAY num(12),obj(12)
BYTE i,j
num(0)="first" num(1)="second" num(2)="third"
num(3)="fourth" num(4)="fifth" num(5)="sixth"
num(6)="seventh" num(7)="eight" num(8)="ninth"
num(9)="tenth" num(10)="eleventh" num(11)="Twelfth"
obj(0)="And a partridge in a pear tree."
obj(1)="Two turtle doves"
obj(2)="Three french hens"
obj(3)="Four calling birds"
obj(4)="Five golden rings"
obj(5)="Six geese a-laying"
obj(6)="Seven swans a-swimming"
obj(7)="Eight maids a-milking"
obj(8)="Nine ladies dancing"
obj(9)="Ten lords a-leaping"
obj(10)="Eleven pipers piping"
obj(11)="Twelve drummers drumming"
FOR i=0 TO 11
DO
PrintF("On the %S day of Christmas,%E",num(i))
PrintE("My true love gave to me:")
IF i=0 THEN
PrintE("A partridge in a pear tree.")
ELSE
j=i+1
WHILE j>0
DO
j==-1
PrintE(obj(j))
OD
FI
PutE()
Wait(50)
OD
RETURN</syntaxhighlight>
{{out}}
[https://gitlab.com/amarok8bit/action-rosetta-code/-/raw/master/images/The_Twelve_Days_of_Christmas.png Screenshot from Atari 8-bit computer]
<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|ActionScript}}==
Line 184 ⟶ 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)
<
import flash.display.Sprite;
Line 294 ⟶ 372:
}
}</
=={{header|Ada}}==
<
with Ada.Strings.Unbounded; use Ada.Strings.Unbounded;
Line 333 ⟶ 411:
end loop;
end Twelve_Days_Of_Christmas;
</syntaxhighlight>
=={{header|ALGOL 68}}==
{{Works with|ALGOL 68 Genie}}
<
[]STRING labels = ("first", "second", "third", "fourth",
"fifth", "sixth", "seventh", "eighth",
Line 362 ⟶ 440:
print(newline)
OD
END</
{{Out}}
Line 387 ⟶ 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===
<
"Three French hens,", "Four calling birds,", ¬
"Five gold rings,", "Six geese a-laying,", ¬
Line 406 ⟶ 527:
end repeat
log ""
end repeat</
{{Out}}
Line 437 ⟶ 558:
Drawing on some functional primitives, and post-Yosemite AppleScript's ability to import Foundation classes:
<
property pstrGifts : "A partridge in a pear tree, Two turtle doves, Three French hens, " & ¬
Line 572 ⟶ 693:
((ca's NSString's stringWithString:(str))'s ¬
uppercaseStringWithLocale:(ca's NSLocale's currentLocale())) as text
end toUpper</
{{Out}}
Line 600 ⟶ 721:
=={{header|Arturo}}==
<
"A partridge in a pear tree."
"Two turtle doves"
Line 626 ⟶ 747:
-> capitalize last g
print ""
]</
{{out}}
Line 745 ⟶ 866:
=={{header|AutoHotkey}}==
<
lines := ["A partridge in a pear tree."
,"Two turtle doves and"
Line 766 ⟶ 887:
full:= full . top . "`n" . mid . ((A_Index<lines.MaxIndex())?"`n":"")
}
MsgBox % full</
=={{header|AWK}}==
<syntaxhighlight lang="awk">
# syntax: GAWK -f THE_TWELVE_DAYS_OF_CHRISTMAS.AWK
BEGIN {
Line 795 ⟶ 916:
exit(0)
}
</syntaxhighlight>
{{out}}
<pre>
Line 826 ⟶ 947:
=={{header|Batch File}}==
<
:: Batch File Implementation
Line 875 ⟶ 996:
echo(
)
exit /b</
=={{header|BASIC}}==
<syntaxhighlight 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 902 ⟶ 1,022:
210 DATA "Ten lords a-leaping"
220 DATA "Eleven pipers piping"
230 DATA "Twelve drummers drumming"</
==={{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}}==
<
let ordinal(n) =
Line 936 ⟶ 1,270:
$)
let start() be for n=1 to 12 do verse(n)</
=={{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.
<
>-#11#\0#50#< g2-:00p4v >\#%"O"/#::$#<3#$+g48*-v^\,+*+ 55!:*!!-"|":g+3<
^02_>#`>#< 2 5 3 1 0 \1-:#^\_^#:-1\+<00_@#:>#<$<
Line 948 ⟶ 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</
=={{header|Bracmat}}==
<
second
third
Line 988 ⟶ 1,322:
)
)
);</
=={{header|C}}==
<syntaxhighlight lang="c">
#include<stdio.h>
Line 1,041 ⟶ 1,375:
return 0;
}</
=={{header|C sharp|C#}}==
<
public class TwelveDaysOfChristmas {
Line 1,086 ⟶ 1,420:
}
}</
=={{header|C++}}==
<
#include <array>
#include <string>
Line 1,146 ⟶ 1,480:
return 0;
}</
=={{header|Clojure}}==
{{trans|Raku}}
<
[numbers '(first second third fourth fifth sixth
seventh eighth ninth tenth eleventh twelfth)
Line 1,172 ⟶ 1,506:
(dorun (for [n (range d -1 -1)]
(println (nth gifts n))))))))
</syntaxhighlight>
{{Out}}
<pre>On the first day of Christmas, my true love sent to me:
Line 1,196 ⟶ 1,530:
Two turtle doves and
A partridge in a pear tree.</pre>
=={{header|CLU}}==
<syntaxhighlight lang="clu">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</syntaxhighlight>
=={{header|COBOL}}==
{{works with|GNU Cobol|2.0}}
<
PROGRAM-ID. twelve-days-of-christmas.
Line 1,242 ⟶ 1,621:
END-PERFORM
.
END PROGRAM twelve-days-of-christmas.</
=={{header|Common Lisp}}==
<
((gifts '("A partridge in a pear tree." "Two turtle doves, and"
"Three French hens," "Four calling birds,"
Line 1,259 ⟶ 1,638:
(format t "~a~%" (nth gift gifts)))
(format t "~%")))
</syntaxhighlight>
{{Out}}
Line 1,286 ⟶ 1,665:
=={{header|Cowgol}}==
<
var ordinals: [uint8][] := {
Line 1,323 ⟶ 1,702:
print_nl();
verse := verse + 1;
end loop;</
=={{header|Crystal}}==
{{trans|Ruby}}
<
gifts = "A partridge in a pear tree
Two turtle doves and
Line 1,345 ⟶ 1,724:
gifts[0, i + 1].reverse.each &->puts(String)
puts
end</
=={{header|D}}==
{{trans|Python}}
<
"A partridge in a pear tree.
Two turtle doves
Line 1,377 ⟶ 1,756:
(n > 0 ? " and\n" ~ g.back : g.back.capitalize), '\n');
}
}</
=={{header|dc}}==
<
d [first] r :n
Line 1,446 ⟶ 1,825:
0 ll x
</syntaxhighlight>
{{Out}}
Line 1,471 ⟶ 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}}==
<
"first", "second", "third", "fourth", "fifth", "sixth", "seventh", "eighth", "ninth",
"tenth", "eleventh", "twelfth"
Line 1,498 ⟶ 2,033:
}
print()
}</
=={{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">
class
APPLICATION
Line 1,557 ⟶ 2,117:
end
</syntaxhighlight>
=={{header|Elena}}==
{{trans|C++}}
ELENA
<
public program()
Line 1,586 ⟶ 2,146:
};
for(int i := 0
{
console.printLine("On the ", days[i], " day of Christmas, my true love gave to me");
Line 1,596 ⟶ 2,156:
else
{
for(int j := i
{
console.printLine(gifts[j])
Line 1,604 ⟶ 2,164:
console.printLine()
}
}</
=={{header|Elixir}}==
<
A partridge in a pear tree
Two turtle doves and
Line 1,629 ⟶ 2,189:
Enum.take(gifts, i+1) |> Enum.reverse |> Enum.each(&IO.puts &1)
IO.puts ""
end)</
{{out}}
Line 1,660 ⟶ 2,220:
=={{header|Erlang}}==
<
-export([gifts_for_day/1]).
Line 1,680 ⟶ 2,240:
main(_) -> lists:map(fun(N) -> io:fwrite("~s~n~n", [gifts_for_day(N)]) end,
lists:seq(1,12)).
</syntaxhighlight>
{{Out}}<pre>On the first day of Christmas, my true love sent to me:
A partridge in a pear tree.
Line 1,705 ⟶ 2,265:
=={{header|F Sharp|F#}}==
<
"And a partridge in a pear tree";
"Two turtle doves";
Line 1,733 ⟶ 2,293:
printf "\n"
List.iter displayGifts [0..11]</
=={{header|Factor}}==
<
IN: rosetta-code.twelve-days-of-christmas
Line 1,769 ⟶ 2,329:
: twelve-days-of-christmas ( -- ) 12 [1,b] [ verse ] each ;
MAIN: twelve-days-of-christmas</
{{out}}
<pre>
Line 1,793 ⟶ 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,798 ⟶ 2,445:
=={{header|Forth}}==
{{works with|GNU Forth}}
<
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,834 ⟶ 2,481:
main
bye
</syntaxhighlight>
{{Out}}
Line 1,862 ⟶ 2,509:
=={{header|Fortran}}==
{{works with|Fortran|FORTRAN|77}}
<
character days(12)*8
Line 1,894 ⟶ 2,541:
10 continue
end
</syntaxhighlight>
{{Out}}
Line 1,921 ⟶ 2,568:
=={{header|FreeBASIC}}==
<
' compile with: fbc -s console
Line 1,956 ⟶ 2,603:
Print : 'Print "hit any key to end program"
Sleep
End</
{{out}}
<pre> On the first day of Christmas
Line 1,986 ⟶ 2,633:
=={{header|Go}}==
[https://play.golang.org/p/dnDyx8ee_G Go Playground]
<
import (
Line 2,011 ⟶ 2,658:
}
}
</syntaxhighlight>
=={{header|Groovy}}==
<
'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,025 ⟶ 2,672:
}
println()
}</
=={{header|Haskell}}==
{{trans|F#}}
<
gifts =
[ "And a partridge in a pear tree!",
Line 2,073 ⟶ 2,720:
main :: IO ()
main = mapM_ verseOfTheDay [0 .. 11]</
{{out}}
<pre style="font-size:80%">On the first day of Christmas my true love gave to me...
Line 2,180 ⟶ 2,827:
Works in both languages.
<
days := ["first","second","third","fourth","fifth","sixth","seventh",
"eighth","ninth","tenth","eleventh","twelveth"]
Line 2,192 ⟶ 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</
=={{header|J}}==
<
days=: ;:'first second third fourth fifth sixth seventh eighth ninth tenth eleventh twelfth'
Line 2,220 ⟶ 2,867:
makeVerses=: [: chgFirstVerse (firstline&.> days) ,&.> [: <@;@|.\ gifts"_
singCarol=: LF joinstring makeVerses</
=={{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}}==
<
final static String[] gifts = {
Line 2,248 ⟶ 2,919:
}
}
}</
=={{header|JavaScript}}==
<syntaxhighlight lang="javascript">
var days = [
'first', 'second', 'third', 'fourth', 'fifth', 'sixth', 'seventh', 'eighth', 'ninth',
Line 2,294 ⟶ 2,965:
song = verses.join('\n\n');
document.write(song);
</syntaxhighlight>
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 :-)
<
(function (
strPrepn,
Line 2,373 ⟶ 3,044:
'On', 'Christmas', 'day', 'my true love', 'gave to', 'me'
), null, 2
);</
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).
<
var c =
"first second third fourth fifth sixth seventh eighth ninth tenth eleventh twelfth"
Line 2,399 ⟶ 3,070:
0 : 1)))]);
}, []);
}("On", "Christmas", "day", "my true love", "gave to", "me"), null, 2);</
Formatted JSON output (the expanded and Closure-compiled versions above both yield the same output).
<syntaxhighlight lang="javascript">[
[
"On the first day of Christmas",
Line 2,442 ⟶ 3,113:
//... etc.
]</
=={{header|jq}}==
<
"seven", "eight", "nine", "ten", "eleven", "twelve"] as $cardinals
| [ "first", "second", "third", "fourth", "fifth", "sixth",
Line 2,459 ⟶ 3,130:
" " + $gifts[$j] + if $j > 0 then "," else "\n" end]
| join("\n"))
</syntaxhighlight>
Run with <pre>jq -rnf programfile.jq</pre> to yield this result:
Line 2,496 ⟶ 3,167:
=={{header|Jsish}}==
Based on Javascript entry, almost identical, added unitTest.
<
"use strict";
Line 2,644 ⟶ 3,315:
And a partridge in a pear tree
=!EXPECTEND!=
*/</
{{out}}
Line 2,652 ⟶ 3,323:
=={{header|Julia}}==
<
function printlyrics()
Line 2,684 ⟶ 3,355:
end
printlyrics()</
{{out}}
Line 2,715 ⟶ 3,386:
=={{header|Kotlin}}==
{{trans|C#}}
<
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,735 ⟶ 3,406:
Day.values().forEachIndexed { i, d -> println(d.header + gifts.slice(0..i).asReversed().joinToString("\n\t")) }
}</
=={{header|Lambdatalk}}==
<
{def days
first second third fourth fifth sixth
Line 2,790 ⟶ 3,461:
Two turtle doves and
A partridge in a pear tree.
</syntaxhighlight>
=={{header|Logo}}==
<
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,814 ⟶ 3,485:
]
]
bye</
{{Out}}
Line 2,843 ⟶ 3,514:
=={{header|LOLCODE}}==
{{works with|LCI 0.10}}
<syntaxhighlight lang="text">HAI 1.2
CAN HAS STDIO?
I HAS A Dayz ITZ A BUKKIT
Line 2,895 ⟶ 3,566:
IM OUTTA YR Outer
KTHXBYE</
{{Out}}
Line 2,923 ⟶ 3,594:
=={{header|Lua}}==
<syntaxhighlight lang="lua">
local days = {
'first', 'second', 'third', 'fourth', 'fifth', 'sixth', 'seventh', 'eighth', 'ninth',
Line 2,962 ⟶ 3,633:
print(table.concat(verses, '\n\n'))
</syntaxhighlight>
=={{header|
<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
.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,006 ⟶ 3,729:
VECTOR VALUES MT = $*$
END OF PROGRAM
</syntaxhighlight>
=={{header|Maple}}==
<
"Eleven pipers piping", "Ten lords a-leaping",
"Nine ladies dancing", "Eight maids a-milking",
Line 3,023 ⟶ 3,746:
end do;
printf("\n");
end do;</
{{out}}
<pre>
Line 3,073 ⟶ 3,796:
</pre>
=={{header|Mathematica}}/{{header|Wolfram Language}}==
<syntaxhighlight lang="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,087 ⟶ 3,809:
daysarray[[i]],
If[i == 1, "A partridge in a pear tree.",
Row[Reverse[Take[giftsarray, i]], ","]]]], {i, 1, 12}]</syntaxhighlight>
{{out}}
<pre style="height:55ex;overflow:scroll">
Line 3,191 ⟶ 3,912:
Three french hens,
Two turtle doves,
And a partridge in a pear tree.</pre>
=={{header|MiniScript}}==
<
"seventh","eigth","nineth","tenth","eleventh","twelfth"]
gifts = ["A partridge in a pear tree.","Two turtle doves, and",
Line 3,212 ⟶ 3,932:
print " ----------"
end for
</syntaxhighlight>
{{out}}
<pre>
Line 3,241 ⟶ 3,961:
=={{header|Nim}}==
{{trans|Python}}
<
const
Line 3,263 ⟶ 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])</
{{out}}
Line 3,294 ⟶ 4,014:
=={{header|Objeck}}==
{{trans|C sharp|C#}}
<
class TwelveDaysOfChristmas {
function : Main(args : String[]) ~ Nil {
Line 3,330 ⟶ 4,050:
}
}
</syntaxhighlight>
=={{header|PARI/GP}}==
<
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,341 ⟶ 4,061:
print(if(i==1,"\tA partridge in a pear tree.",Str("\t",gifts[1])))
)
}</
{{out}}
<pre>On the first day of Christmas, my true love gave to me:
Line 3,366 ⟶ 4,086:
This should work with any modern Pascal implementation that has a '''string''' type, e.g. [[Free Pascal]].
<
const
Line 3,397 ⟶ 4,117:
writeln
end
end.</
{{Out}}
<pre>On the first day of Christmas, my true love sent to me:
Line 3,424 ⟶ 4,144:
Here's a version that works in ISO Standard Pascal, albeit with extraneous spaces in the output:
<
const
Line 3,456 ⟶ 4,176:
writeln
end
end.</
{{Out}}
Line 3,483 ⟶ 4,203:
=={{header|Perl}}==
<
my @days = qw{ first second third fourth fifth sixth seventh eighth ninth tenth eleventh twelfth };
Line 3,507 ⟶ 4,227:
Three french hens
Two turtle doves
And a partridge in a pear tree.</
{{out}}
<pre>On the first day of Christmas,
Line 3,536 ⟶ 4,256:
=={{header|Phix}}==
<!--<
<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,557 ⟶ 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>
<!--</
=={{header|Phixmonti}}==
<
( "A partridge in a pear tree."
Line 3,589 ⟶ 4,309:
swap
nl
endfor</
=={{header|PHP}}==
<syntaxhighlight lang="php">
<?php
Line 3,639 ⟶ 4,359:
?>
</syntaxhighlight>
Or using recursion:
<
$gifts = array(
Line 3,677 ⟶ 4,397:
twelve_days( array_reverse( $gifts, true ) );
</syntaxhighlight>
{{Out}}
<pre style="font-size:84%;height:55ex">
Line 3,782 ⟶ 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}}==
<
first second third fourth fifth sixth
seventh eight ninth tenth eleventh twelfth )
Line 3,812 ⟶ 4,596:
(prinl) )
(bye)</
=={{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}}==
<
1 = "first";
2 = "second";
Line 3,853 ⟶ 4,735:
}
""
}</
{{out}}
Line 3,882 ⟶ 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}}==
<
day(2, 'second').
day(3, 'third').
Line 3,925 ⟶ 4,876:
writeLoop(N) :- Day is 13 - N, writeGifts(Day), M is N - 1, writeLoop(M).
main :- writeLoop(12), halt.</
{{Out}}
Line 3,935 ⟶ 4,886:
A partridge in a pear tree.
[ ... ]
On the twelfth day of Christmas, my true love sent to me:
Line 3,952 ⟶ 4,903:
=={{header|PureBasic}}==
<
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 3,967 ⟶ 4,918:
Next I
Input()
EndIf</
{{out}}
<pre>On the first day of Christmas, my true love sent to me:
Line 4,004 ⟶ 4,955:
=={{header|Python}}==
<
A partridge in a pear tree.
Two turtle doves
Line 4,026 ⟶ 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()))</
{{out}}
Line 4,070 ⟶ 5,021:
=={{header|q}}==
<syntaxhighlight lang="q">
" seventh eighth ninth tenth eleventh twelfth"
STANZA:( / final stanza
"On the twelfth day of Christmas";
"My true love gave to me:";
"Twelve drummers drumming";
"Eleven pipers piping";
Line 4,088 ⟶ 5,042:
"")
-1 raze
.[;(::;0);ssr[;"twelfth";];DAYS] / number the verses
STANZA 0 1,/:#\:[;til 15] -2 -til 12; / compose 12 verses
</syntaxhighlight>
{{out}}
<pre>On the first day of Christmas
Line 4,120 ⟶ 5,074:
And a partridge in a pear tree.
</pre>
* [https://code.kx.com/q/ref/ Language Reference]
=={{header|Quackery}}==
<
$ "first" $ "second" $ "third" $ "fourth"
$ "fifth" $ "sixth" $ "seventh" $ "eighth"
Line 4,151 ⟶ 5,104:
[ 12 times [ i^ verse ] ] is song ( --> )
song</
{{out}}
Line 4,184 ⟶ 5,137:
=={{header|R}}==
<syntaxhighlight 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,192 ⟶ 5,145:
cat("My true love gave to me:\n")
cat(paste(gifts[i:1], collapse = "\n"), "\n\n")
}</
{{out}}
<pre>
Line 4,243 ⟶ 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.
<
(define (ordinal-text d)
(vector-ref
Line 4,277 ⟶ 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)))</
{{out}}
Line 4,342 ⟶ 5,295:
=={{header|Raku}}==
(formerly Perl 6)
<syntaxhighlight lang="raku"
my @gifts = lines q:to/END/;
Line 4,368 ⟶ 5,321:
nth($d);
say @gifts[$_] for $d ... 0;
}</
{{out}}
<pre>On the first day of Christmas, my true love gave to me:
Line 4,410 ⟶ 5,363:
::* capitalized '''True Love''' as it (may) refer to a deity
::* added indentation to make verses resemble song lyrics
<
ordD= 'first second third fourth fifth sixth seventh eighth ninth tenth eleventh twelfth'
pad= left('', 20) /*used for indenting the shown verses. */
Line 4,425 ⟶ 5,378:
end /*j*/
say /*add a blank line between the verses. */
end /*day*/ /*stick a fork in it, we're all done. */</
{{out|output|:}}
Line 4,547 ⟶ 5,500:
=={{header|Ring}}==
<
# Project : The Twelve Days of Christmas
Line 4,566 ⟶ 5,519:
next
</syntaxhighlight>
Output:
<pre>
Line 4,696 ⟶ 5,649:
=={{header|Ruby}}==
<
Two turtle doves and
Three french hens
Line 4,717 ⟶ 5,670:
puts gifts[0, i+1].reverse
puts
end</
=={{header|Run BASIC}}==
<
A partridge in a pear tree.,
Two turtle doves,
Line 4,745 ⟶ 5,698:
print
next i
</
<pre>On the first day of Christmas
My true love gave to me:
Line 4,768 ⟶ 5,721:
=={{header|Rust}}==
[https://play.rust-lang.org/?gist=773d4af97e7c4b374574a3e1656b5029&version=stable&backtrace=0 Rust Playground]
<
let days = ["first", "second", "third", "fourth", "fifth", "sixth", "seventh", "eighth",
"ninth", "tenth", "eleventh", "twelfth"];
let gifts = ["A
"Two Turtle Doves and",
"Three French Hens",
Line 4,794 ⟶ 5,747:
println!()
}
}</
=={{header|Scala}}==
<
"A partridge in a pear tree.",
"Two turtle doves and",
Line 4,822 ⟶ 5,775:
(0 until 12).map(giftsForDay andThen println)
</syntaxhighlight>
{{Out}}
Line 4,851 ⟶ 5,804:
=={{header|Scheme}}==
Without Common Lisp's <tt>format</tt>, we sadly have to hard-code the list of ordinals.
<
(define (take lst n)
(if (or (null? lst) (<= n 0))
Line 4,886 ⟶ 5,839:
(newline)))
(exit)</
{{Out}}
Line 4,913 ⟶ 5,866:
=={{header|Seed7}}==
<
const proc: main is func
Line 4,938 ⟶ 5,891:
end for;
end for;
end func;</
{{out}}
Line 4,977 ⟶ 5,930:
=={{header|Self}}==
Nicely factored:
<
parent* = traits oddball.
Line 5,008 ⟶ 5,961:
|) value printLine
</syntaxhighlight>
=={{header|SenseTalk}}==
<
"partridge in a pear tree.",
"turtle doves and",
Line 5,038 ⟶ 5,991:
end repeat
put ""
end repeat</
{{out}}
Line 5,075 ⟶ 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}}
<
var gifts = <<'EOT'.lines;
Line 5,105 ⟶ 6,090:
say gifts[i];
}
}</
{{out}}
Line 5,146 ⟶ 6,131:
=={{header|Simula}}==
{{works with|GNU Cim}}
<
Text Array days(1:12), gifts(1:12);
Integer day, gift;
Line 5,186 ⟶ 6,171:
End
End
</syntaxhighlight>
{{Out}}
Line 5,214 ⟶ 6,199:
=={{header|Smalltalk}}==
{{works with|GNU Smalltalk}}
<
Ordinals := #('first' 'second' 'third' 'fourth' 'fifth' 'sixth'
'seventh' 'eighth' 'ninth' 'tenth' 'eleventh' 'twelfth').
Line 5,240 ⟶ 6,225:
1 to: 12 do: [:i |
Transcript show: (TwelveDays giftsFor: i); cr.
].</
{{Out}}
Line 5,267 ⟶ 6,252:
=={{header|Smart BASIC}}==
<
dim d$(12),x$(15)!s=15
for t=0 to 11!read d$(t)!next t
Line 5,274 ⟶ 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."</
<pre>On the first day of Christmas
My true love gave to me:
Line 5,323 ⟶ 6,308:
=={{header|Snobol}}==
{{Works with|CSNOBOL4}}
<
DAYS<1> = 'first'
DAYS<2> = 'second'
Line 5,362 ⟶ 6,347:
NEXT OUTPUT = ''
DAY = DAY + 1 :(OUTER)
END</
{{Out}}
Line 5,387 ⟶ 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">
with
function nl ( s in varchar2 )
Line 5,427 ⟶ 6,458:
connect by level <= 12
/
</syntaxhighlight>
output:
<pre>
Line 5,456 ⟶ 6,487:
=={{header|Swift}}==
{{works with|Swift|2.1}}
<
"Three French hens", "Four calling birds",
"Five gold rings", "Six geese a-laying",
Line 5,484 ⟶ 6,515:
for day in 1...12 {
print(giftsForDay(day))
}</
{{out}}
Line 5,511 ⟶ 6,542:
=={{header|Tailspin}}==
<
def ordinal: ['first', 'second', 'third', 'fourth', 'fifth', 'sixth', 'seventh', 'eighth', 'ninth', 'tenth', 'eleventh', 'twelfth'];
def gift: [
Line 5,543 ⟶ 6,574:
' !
\singVerse) -> !OUT::write
</syntaxhighlight>
{{out}}
<pre>
Line 5,575 ⟶ 6,606:
</pre>
=={{header|Terraform}}==
<
days = [ "first", "second", "third", "fourth", "fifth", "sixth",
"seventh", "eighth", "ninth", "tenth", "eleventh", "twelfth" ]
Line 5,601 ⟶ 6,632:
output "lyrics" {
value = join("\n\n",[for t in data.template_file.days: t.rendered])
}</
Line 5,636 ⟶ 6,667:
=={{header|Tcl}}==
{{works with|Tcl|8.6}}
<
first second third fourth fifth sixth
seventh eighth ninth tenth eleventh twelfth
Line 5,658 ⟶ 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]</
{{out}}
<pre style="height:55ex;overflow:scroll">
Line 5,775 ⟶ 6,806:
A partridge in a pear tree.
</pre>
=={{header|uBasic/4tH}}==
<syntaxhighlight lang="text">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 "first", "second", "third", "fourth"
Push "fifth", "sixth", "seventh", "eighth"
Push "ninth", "tenth", "eleventh", "twelfth"
Return
_DataGifts
Push "A partridge in a pear tree."
Push "Two turtle doves and"
Push "Three french hens"
Push "Four calling birds"
Push "Five golden rings"
Push "Six geese a-laying"
Push "Seven swans a-swimming"
Push "Eight maids a-milking"
Push "Nine ladies dancing"
Push "Ten lords a-leaping"
Push "Eleven pipers piping"
Push "Twelve drummers drumming"
Return</syntaxhighlight>
=={{header|UNIX Shell}}==
{{works with|Bourne Again SHell}}
{{works with|Korn Shell|93}}
<
ordinals=(first second third fourth fifth sixth
seventh eighth ninth tenth eleventh twelfth)
Line 5,801 ⟶ 6,880:
for (( day=0; day < 12; ++day )); do
echo_gifts $day
done</
The above will also work in zsh if the index range is changed from 0..11 to 1..12.
Line 5,808 ⟶ 6,887:
(requires the '''seq''' command)
<
ordinal() {
n=$1
Line 5,840 ⟶ 6,919:
for day in `seq 0 11`; do
echo_gifts $day
done</
{{Out}}
Line 5,867 ⟶ 6,946:
=={{header|VBA}}==
<
Dim i As Integer, c As Integer, j As Integer, strReturn() As String
Dim s, n
Line 5,882 ⟶ 6,961:
strReturn(UBound(strReturn)) = Replace(strReturn(UBound(strReturn)), "and" & vbCrLf & "A", vbCrLf & "And a")
Debug.Print Join(strReturn, vbCrLf)
End Sub</
{{out}}
<pre>On the first day of Christmas,
Line 5,915 ⟶ 6,994:
=={{header|VBScript}}==
<
"seventh","eight","ninth","tenth","eleventh","twelfth")
Line 5,941 ⟶ 7,020:
End If
WScript.StdOut.WriteBlankLines(2)
Next</
Line 5,947 ⟶ 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.
<
Num_Str(#1, 9, LEFT)
IT("On the ")
Line 5,982 ⟶ 7,061:
:gift 2: IT("Two turtle doves, and") IN
:gift 1: IT("A partridge in a pear tree.") IN
return </
=={{header|Vim Script}}==
{{trans|Raku}}
<
let b:days=["first", "second", "third", "fourth", "fifth", "sixth",
\ "seventh", "eighth", "ninth", "tenth", "eleventh", "twelfth"]
Line 6,022 ⟶ 7,101:
endwhile
let b:day = b:day + 1
endwhile</
{{Out}}
Line 6,052 ⟶ 7,131:
'''Compiler:''' Roslyn Visual Basic (language version >= 14, e.g. with Visual Studio 2015)
<
Sub Main()
Dim days = New String(11) {"first", "second", "third", "fourth", "fifth", "sixth", "seventh", "eighth", "ninth", "tenth", "eleventh", "twelfth"}
Line 6,082 ⟶ 7,161:
Next
End Sub
End Module</
=={{header|Wren}}==
<
"first", "second", "third", "fourth", "fifth", "sixth",
"seventh", "eighth", "ninth", "tenth", "eleventh", "twelfth"
Line 6,102 ⟶ 7,181:
for (j in i..0) System.print(gifts[j])
System.print()
}</
=={{header|XPL0}}==
<
[Day:= [0, "first", "second", "third", "forth", "fifth", "sixth",
"seventh", "eighth", "ninth", "tenth", "eleventh", "twelfth"];
Line 6,129 ⟶ 7,208:
CrLf(0);
];
]</
{{out}}
Line 6,157 ⟶ 7,236:
A partridge in a pear tree.
</pre>
=={{header|Z80 Assembly}}==
You can copy-paste this into the WinAPE assembler and it will work. Run it with <code>CALL &8000</code> (remember that Shift+6 on the keyboard will give you & on Winape!) Press any key to advance to the next verse. This was repurposed from my entry to the Old Lady Swallowed A Fly task.
<syntaxhighlight lang="z80">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.</syntaxhighlight>
=={{header|zkl}}==
{{trans|Python}}
<
#<<<
"A beer, in a tree.; Two turtlenecks; Three french toast;
Line 6,176 ⟶ 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");
}</
{{out}}
|