Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- function solve(input) {
- let name = input.shift();
- let sector = input.shift();
- let points = Number(input.shift());
- let leg = 301;
- let shots = 0;
- let isLeg = false;
- let fasleShots = 0;
- while (sector != 'Retire') {
- let currentPoints = 0;
- switch (sector) {
- case 'Triple': currentPoints += 3 * points;
- break;
- case 'Double': currentPoints += 2 * points;
- break;
- case 'Single': currentPoints += points;
- }
- if (leg - currentPoints >= 0) {
- shots++;
- leg -= currentPoints;
- } else {
- fasleShots++;
- }
- if (leg == 0) {
- isLeg = true;
- break;
- }
- sector = input.shift();
- points = Number(input.shift());
- }
- if (isLeg) {
- console.log(`${name} won the leg with ${shots} shots.`)
- } else {
- console.log(`${name} retired after ${fasleShots} unsuccessful shots.`);
- }
- }
- //solve(['Michael van Gerwen', 'Triple', '20', 'Triple', '19', 'Double', '10', 'Single', '3', 'Single', '1', 'Triple', '20', 'Triple', '20', 'Double', '20']);
Advertisement
Add Comment
Please, Sign In to add comment