How to resolve the algorithm The Twelve Days of Christmas step by step in the Nim 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 Nim 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 Nim programming language

Source code in the nim programming language

import strutils, algorithm

const
  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"]

  Days = ["first", "second", "third", "fourth", "fifth", "sixth",
          "seventh", "eighth", "ninth", "tenth", "eleventh", "twelfth"]

for n, day in Days:
  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])


  

You may also check:How to resolve the algorithm Knuth's power tree step by step in the jq programming language
You may also check:How to resolve the algorithm Sierpinski triangle step by step in the X86 Assembly programming language
You may also check:How to resolve the algorithm Parsing/RPN calculator algorithm step by step in the Quackery programming language
You may also check:How to resolve the algorithm Variables step by step in the AArch64 Assembly programming language
You may also check:How to resolve the algorithm Sorting algorithms/Gnome sort step by step in the AArch64 Assembly programming language