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

Source code in the elixir programming language

gifts = """
A partridge in a pear tree
Two turtle doves and
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
""" |> String.split("\n", trim: true)

days = ~w(first second third fourth fifth sixth seventh eighth ninth tenth eleventh twelfth)

Enum.with_index(days) |> Enum.each(fn {day, i} ->
  IO.puts "On the #{day} day of Christmas"
  IO.puts "My true love gave to me:"
  Enum.take(gifts, i+1) |> Enum.reverse |> Enum.each(&IO.puts &1)
  IO.puts ""
end)


  

You may also check:How to resolve the algorithm 2048 step by step in the Seed7 programming language
You may also check:How to resolve the algorithm Create an HTML table step by step in the FreeBASIC programming language
You may also check:How to resolve the algorithm Send an unknown method call step by step in the AutoHotkey programming language
You may also check:How to resolve the algorithm Euler method step by step in the Go programming language
You may also check:How to resolve the algorithm Averages/Mean time of day step by step in the PHP programming language