Jump to content

The Twelve Days of Christmas: Difference between revisions

m
syntax highlighting fixup automation
(The Twelve Days of Christmas in BASIC256)
m (syntax highlighting fixup automation)
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 468:
=={{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:
end repeat
log ""
end repeat</langsyntaxhighlight>
 
{{Out}}
Line 515:
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:
((ca's NSString's stringWithString:(str))'s ¬
uppercaseStringWithLocale:(ca's NSLocale's currentLocale())) as text
end toUpper</langsyntaxhighlight>
 
{{Out}}
Line 678:
=={{header|Arturo}}==
 
<langsyntaxhighlight lang="rebol">gifts: [
"A partridge in a pear tree."
"Two turtle doves"
Line 704:
-> capitalize last g
print ""
]</langsyntaxhighlight>
 
{{out}}
Line 823:
 
=={{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:
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:
exit(0)
}
</syntaxhighlight>
</lang>
{{out}}
<pre>
Line 904:
 
=={{header|Batch File}}==
<langsyntaxhighlight lang="dos">:: The Twelve Days of Christmas
:: Batch File Implementation
 
Line 953:
echo(
)
exit /b</langsyntaxhighlight>
 
=={{header|BASIC}}==
 
<langsyntaxhighlight 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:
210 DATA "Ten lords a-leaping"
220 DATA "Eleven pipers piping"
230 DATA "Twelve drummers drumming"</langsyntaxhighlight>
 
=={{header|BASIC256}}==
<langsyntaxhighlight BASIC256lang="basic256">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"}
Line 994:
next j
print
next i</langsyntaxhighlight>
 
=={{header|BCPL}}==
<langsyntaxhighlight BCPLlang="bcpl">get "libhdr"
 
let ordinal(n) =
Line 1,028:
$)
 
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,040:
-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,080:
)
)
);</langsyntaxhighlight>
 
=={{header|C}}==
<syntaxhighlight lang="c">
<lang C>
#include<stdio.h>
Line 1,133:
return 0;
}</langsyntaxhighlight>
 
=={{header|C sharp|C#}}==
<langsyntaxhighlight lang="csharp">using System;
 
public class TwelveDaysOfChristmas {
Line 1,178:
}
 
}</langsyntaxhighlight>
 
=={{header|C++}}==
<langsyntaxhighlight lang="cpp">#include <iostream>
#include <array>
#include <string>
Line 1,238:
 
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,264:
(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,290:
 
=={{header|CLU}}==
<langsyntaxhighlight lang="clu">christmas = cluster is carol
rep = null
Line 1,332:
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,379:
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,396:
(format t "~a~%" (nth gift gifts)))
(format t "~%")))
</syntaxhighlight>
</lang>
 
{{Out}}
Line 1,423:
 
=={{header|Cowgol}}==
<langsyntaxhighlight lang="cowgol">include "cowgol.coh";
 
var ordinals: [uint8][] := {
Line 1,460:
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,482:
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,514:
(n > 0 ? " and\n" ~ g.back : g.back.capitalize), '\n');
}
}</langsyntaxhighlight>
 
=={{header|dc}}==
<langsyntaxhighlight lang="dc">0
 
d [first] r :n
Line 1,583:
 
0 ll x
</syntaxhighlight>
</lang>
 
{{Out}}
Line 1,610:
 
=={{header|Dyalect}}==
<langsyntaxhighlight lang="dyalect">let days = [
"first", "second", "third", "fourth", "fifth", "sixth", "seventh", "eighth", "ninth",
"tenth", "eleventh", "twelfth"
Line 1,635:
}
print()
}</langsyntaxhighlight>
 
=={{header|Eiffel}}==
<syntaxhighlight lang="eiffel">
<lang Eiffel>
class
APPLICATION
Line 1,694:
 
end
</syntaxhighlight>
</lang>
 
=={{header|Elena}}==
{{trans|C++}}
ELENA 5.0 :
<langsyntaxhighlight lang="elena">import extensions;
public program()
Line 1,741:
console.printLine()
}
}</langsyntaxhighlight>
 
=={{header|Elixir}}==
<langsyntaxhighlight lang="elixir">gifts = """
A partridge in a pear tree
Two turtle doves and
Line 1,766:
Enum.take(gifts, i+1) |> Enum.reverse |> Enum.each(&IO.puts &1)
IO.puts ""
end)</langsyntaxhighlight>
 
{{out}}
Line 1,797:
 
=={{header|Erlang}}==
<langsyntaxhighlight lang="erlang">-module(twelve_days).
-export([gifts_for_day/1]).
 
Line 1,817:
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,842:
 
=={{header|F Sharp|F#}}==
<langsyntaxhighlight lang="fsharp">let gifts = [
"And a partridge in a pear tree";
"Two turtle doves";
Line 1,870:
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,906:
: twelve-days-of-christmas ( -- ) 12 [1,b] [ verse ] each ;
 
MAIN: twelve-days-of-christmas</langsyntaxhighlight>
{{out}}
<pre>
Line 1,935:
=={{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,971:
main
bye
</syntaxhighlight>
</lang>
 
{{Out}}
Line 1,999:
=={{header|Fortran}}==
{{works with|Fortran|FORTRAN|77}}
<langsyntaxhighlight lang="fortran"> program twelve_days
 
character days(12)*8
Line 2,031:
10 continue
end
</syntaxhighlight>
</lang>
 
{{Out}}
Line 2,058:
 
=={{header|FreeBASIC}}==
<langsyntaxhighlight lang="freebasic">' version 10-01-2017
' compile with: fbc -s console
 
Line 2,093:
Print : 'Print "hit any key to end program"
Sleep
End</langsyntaxhighlight>
{{out}}
<pre> On the first day of Christmas
Line 2,123:
=={{header|Go}}==
[https://play.golang.org/p/dnDyx8ee_G Go Playground]
<langsyntaxhighlight lang="go">package main
 
import (
Line 2,148:
}
}
</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,162:
}
println()
}</langsyntaxhighlight>
 
=={{header|Haskell}}==
{{trans|F#}}
<langsyntaxhighlight lang="haskell">gifts :: [String]
gifts =
[ "And a partridge in a pear tree!",
Line 2,210:
 
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,317:
 
Works in both languages.
<langsyntaxhighlight lang="unicon">procedure main()
days := ["first","second","third","fourth","fifth","sixth","seventh",
"eighth","ninth","tenth","eleventh","twelveth"]
Line 2,329:
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,357:
makeVerses=: [: chgFirstVerse (firstline&.> days) ,&.> [: <@;@|.\ gifts"_
 
singCarol=: LF joinstring makeVerses</langsyntaxhighlight>
 
=={{header|Java}}==
<langsyntaxhighlight lang="java">public class TwelveDaysOfChristmas {
 
final static String[] gifts = {
Line 2,385:
}
}
}</langsyntaxhighlight>
 
=={{header|JavaScript}}==
<syntaxhighlight lang="javascript">
<lang JavaScript>
var days = [
'first', 'second', 'third', 'fourth', 'fifth', 'sixth', 'seventh', 'eighth', 'ninth',
Line 2,431:
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,510:
'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,536:
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,579:
//... 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,596:
" " + $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,633:
=={{header|Jsish}}==
Based on Javascript entry, almost identical, added unitTest.
<langsyntaxhighlight lang="javascript">#!/usr/bin/env jsish
"use strict";
 
Line 2,781:
And a partridge in a pear tree
=!EXPECTEND!=
*/</langsyntaxhighlight>
 
{{out}}
Line 2,789:
 
=={{header|Julia}}==
<langsyntaxhighlight lang="julia"># v0.6.0
 
function printlyrics()
Line 2,821:
end
 
printlyrics()</langsyntaxhighlight>
 
{{out}}
Line 2,852:
=={{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,872:
 
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,927:
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,951:
]
]
bye</langsyntaxhighlight>
 
{{Out}}
Line 2,980:
=={{header|LOLCODE}}==
{{works with|LCI 0.10}}
<syntaxhighlight lang="text">CAN HAS STDIO?
HAI 1.2
 
Line 3,032:
IM OUTTA YR Outer
KTHXBYE</langsyntaxhighlight>
 
{{Out}}
Line 3,060:
 
=={{header|Lua}}==
<syntaxhighlight lang="lua">
<lang Lua>
local days = {
'first', 'second', 'third', 'fourth', 'fifth', 'sixth', 'seventh', 'eighth', 'ninth',
Line 3,099:
 
print(table.concat(verses, '\n\n'))
</syntaxhighlight>
</lang>
 
=={{header|MAD}}==
 
<langsyntaxhighlight MADlang="mad"> NORMAL MODE IS INTEGER
THROUGH VERSE, FOR I=1, 1, I.G.12
Line 3,143:
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,160:
end do;
printf("\n");
end do;</langsyntaxhighlight>
{{out}}
<pre>
Line 3,211:
 
=={{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,223:
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,329:
 
=={{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,346:
print " ----------"
end for
</syntaxhighlight>
</lang>
{{out}}
<pre>
Line 3,375:
=={{header|Nim}}==
{{trans|Python}}
<langsyntaxhighlight lang="nim">import strutils, algorithm
 
const
Line 3,397:
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,428:
=={{header|Objeck}}==
{{trans|C sharp|C#}}
<langsyntaxhighlight lang="objeck">
class TwelveDaysOfChristmas {
function : Main(args : String[]) ~ Nil {
Line 3,464:
}
}
</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,475:
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,500:
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,531:
writeln
end
end.</langsyntaxhighlight>
{{Out}}
<pre>On the first day of Christmas, my true love sent to me:
Line 3,558:
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,590:
writeln
end
end.</langsyntaxhighlight>
 
{{Out}}
Line 3,617:
 
=={{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,641:
Three french hens
Two turtle doves
And a partridge in a pear tree.</langsyntaxhighlight>
{{out}}
<pre>On the first day of Christmas,
Line 3,670:
 
=={{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,691:
<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,723:
swap
nl
endfor</langsyntaxhighlight>
 
=={{header|PHP}}==
<syntaxhighlight lang="php">
<lang PHP>
<?php
 
Line 3,773:
 
?>
</syntaxhighlight>
</lang>
 
Or using recursion:
 
<langsyntaxhighlight PHPlang="php"><?php
 
$gifts = array(
Line 3,811:
twelve_days( array_reverse( $gifts, true ) );
 
</syntaxhighlight>
</lang>
{{Out}}
<pre style="font-size:84%;height:55ex">
Line 3,919:
=={{header|Picat}}==
===List comprehension===
<langsyntaxhighlight Picatlang="picat">go =>
Days = "first second third fourth fifth sixth seventh eighth ninth tenth eleventh twelfth".split(" "),
Gifts =
Line 3,938:
Day, slice(Gifts,1,D).reverse().join("\n")) : {Day,D} in zip(Days,1..length(Days))]
.join("\n")),
nl.</langsyntaxhighlight>
 
===Definite clause grammars (DCG)===
<langsyntaxhighlight Picatlang="picat">go2 ?=>
lyrics(Ls,[]),
println(Ls.flatten),
Line 3,979:
day(tenth) --> "Ten lords a-leaping".
day(eleventh) --> "Eleven pipers piping".
day(twelth) --> "Twelve drummers drumming".</langsyntaxhighlight>
 
=={{header|PicoLisp}}==
<langsyntaxhighlight PicoLisplang="picolisp">(de days
first second third fourth fifth sixth
seventh eight ninth tenth eleventh twelfth )
Line 4,010:
(prinl) )
 
(bye)</langsyntaxhighlight>
 
=={{header|Pike}}==
<langsyntaxhighlight Pikelang="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"});
Line 4,028:
}
return 0;
}</langsyntaxhighlight>
{{out}}
<pre>On the first day of Christmas
Line 4,057:
 
=={{header|PowerShell}}==
<langsyntaxhighlight PowerShelllang="powershell">$days = @{
1 = "first";
2 = "second";
Line 4,095:
}
""
}</langsyntaxhighlight>
 
{{out}}
Line 4,126:
 
=={{header|Prolog}}==
<langsyntaxhighlight lang="prolog">day(1, 'first').
day(2, 'second').
day(3, 'third').
Line 4,167:
writeLoop(N) :- Day is 13 - N, writeGifts(Day), M is N - 1, writeLoop(M).
 
main :- writeLoop(12), halt.</langsyntaxhighlight>
 
{{Out}}
Line 4,194:
 
=={{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,209:
Next I
Input()
EndIf</langsyntaxhighlight>
{{out}}
<pre>On the first day of Christmas, my true love sent to me:
Line 4,246:
 
=={{header|Python}}==
<langsyntaxhighlight lang="python">gifts = '''\
A partridge in a pear tree.
Two turtle doves
Line 4,268:
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,312:
 
=={{header|q}}==
<syntaxhighlight lang="q">
<lang q>
days:" "vs"first second third fourth fifth sixth seventh eighth ninth tenth eleventh twelfth"
 
Line 4,334:
 
1 "\n"sv lyric; // print
</syntaxhighlight>
</lang>
{{out}}
<pre>On the first day of Christmas
Line 4,367:
=={{header|Quackery}}==
 
<langsyntaxhighlight Quackerylang="quackery"> [ [ table
$ "first" $ "second" $ "third" $ "fourth"
$ "fifth" $ "sixth" $ "seventh" $ "eighth"
Line 4,393:
[ 12 times [ i^ verse ] ] is song ( --> )
song</langsyntaxhighlight>
 
{{out}}
Line 4,426:
 
=={{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,434:
cat("My true love gave to me:\n")
cat(paste(gifts[i:1], collapse = "\n"), "\n\n")
}</langsyntaxhighlight>
{{out}}
<pre>
Line 4,485:
* 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,519:
#: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,584:
=={{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,610:
nth($d);
say @gifts[$_] for $d ... 0;
}</langsyntaxhighlight>
{{out}}
<pre>On the first day of Christmas, my true love gave to me:
Line 4,652:
::* &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,667:
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,789:
 
=={{header|Ring}}==
<langsyntaxhighlight lang="ring">
# Project : The Twelve Days of Christmas
 
Line 4,808:
next
 
</syntaxhighlight>
</lang>
Output:
<pre>
Line 4,938:
 
=={{header|Ruby}}==
<langsyntaxhighlight lang="ruby">gifts = "A partridge in a pear tree
Two turtle doves and
Three french hens
Line 4,959:
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,987:
print
next i
</langsyntaxhighlight>Output:
<pre>On the first day of Christmas
My true love gave to me:
Line 5,010:
=={{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"];
Line 5,036:
println!()
}
}</langsyntaxhighlight>
 
=={{header|Scala}}==
<langsyntaxhighlight lang="scala">val gifts = Array(
"A partridge in a pear tree.",
"Two turtle doves and",
Line 5,064:
 
(0 until 12).map(giftsForDay andThen println)
</syntaxhighlight>
</lang>
 
{{Out}}
Line 5,093:
=={{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,128:
(newline)))
 
(exit)</langsyntaxhighlight>
 
{{Out}}
Line 5,155:
 
=={{header|Seed7}}==
<langsyntaxhighlight lang="seed7">$ include "seed7_05.s7i";
 
const proc: main is func
Line 5,180:
end for;
end for;
end func;</langsyntaxhighlight>
 
{{out}}
Line 5,219:
=={{header|Self}}==
Nicely factored:
<langsyntaxhighlight lang="self">(|
parent* = traits oddball.
 
Line 5,250:
 
|) value printLine
</syntaxhighlight>
</lang>
 
=={{header|SenseTalk}}==
<langsyntaxhighlight lang="sensetalk">put [
"partridge in a pear tree.",
"turtle doves and",
Line 5,280:
end repeat
put ""
end repeat</langsyntaxhighlight>
 
{{out}}
Line 5,319:
=={{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,347:
say gifts[i];
}
}</langsyntaxhighlight>
 
{{out}}
Line 5,388:
=={{header|Simula}}==
{{works with|GNU Cim}}
<langsyntaxhighlight lang="simula">Begin
Text Array days(1:12), gifts(1:12);
Integer day, gift;
Line 5,428:
End
End
</syntaxhighlight>
</lang>
 
{{Out}}
Line 5,456:
=={{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,482:
1 to: 12 do: [:i |
Transcript show: (TwelveDays giftsFor: i); cr.
].</langsyntaxhighlight>
 
{{Out}}
Line 5,509:
 
=={{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,516:
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,565:
=={{header|Snobol}}==
{{Works with|CSNOBOL4}}
<langsyntaxhighlight lang="snobol"> DAYS = ARRAY('12')
DAYS<1> = 'first'
DAYS<2> = 'second'
Line 5,604:
NEXT OUTPUT = ''
DAY = DAY + 1 :(OUTER)
END</langsyntaxhighlight>
 
{{Out}}
Line 5,633:
Demonstration of Oracle 12c "with" clause enhancement.
 
<syntaxhighlight lang="sql">
<lang SQL>
with
function nl ( s in varchar2 )
Line 5,669:
connect by level <= 12
/
</syntaxhighlight>
</lang>
output:
<pre>
Line 5,698:
=={{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,726:
for day in 1...12 {
print(giftsForDay(day))
}</langsyntaxhighlight>
 
{{out}}
Line 5,753:
 
=={{header|Tailspin}}==
<langsyntaxhighlight lang="tailspin">
def ordinal: ['first', 'second', 'third', 'fourth', 'fifth', 'sixth', 'seventh', 'eighth', 'ninth', 'tenth', 'eleventh', 'twelfth'];
def gift: [
Line 5,785:
' !
\singVerse) -> !OUT::write
</syntaxhighlight>
</lang>
{{out}}
<pre>
Line 5,817:
</pre>
=={{header|Terraform}}==
<langsyntaxhighlight lang="terraform">locals {
days = [ "first", "second", "third", "fourth", "fifth", "sixth",
"seventh", "eighth", "ninth", "tenth", "eleventh", "twelfth" ]
Line 5,843:
output "lyrics" {
value = join("\n\n",[for t in data.template_file.days: t.rendered])
}</langsyntaxhighlight>
 
 
Line 5,878:
=={{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,900:
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 6,022:
{{works with|QBasic|1.1}}
{{works with|QuickBasic|4.5}}
<langsyntaxhighlight lang="qbasic">DATA "first","second","third","fourth","fifth","sixth"
DATA "seventh","eighth","ninth","tenth","eleventh","twelfth"
DATA "A partridge in a pear tree."
Line 6,053:
PRINT
NEXT i
END</langsyntaxhighlight>
 
=={{header|uBasic/4tH}}==
<syntaxhighlight lang="text">Dim @n(12) : Dim @v(12) ' define both arrays
 
Proc _DataDays ' put data on the stack
Line 6,102:
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 6,129:
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 6,136:
(requires the '''seq''' command)
 
<langsyntaxhighlight lang="sh">#!/bin/sh
ordinal() {
n=$1
Line 6,168:
for day in `seq 0 11`; do
echo_gifts $day
done</langsyntaxhighlight>
 
{{Out}}
Line 6,195:
 
=={{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,210:
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,243:
 
=={{header|VBScript}}==
<langsyntaxhighlight lang="vb">days = Array("first","second","third","fourth","fifth","sixth",_
"seventh","eight","ninth","tenth","eleventh","twelfth")
Line 6,269:
End If
WScript.StdOut.WriteBlankLines(2)
Next</langsyntaxhighlight>
 
 
Line 6,275:
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,310:
: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,350:
endwhile
let b:day = b:day + 1
endwhile</langsyntaxhighlight>
 
{{Out}}
Line 6,380:
'''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,410:
Next
End Sub
End Module</langsyntaxhighlight>
 
=={{header|Wren}}==
<langsyntaxhighlight lang="ecmascript">var days = [
"first", "second", "third", "fourth", "fifth", "sixth",
"seventh", "eighth", "ninth", "tenth", "eleventh", "twelfth"
Line 6,430:
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,457:
CrLf(0);
];
]</langsyntaxhighlight>
 
{{out}}
Line 6,488:
 
=={{header|Yabasic}}==
<langsyntaxhighlight lang="yabasic">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
Line 6,512:
data "Ten lords a-leaping"
data "Eleven pipers piping"
data "Twelve drummers drumming"</langsyntaxhighlight>
 
 
Line 6,519:
 
 
<langsyntaxhighlight lang="z80">waitChar equ &BB06 ;wait for a key press
PrintChar equ &BB5A ;print accumulator to screen
 
Line 6,772:
 
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,792:
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}}
10,351

edits

Cookies help us deliver our services. By using our services, you agree to our use of cookies.