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

Source code in the groovy programming language

def presents = ['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']
['first', 'second', 'third', 'forth', 'fifth', 'sixth', 'seventh', 'eight', 'ninth', 'tenth', 'eleventh', 'Twelfth'].eachWithIndex{ day, dayIndex ->
    println "On the $day day of Christmas"
    println 'My true love gave to me:'
    (dayIndex..0).each { p ->
        print presents[p]
        println p == 1 ? ' and' : ''
    }
    println()
}


  

You may also check:How to resolve the algorithm Copy stdin to stdout step by step in the D programming language
You may also check:How to resolve the algorithm Function definition step by step in the DWScript programming language
You may also check:How to resolve the algorithm Mandelbrot set step by step in the JavaScript programming language
You may also check:How to resolve the algorithm Levenshtein distance/Alignment step by step in the Wren programming language
You may also check:How to resolve the algorithm Isqrt (integer square root) of X step by step in the Rust programming language