This commit is contained in:
2024-07-04 17:39:14 -04:00
parent 2eb14fcd40
commit 7b3e6d3216
10 changed files with 502 additions and 0 deletions

36
elixir/house/lib/house.ex Normal file
View File

@@ -0,0 +1,36 @@
defmodule House do
@doc """
Return verses of the nursery rhyme 'This is the House that Jack Built'.
"""
@this_is "This is"
@verses [
"house that Jack built",
"malt that lay in",
"rat that ate",
"cat that killed",
"dog that worried",
"cow with the crumpled horn that tossed",
"maiden all forlorn that milked",
"man all tattered and torn that kissed",
"priest all shaven and shorn that married",
"rooster that crowed in the morn that woke",
"farmer sowing his corn that kept",
"horse and the hound and the horn that belonged to"
]
@spec recite(start :: integer, stop :: integer) :: String.t()
def recite(start, stop) do
(Enum.map(start..stop, &verse/1) |> Enum.join("\n")) <> "\n"
end
defp verse(i) do
verse =
@verses
|> Enum.take(i)
|> Enum.reverse()
|> Enum.join(" the ")
@this_is <> " the " <> verse <> "."
end
end