Skip to content

Instantly share code, notes, and snippets.

@yowchun93
Created February 15, 2021 03:43
Show Gist options
  • Save yowchun93/9bf982163a752a3d8bb7e195118f8746 to your computer and use it in GitHub Desktop.
Save yowchun93/9bf982163a752a3d8bb7e195118f8746 to your computer and use it in GitHub Desktop.
Elixir
defmodule DeafAunty do
def run do
read_input(0)
end
# main loop
defp read_input(consecutive_byes) when consecutive_byes < 3 do
IO.read(:stdio, :line)
|> String.trim
|> talk_to_aunty(consecutive_byes)
end
defp read_input(consecutive_byes) when consecutive_byes >= 3 do
say_goodbye()
end
defp talk_to_aunty(sentence, consecutive_byes) do
if sentence == "BYE" do
IO.puts "What!? You want to leave????"
read_input(consecutive_byes + 1)
else
IO.puts sentence
read_input(consecutive_byes)
end
end
defp say_goodbye do
IO.puts("Okay BYE!")
end
end
DeafAunty.run()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment