18 lines
355 B
Elixir
Raw Normal View History

2023-12-17 00:26:14 -05: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