How to resolve the algorithm The Twelve Days of Christmas step by step in the J programming language

Published on 12 May 2024 09:40 PM
#J

How to resolve the algorithm The Twelve Days of Christmas step by step in the J programming language

Table of Contents

Problem Statement

Write a program that outputs the lyrics of the Christmas carol The Twelve Days of Christmas. The lyrics can be found here.
(You must reproduce the words in the correct order, but case, format, and punctuation are left to your discretion.)

Let's start with the solution:

Step by Step solution about How to resolve the algorithm The Twelve Days of Christmas step by step in the J programming language

Source code in the j programming language

require 'strings'  NB. not necessary for versions > j6

days=: ;:'first second third fourth fifth sixth seventh eighth ninth tenth eleventh twelfth'

gifts=: <;.2 ] 0 : 0
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,
)

firstline=: 'On the ' , ,&(' day of Christmas, my true love gave to me',LF)

chgFirstVerse=: rplc&('nd a';'')&.>@{. , }.

makeVerses=: [: chgFirstVerse (firstline&.> days) ,&.> [: <@;@|.\ gifts"_

singCarol=: LF joinstring makeVerses


  

You may also check:How to resolve the algorithm Bernoulli numbers step by step in the FunL programming language
You may also check:How to resolve the algorithm Truth table step by step in the Clojure programming language
You may also check:How to resolve the algorithm Safe primes and unsafe primes step by step in the Simula programming language
You may also check:How to resolve the algorithm String concatenation step by step in the Lisaac programming language
You may also check:How to resolve the algorithm Sum and product of an array step by step in the Groovy programming language