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