Elixir
Some recursion
defmodule Cards do def blackjack(list), do: _blackjack(0, 0, list) defp _blackjack(n, a, []), do: n + _get_as(n, a) defp _blackjack(n, a, [ head | tail ]) do cond do head == "A" -> _blackjack(n, a + 1, tail) Enum.member?([ "J", "Q", "K" ], head) -> _blackjack(n + 10, a, tail) true -> _blackjack(n + String.to_integer(head), a, tail) end end defp _get_as(_n, 0), do: 0 defp _get_as(n, a) when n + a - 1 < 11, do: a + 10 defp _get_as(_n, a), do: a end
Are you sure you want to hide this comment? It will become hidden in your post, but will still be visible via the comment's permalink.
Hide child comments as well
Confirm
For further actions, you may consider blocking this person and/or reporting abuse
We're a place where coders share, stay up-to-date and grow their careers.
Elixir
Some recursion