We're a place where coders share, stay up-to-date and grow their careers.
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
Elixir: