The Twelve Days of Christmas: Difference between revisions
m
syntax highlighting fixup automation
(The Twelve Days of Christmas in BASIC256) |
Thundergnat (talk | contribs) m (syntax highlighting fixup automation) |
||
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!}}==
<
BYTE RTCLOK=$14
frames==+RTCLOK
Line 225:
Wait(50)
OD
RETURN</
{{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)
<
import flash.display.Sprite;
Line 372:
}
}</
=={{header|Ada}}==
<
with Ada.Strings.Unbounded; use Ada.Strings.Unbounded;
Line 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 440:
print(newline)
OD
END</
{{Out}}
Line 468:
=={{header|AppleScript}}==
===Iterative===
<
"Three French hens,", "Four calling birds,", ¬
"Five gold rings,", "Six geese a-laying,", ¬
Line 484:
end repeat
log ""
end repeat</
{{Out}}
Line 515:
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 650:
((ca's NSString's stringWithString:(str))'s ¬
uppercaseStringWithLocale:(ca's NSLocale's currentLocale())) as text
end toUpper</
{{Out}}
Line 678:
=={{header|Arturo}}==
<
"A partridge in a pear tree."
"Two turtle doves"
Line 704:
-> capitalize last g
print ""
]</
{{out}}
Line 823:
=={{header|AutoHotkey}}==
<
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</
=={{header|AWK}}==
<syntaxhighlight lang="awk">
# syntax: GAWK -f THE_TWELVE_DAYS_OF_CHRISTMAS.AWK
BEGIN {
Line 873:
exit(0)
}
</syntaxhighlight>
{{out}}
<pre>
Line 904:
=={{header|Batch File}}==
<
:: Batch File Implementation
Line 953:
echo(
)
exit /b</
=={{header|BASIC}}==
<
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"</
=={{header|BASIC256}}==
<
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</
=={{header|BCPL}}==
<
let ordinal(n) =
Line 1,028:
$)
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 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</
=={{header|Bracmat}}==
<
second
third
Line 1,080:
)
)
);</
=={{header|C}}==
<syntaxhighlight lang="c">
#include<stdio.h>
Line 1,133:
return 0;
}</
=={{header|C sharp|C#}}==
<
public class TwelveDaysOfChristmas {
Line 1,178:
}
}</
=={{header|C++}}==
<
#include <array>
#include <string>
Line 1,238:
return 0;
}</
=={{header|Clojure}}==
{{trans|Raku}}
<
[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>
{{Out}}
<pre>On the first day of Christmas, my true love sent to me:
Line 1,290:
=={{header|CLU}}==
<
rep = null
Line 1,332:
start_up = proc ()
christmas$carol(stream$primary_output())
end start_up</
=={{header|COBOL}}==
{{works with|GNU Cobol|2.0}}
<
PROGRAM-ID. twelve-days-of-christmas.
Line 1,379:
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,396:
(format t "~a~%" (nth gift gifts)))
(format t "~%")))
</syntaxhighlight>
{{Out}}
Line 1,423:
=={{header|Cowgol}}==
<
var ordinals: [uint8][] := {
Line 1,460:
print_nl();
verse := verse + 1;
end loop;</
=={{header|Crystal}}==
{{trans|Ruby}}
<
gifts = "A partridge in a pear tree
Two turtle doves and
Line 1,482:
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,514:
(n > 0 ? " and\n" ~ g.back : g.back.capitalize), '\n');
}
}</
=={{header|dc}}==
<
d [first] r :n
Line 1,583:
0 ll x
</syntaxhighlight>
{{Out}}
Line 1,610:
=={{header|Dyalect}}==
<
"first", "second", "third", "fourth", "fifth", "sixth", "seventh", "eighth", "ninth",
"tenth", "eleventh", "twelfth"
Line 1,635:
}
print()
}</
=={{header|Eiffel}}==
<syntaxhighlight lang="eiffel">
class
APPLICATION
Line 1,694:
end
</syntaxhighlight>
=={{header|Elena}}==
{{trans|C++}}
ELENA 5.0 :
<
public program()
Line 1,741:
console.printLine()
}
}</
=={{header|Elixir}}==
<
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)</
{{out}}
Line 1,797:
=={{header|Erlang}}==
<
-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>
{{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#}}==
<
"And a partridge in a pear tree";
"Two turtle doves";
Line 1,870:
printf "\n"
List.iter displayGifts [0..11]</
=={{header|Factor}}==
<
IN: rosetta-code.twelve-days-of-christmas
Line 1,906:
: twelve-days-of-christmas ( -- ) 12 [1,b] [ verse ] each ;
MAIN: twelve-days-of-christmas</
{{out}}
<pre>
Line 1,935:
=={{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,971:
main
bye
</syntaxhighlight>
{{Out}}
Line 1,999:
=={{header|Fortran}}==
{{works with|Fortran|FORTRAN|77}}
<
character days(12)*8
Line 2,031:
10 continue
end
</syntaxhighlight>
{{Out}}
Line 2,058:
=={{header|FreeBASIC}}==
<
' compile with: fbc -s console
Line 2,093:
Print : 'Print "hit any key to end program"
Sleep
End</
{{out}}
<pre> On the first day of Christmas
Line 2,123:
=={{header|Go}}==
[https://play.golang.org/p/dnDyx8ee_G Go Playground]
<
import (
Line 2,148:
}
}
</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,162:
}
println()
}</
=={{header|Haskell}}==
{{trans|F#}}
<
gifts =
[ "And a partridge in a pear tree!",
Line 2,210:
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,317:
Works in both languages.
<
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</
=={{header|J}}==
<
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</
=={{header|Java}}==
<
final static String[] gifts = {
Line 2,385:
}
}
}</
=={{header|JavaScript}}==
<syntaxhighlight 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>
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,510:
'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,536:
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,579:
//... etc.
]</
=={{header|jq}}==
<
"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>
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.
<
"use strict";
Line 2,781:
And a partridge in a pear tree
=!EXPECTEND!=
*/</
{{out}}
Line 2,789:
=={{header|Julia}}==
<
function printlyrics()
Line 2,821:
end
printlyrics()</
{{out}}
Line 2,852:
=={{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,872:
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,927:
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,951:
]
]
bye</
{{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</
{{Out}}
Line 3,060:
=={{header|Lua}}==
<syntaxhighlight lang="lua">
local days = {
'first', 'second', 'third', 'fourth', 'fifth', 'sixth', 'seventh', 'eighth', 'ninth',
Line 3,099:
print(table.concat(verses, '\n\n'))
</syntaxhighlight>
=={{header|MAD}}==
<
THROUGH VERSE, FOR I=1, 1, I.G.12
Line 3,143:
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,160:
end do;
printf("\n");
end do;</
{{out}}
<pre>
Line 3,211:
=={{header|Mathematica}}/{{header|Wolfram Language}}==
<
"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}]</
{{out}}
<pre style="height:55ex;overflow:scroll">
Line 3,329:
=={{header|MiniScript}}==
<
"seventh","eigth","nineth","tenth","eleventh","twelfth"]
gifts = ["A partridge in a pear tree.","Two turtle doves, and",
Line 3,346:
print " ----------"
end for
</syntaxhighlight>
{{out}}
<pre>
Line 3,375:
=={{header|Nim}}==
{{trans|Python}}
<
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])</
{{out}}
Line 3,428:
=={{header|Objeck}}==
{{trans|C sharp|C#}}
<
class TwelveDaysOfChristmas {
function : Main(args : String[]) ~ Nil {
Line 3,464:
}
}
</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,475:
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,500:
This should work with any modern Pascal implementation that has a '''string''' type, e.g. [[Free Pascal]].
<
const
Line 3,531:
writeln
end
end.</
{{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:
<
const
Line 3,590:
writeln
end
end.</
{{Out}}
Line 3,617:
=={{header|Perl}}==
<
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.</
{{out}}
<pre>On the first day of Christmas,
Line 3,670:
=={{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,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>
<!--</
=={{header|Phixmonti}}==
<
( "A partridge in a pear tree."
Line 3,723:
swap
nl
endfor</
=={{header|PHP}}==
<syntaxhighlight lang="php">
<?php
Line 3,773:
?>
</syntaxhighlight>
Or using recursion:
<
$gifts = array(
Line 3,811:
twelve_days( array_reverse( $gifts, true ) );
</syntaxhighlight>
{{Out}}
<pre style="font-size:84%;height:55ex">
Line 3,919:
=={{header|Picat}}==
===List comprehension===
<
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.</
===Definite clause grammars (DCG)===
<
lyrics(Ls,[]),
println(Ls.flatten),
Line 3,979:
day(tenth) --> "Ten lords a-leaping".
day(eleventh) --> "Eleven pipers piping".
day(twelth) --> "Twelve drummers drumming".</
=={{header|PicoLisp}}==
<
first second third fourth fifth sixth
seventh eight ninth tenth eleventh twelfth )
Line 4,010:
(prinl) )
(bye)</
=={{header|Pike}}==
<
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;
}</
{{out}}
<pre>On the first day of Christmas
Line 4,057:
=={{header|PowerShell}}==
<
1 = "first";
2 = "second";
Line 4,095:
}
""
}</
{{out}}
Line 4,126:
=={{header|Prolog}}==
<
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.</
{{Out}}
Line 4,194:
=={{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 4,209:
Next I
Input()
EndIf</
{{out}}
<pre>On the first day of Christmas, my true love sent to me:
Line 4,246:
=={{header|Python}}==
<
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()))</
{{out}}
Line 4,312:
=={{header|q}}==
<syntaxhighlight 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>
{{out}}
<pre>On the first day of Christmas
Line 4,367:
=={{header|Quackery}}==
<
$ "first" $ "second" $ "third" $ "fourth"
$ "fifth" $ "sixth" $ "seventh" $ "eighth"
Line 4,393:
[ 12 times [ i^ verse ] ] is song ( --> )
song</
{{out}}
Line 4,426:
=={{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,434:
cat("My true love gave to me:\n")
cat(paste(gifts[i:1], collapse = "\n"), "\n\n")
}</
{{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.
<
(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)))</
{{out}}
Line 4,584:
=={{header|Raku}}==
(formerly Perl 6)
<syntaxhighlight lang="raku"
my @gifts = lines q:to/END/;
Line 4,610:
nth($d);
say @gifts[$_] for $d ... 0;
}</
{{out}}
<pre>On the first day of Christmas, my true love gave to me:
Line 4,652:
::* 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,667:
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,789:
=={{header|Ring}}==
<
# Project : The Twelve Days of Christmas
Line 4,808:
next
</syntaxhighlight>
Output:
<pre>
Line 4,938:
=={{header|Ruby}}==
<
Two turtle doves and
Three french hens
Line 4,959:
puts gifts[0, i+1].reverse
puts
end</
=={{header|Run BASIC}}==
<
A partridge in a pear tree.,
Two turtle doves,
Line 4,987:
print
next i
</
<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]
<
let days = ["first", "second", "third", "fourth", "fifth", "sixth", "seventh", "eighth",
"ninth", "tenth", "eleventh", "twelfth"];
Line 5,036:
println!()
}
}</
=={{header|Scala}}==
<
"A partridge in a pear tree.",
"Two turtle doves and",
Line 5,064:
(0 until 12).map(giftsForDay andThen println)
</syntaxhighlight>
{{Out}}
Line 5,093:
=={{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 5,128:
(newline)))
(exit)</
{{Out}}
Line 5,155:
=={{header|Seed7}}==
<
const proc: main is func
Line 5,180:
end for;
end for;
end func;</
{{out}}
Line 5,219:
=={{header|Self}}==
Nicely factored:
<
parent* = traits oddball.
Line 5,250:
|) value printLine
</syntaxhighlight>
=={{header|SenseTalk}}==
<
"partridge in a pear tree.",
"turtle doves and",
Line 5,280:
end repeat
put ""
end repeat</
{{out}}
Line 5,319:
=={{header|Sidef}}==
{{trans|Raku}}
<
var gifts = <<'EOT'.lines;
Line 5,347:
say gifts[i];
}
}</
{{out}}
Line 5,388:
=={{header|Simula}}==
{{works with|GNU Cim}}
<
Text Array days(1:12), gifts(1:12);
Integer day, gift;
Line 5,428:
End
End
</syntaxhighlight>
{{Out}}
Line 5,456:
=={{header|Smalltalk}}==
{{works with|GNU Smalltalk}}
<
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.
].</
{{Out}}
Line 5,509:
=={{header|Smart BASIC}}==
<
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."</
<pre>On the first day of Christmas
My true love gave to me:
Line 5,565:
=={{header|Snobol}}==
{{Works with|CSNOBOL4}}
<
DAYS<1> = 'first'
DAYS<2> = 'second'
Line 5,604:
NEXT OUTPUT = ''
DAY = DAY + 1 :(OUTER)
END</
{{Out}}
Line 5,633:
Demonstration of Oracle 12c "with" clause enhancement.
<syntaxhighlight lang="sql">
with
function nl ( s in varchar2 )
Line 5,669:
connect by level <= 12
/
</syntaxhighlight>
output:
<pre>
Line 5,698:
=={{header|Swift}}==
{{works with|Swift|2.1}}
<
"Three French hens", "Four calling birds",
"Five gold rings", "Six geese a-laying",
Line 5,726:
for day in 1...12 {
print(giftsForDay(day))
}</
{{out}}
Line 5,753:
=={{header|Tailspin}}==
<
def ordinal: ['first', 'second', 'third', 'fourth', 'fifth', 'sixth', 'seventh', 'eighth', 'ninth', 'tenth', 'eleventh', 'twelfth'];
def gift: [
Line 5,785:
' !
\singVerse) -> !OUT::write
</syntaxhighlight>
{{out}}
<pre>
Line 5,817:
</pre>
=={{header|Terraform}}==
<
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])
}</
Line 5,878:
=={{header|Tcl}}==
{{works with|Tcl|8.6}}
<
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]</
{{out}}
<pre style="height:55ex;overflow:scroll">
Line 6,022:
{{works with|QBasic|1.1}}
{{works with|QuickBasic|4.5}}
<
DATA "seventh","eighth","ninth","tenth","eleventh","twelfth"
DATA "A partridge in a pear tree."
Line 6,053:
PRINT
NEXT i
END</
=={{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</
=={{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 6,129:
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 6,136:
(requires the '''seq''' command)
<
ordinal() {
n=$1
Line 6,168:
for day in `seq 0 11`; do
echo_gifts $day
done</
{{Out}}
Line 6,195:
=={{header|VBA}}==
<
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</
{{out}}
<pre>On the first day of Christmas,
Line 6,243:
=={{header|VBScript}}==
<
"seventh","eight","ninth","tenth","eleventh","twelfth")
Line 6,269:
End If
WScript.StdOut.WriteBlankLines(2)
Next</
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.
<
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 </
=={{header|Vim Script}}==
{{trans|Raku}}
<
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</
{{Out}}
Line 6,380:
'''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,410:
Next
End Sub
End Module</
=={{header|Wren}}==
<
"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()
}</
=={{header|XPL0}}==
<
[Day:= [0, "first", "second", "third", "forth", "fifth", "sixth",
"seventh", "eighth", "ninth", "tenth", "eleventh", "twelfth"];
Line 6,457:
CrLf(0);
];
]</
{{out}}
Line 6,488:
=={{header|Yabasic}}==
<
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"</
Line 6,519:
<
PrintChar equ &BB5A ;print accumulator to screen
Line 6,772:
Song_NewLine:
byte 13,10,0 ;control codes for a new line.</
=={{header|zkl}}==
{{trans|Python}}
<
#<<<
"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");
}</
{{out}}
|