DEV Community

Discussion on: Daily Challenge #28 - Kill the Monster!

Collapse
 
brightone profile image
Oleksii Filonenko • Edited

Elixir:

defmodule Monsters do
  def kill(health, monsters, damage_per_hit) do
    hits = div(monsters - 1, 3)
    total_damage = damage_per_hit * hits
    result(hits, total_damage, health - total_damage)
  end

  defp result(hits, damage, health) when health > 0,
    do: "hits: #{hits}, damage: #{damage}, health: #{health}"

  defp result(_, _, _), do: "hero died"
end