The Twelve Days of Christmas: Difference between revisions

→‎{{header|q}}: removed redundant iteration and variable
imported>Arakov
(→‎{{header|q}}: removed redundant iteration and variable)
 
(9 intermediate revisions by 2 users not shown)
Line 465:
Two turtle doves, and
A partridge in a pear tree.</pre>
 
=={{header|APL}}==
{{works with|Dyalog APL}}
{{trans|Forth}}
<syntaxhighlight lang="apl">ord ← { ⍵ ⌷ 'first' 'second' 'third' 'fourth' 'fifth' 'sixth' 'seventh' 'eighth' 'ninth' 'tenth' 'eleventh' 'twelfth' }
 
gift ← { ⍵ ⌷ 'A partridge in a pear tree.' 'Two turtle doves, and' 'Three French hens,' 'Four calling birds,' 'Five gold rings,' 'Six geese a-laying,' 'Seven swans a-swimming,' 'Eight maids a-milking,' 'Nine ladies dancing,' 'Ten lords a-leaping,' 'Eleven pipers piping,' 'Twelve drummers drumming,' }
 
day ← { ⎕ ← (⎕ucs 10),'On the',(ord ⍵),'day of Christmas, my true love sent to me:' ⋄ { ⎕ ← gift ⍵ } ¨ ⌽⍳⍵ }
 
day ¨ ⍳12</syntaxhighlight>
 
{{Out}}
<pre>
On the first day of Christmas, my true love sent to me:
A partridge in a pear tree.
 
 
On the second day of Christmas, my true love sent to me:
Two turtle doves, and
A partridge in a pear tree.
 
 
On the third day of Christmas, my true love sent to me:
Three French hens,
Two turtle doves, and
A partridge in a pear tree.
 
[...]
 
On the twelfth day of Christmas, my true love sent to me:
Twelve drummers drumming,
Eleven pipers piping,
Ten lords a-leaping,
Nine ladies dancing,
Eight maids a-milking,
Seven swans a-swimming,
Six geese a-laying,
Five gold rings,
Four calling birds,
Three French hens,
Two turtle doves, and
A partridge in a pear tree.</pre>
 
=={{header|AppleScript}}==
Line 2,310 ⟶ 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 3,384 ⟶ 3,514:
=={{header|LOLCODE}}==
{{works with|LCI 0.10}}
<syntaxhighlight lang="text">CANHAI HAS STDIO?1.2
CAN HAS STDIO?
HAI 1.2
 
I HAS A Dayz ITZ A BUKKIT
Line 4,634 ⟶ 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}}==
Line 4,687 ⟶ 4,886:
A partridge in a pear tree.
 
[ ... ]
 
On the twelfth day of Christmas, my true love sent to me:
Line 4,823 ⟶ 5,022:
=={{header|q}}==
<syntaxhighlight lang="q">
daysDAYS:" "vs"first second third fourth fifth sixth seventh eighth ninth tenth eleventh twelfth",
" seventh eighth ninth tenth eleventh twelfth"
 
STANZA:( / final stanza
gifts:(
"On the twelfth day of Christmas";
"My true love gave to me:";
"Twelve drummers drumming";
"Eleven pipers piping";
Line 4,840 ⟶ 5,042:
"")
 
-1 raze
verses:stanza 0 1,/:{(reverse x)+2+til each 2+x}til 12
lyric:raze .[;0 2;{"A",5_x}5_] verses{@[x;0;ssr[;"twelfth";y]]}'days / tweak one line
.[;(::;0);ssr[;"twelfth";];DAYS] / number the verses
 
STANZA 0 1,/:#\:[;til 15] -2 -til 12; / compose 12 verses
1 "\n"sv lyric; // print
</syntaxhighlight>
{{out}}
Line 4,872 ⟶ 5,074:
And a partridge in a pear tree.
</pre>
* [https://code.kx.com/q/ref/ Language Reference]
* [https://code.kx.com/q/learn/pb/xmas-days/ The Q Playbook: The Twelve Days of Christmas – analysis]
 
=={{header|Quackery}}==
Line 6,963 ⟶ 7,164:
 
=={{header|Wren}}==
<syntaxhighlight lang="ecmascriptwren">var days = [
"first", "second", "third", "fourth", "fifth", "sixth",
"seventh", "eighth", "ninth", "tenth", "eleventh", "twelfth"
38

edits