How to resolve the algorithm The Twelve Days of Christmas step by step in the Jsish programming language
Published on 12 May 2024 09:40 PM
How to resolve the algorithm The Twelve Days of Christmas step by step in the Jsish 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 Jsish programming language
Source code in the jsish programming language
#!/usr/bin/env jsish
"use strict";
/* Twelve Days Of Christmas, in Jsish */
var days = [
'first', 'second', 'third', 'fourth', 'fifth', 'sixth', 'seventh', 'eighth', 'ninth',
'tenth', 'eleventh', 'twelfth'
];
var gifts = [
"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"
];
var lines, verses = [], song;
for ( var i = 0; i < 12; i++ ) {
lines = [];
lines[0] = "On the " + days[i] + " day of Christmas, my true love gave to me";
var j = i + 1;
var k = 0;
while ( j-- > 0 )
lines[++k] = gifts[j];
verses[i] = lines.join('\n');
if ( i == 0 )
gifts[0] = "And a partridge in a pear tree";
}
song = verses.join('\n\n');
;song;
/*
=!EXPECTSTART!=
song ==> 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 third day of Christmas, my true love gave to me
Three french hens
Two turtle doves
And a partridge in a pear tree
On the fourth day of Christmas, my true love gave to me
Four calling birds
Three french hens
Two turtle doves
And a partridge in a pear tree
On the fifth day of Christmas, my true love gave to me
Five golden rings
Four calling birds
Three french hens
Two turtle doves
And a partridge in a pear tree
On the sixth day of Christmas, my true love gave to me
Six geese a-laying
Five golden rings
Four calling birds
Three french hens
Two turtle doves
And a partridge in a pear tree
On the seventh day of Christmas, my true love gave to me
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
On the eighth day of Christmas, my true love gave to me
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
On the ninth day of Christmas, my true love gave to me
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
On the tenth day of Christmas, my true love gave to me
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
On the eleventh day of Christmas, my true love gave to me
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
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 golden rings
Four calling birds
Three french hens
Two turtle doves
And a partridge in a pear tree
=!EXPECTEND!=
*/
You may also check:How to resolve the algorithm Four is magic step by step in the Java programming language
You may also check:How to resolve the algorithm Chinese zodiac step by step in the Fōrmulæ programming language
You may also check:How to resolve the algorithm Exponentiation order step by step in the Seed7 programming language
You may also check:How to resolve the algorithm Calculating the value of e step by step in the Phix programming language
You may also check:How to resolve the algorithm Magnanimous numbers step by step in the BBC BASIC programming language