File tree Expand file tree Collapse file tree 2 files changed +43
-0
lines changed Expand file tree Collapse file tree 2 files changed +43
-0
lines changed Original file line number Diff line number Diff line change 1+ /*
2+ * <--Introduction-->
3+ * Refer to this exercise for full details:
4+ * https://exercism.org/tracks/c/exercises/darts
5+ *
6+ */
7+
8+ #include "darts.h"
9+
10+ unsigned int score (coordinate_t landing_position ){
11+
12+ // We used the Pythagorean theorem to get the radius by using the two coordinates:
13+ // 1. landing_position.x
14+ // 2. landing_position.y
15+ float radius = sqrt (pow (landing_position .x , 2 ) + pow (landing_position .y , 2 ));
16+
17+ /*
18+ * Note: Interval notation is used to show the range of the radius to
19+ * determine the score
20+ *
21+ * If radius is [0, 1] , return a score of 10
22+ * If radius is (1, 5] , return a score of 5
23+ * If radius is (5, 10] , return a score of 1
24+ * If radius is (-inf, 0) or (10, +inf), return a score of 0
25+ *
26+ */
27+ return radius >= 0 && radius <= 1 ? 10 : radius > 1 && radius <= 5 ? 5 : radius > 5 && radius <= 10 ? 1 : 0 ;
28+ }
Original file line number Diff line number Diff line change 1+ #ifndef DARTS_H
2+ #define DARTS_H
3+
4+ #include <math.h>
5+ #include <stdlib.h>
6+
7+ typedef struct
8+ {
9+ float x ;
10+ float y ;
11+ } coordinate_t ;
12+
13+ unsigned int score (coordinate_t landing_position );
14+
15+ #endif
You can’t perform that action at this time.
0 commit comments