Skip to content

Instantly share code, notes, and snippets.

@cored

cored/darts.ex Secret

Last active April 7, 2023 18:06
Show Gist options
  • Save cored/dff0dba92f834e349503286ada049844 to your computer and use it in GitHub Desktop.
Save cored/dff0dba92f834e349503286ada049844 to your computer and use it in GitHub Desktop.
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
cond do
x * x + y * y > 100 -> 0
x * x + y * y > 25 -> 1
x * x + y * y > 1 -> 5
true -> 10
end
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment