house
This commit is contained in:
36
elixir/house/lib/house.ex
Normal file
36
elixir/house/lib/house.ex
Normal 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
|
||||
Reference in New Issue
Block a user