exercism/elixir/darts/lib/darts.ex

18 lines
355 B
Elixir
Raw Permalink Normal View History

2023-12-17 05:26:14 +00:00
defmodule Darts do
@type position :: {number, number}
@doc """
Calculate the score of a single dart hitting a target
"""
@spec score(position) :: integer
def score({x, y}) do
in_radius = (x ** 2 + y ** 2) ** 0.5
cond do
in_radius <= 1 -> 10
in_radius <= 5 -> 5
in_radius <= 10 -> 1
true -> 0
end
end
end