-
Notifications
You must be signed in to change notification settings - Fork 36
/
Darts.js
27 lines (22 loc) · 945 Bytes
/
Darts.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
// https://www.codingame.com/training/easy/darts
const R = +readline() / 2;
const playersScores =
new Map([...Array(+readline())].map(() => [readline(), 0]));
const throws = [...Array(+readline())].map(() => {
const [name, x, y] = readline().split(' ');
return [name, +x, +y];
});
const DIAMOND_SCORE = 15; const CIRCLE_SCORE = 10; const SQUARE_SCORE = 5;
throws.forEach(([player, x, y]) => {
const currentScore = playersScores.get(player);
if (Math.abs(x) + Math.abs(y) <= R) {
playersScores.set(player, currentScore+DIAMOND_SCORE);
} else if (Math.sqrt(x*x + y*y) <= R) {
playersScores.set(player, currentScore+CIRCLE_SCORE);
} else if (Math.max(x, y) <= R && Math.min(x, y) >= -R) {
playersScores.set(player, currentScore+SQUARE_SCORE);
}
});
Array.from(playersScores)
.sort(([, score1], [, score2]) => score2-score1)
.forEach(([name, score]) => console.log(name, score));