Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 15 additions & 1 deletion darts/darts.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
"""Darts is a game where players throw darts at a target."""

from math import sqrt


def score(x: int, y: int) -> int:
"""
Expand All @@ -16,4 +18,16 @@ def score(x: int, y: int) -> int:
:param y: The y-coordinate where the dart landed
:return: The points scored (0, 1, 5, or 10)
"""
pass
# Calculate distance form the center of the circle (0, 0)
distance: float = sqrt(pow(x, 2) + pow(y, 2))
# Outside target
if distance > 10:
return 0
# Outer circle
if distance > 5:
return 1
# Middle circle
if distance > 1:
return 5
# Inner circle
return 10
2 changes: 1 addition & 1 deletion darts/darts_test.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
# pylint: disable=C0301
# pylint: disable=C0114, C0115, C0116, R0904

# These tests are auto-generated with test data from:
# https://github.com/exercism/problem-specifications/tree/main/exercises/darts/canonical-data.json
Expand Down
19 changes: 19 additions & 0 deletions solutions/python/darts/1/darts.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
"""Darts is a game where players throw darts at a target."""


def score(x: int, y: int) -> int:
"""
Calculate the points scored in a single toss of a Darts game.

Given the x and y coordinates where a dart lands, returns the score
based on the distance from the center (0, 0):
- Inner circle (distance <= 1): 10 points
- Middle circle (distance <= 5): 5 points
- Outer circle (distance <= 10): 1 point
- Outside target (distance > 10): 0 points

:param x: The x-coordinate where the dart landed
:param y: The y-coordinate where the dart landed
:return: The points scored (0, 1, 5, or 10)
"""
pass