The Twelve Days of Christmas: Difference between revisions

→‎{{header|q}}: removed redundant iteration and variable
m (→‎Fish: Format twelfth to match other ordinals.)
(→‎{{header|q}}: removed redundant iteration and variable)
 
(5 intermediate revisions by 2 users not shown)
Line 473:
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 ⍵ } ¨ ⌽⍳⍵ }
 
{ ⎕←⎕ucs 10⋄day ⍵ }day ¨ ⍳12</syntaxhighlight>
 
{{Out}}
Line 2,370:
> "c" 4 0 p 0 1 .
> \
/ " day of Christmas, my true love gavesent to me:" a 0 /
> "f" 4 0 p 0 1 .
> "1" 6 4 p "4" 4 0 p : 0 3 .
Line 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,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,817 ⟶ 4,886:
A partridge in a pear tree.
 
[ ... ]
 
On the twelfth day of Christmas, my true love sent to me:
Line 4,953 ⟶ 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,970 ⟶ 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 5,002 ⟶ 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 7,093 ⟶ 7,164:
 
=={{header|Wren}}==
<syntaxhighlight lang="ecmascriptwren">var days = [
"first", "second", "third", "fourth", "fifth", "sixth",
"seventh", "eighth", "ninth", "tenth", "eleventh", "twelfth"
38

edits