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

Source code in the fsharp programming language

let gifts = [
    "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"
]

let days = [
    "first"; "second"; "third"; "fourth"; "fifth"; "sixth"; "seventh"; "eighth";
    "ninth"; "tenth"; "eleventh"; "twelfth"
]

let displayGifts day =
    printfn "On the %s day of Christmas, my true love gave to me" days.[day]
    if day = 0 then
        printfn "A partridge in a pear tree"
    else
        List.iter (fun i -> printfn "%s" gifts.[i]) [day..(-1)..0]
    printf "\n"
    
List.iter displayGifts [0..11]


  

You may also check:How to resolve the algorithm Higher-order functions step by step in the C# programming language
You may also check:How to resolve the algorithm I before E except after C step by step in the Clojure programming language
You may also check:How to resolve the algorithm Caesar cipher step by step in the AWK programming language
You may also check:How to resolve the algorithm Arithmetic/Integer step by step in the JavaScript programming language
You may also check:How to resolve the algorithm Nth root step by step in the bc programming language