Skip to content

Commit e8f3d69

Browse files
authored
Merge pull request #119 from ikostan/exercism-sync/bd4d89608b296431
[Sync Iteration] python/darts/1
2 parents a413717 + cb6ad02 commit e8f3d69

File tree

3 files changed

+35
-2
lines changed

3 files changed

+35
-2
lines changed

darts/darts.py

Lines changed: 15 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
11
"""Darts is a game where players throw darts at a target."""
22

3+
from math import sqrt
4+
35

46
def score(x: int, y: int) -> int:
57
"""
@@ -16,4 +18,16 @@ def score(x: int, y: int) -> int:
1618
:param y: The y-coordinate where the dart landed
1719
:return: The points scored (0, 1, 5, or 10)
1820
"""
19-
pass
21+
# Calculate distance form the center of the circle (0, 0)
22+
distance: float = sqrt(pow(x, 2) + pow(y, 2))
23+
# Outside target
24+
if distance > 10:
25+
return 0
26+
# Outer circle
27+
if distance > 5:
28+
return 1
29+
# Middle circle
30+
if distance > 1:
31+
return 5
32+
# Inner circle
33+
return 10

darts/darts_test.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
# pylint: disable=C0301
1+
# pylint: disable=C0114, C0115, C0116, R0904
22

33
# These tests are auto-generated with test data from:
44
# https://github.com/exercism/problem-specifications/tree/main/exercises/darts/canonical-data.json

solutions/python/darts/1/darts.py

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
"""Darts is a game where players throw darts at a target."""
2+
3+
4+
def score(x: int, y: int) -> int:
5+
"""
6+
Calculate the points scored in a single toss of a Darts game.
7+
8+
Given the x and y coordinates where a dart lands, returns the score
9+
based on the distance from the center (0, 0):
10+
- Inner circle (distance <= 1): 10 points
11+
- Middle circle (distance <= 5): 5 points
12+
- Outer circle (distance <= 10): 1 point
13+
- Outside target (distance > 10): 0 points
14+
15+
:param x: The x-coordinate where the dart landed
16+
:param y: The y-coordinate where the dart landed
17+
:return: The points scored (0, 1, 5, or 10)
18+
"""
19+
pass

0 commit comments

Comments
 (0)