Three Darts Thrown... How Many Scored?

Published by Mubashir Hassan in

Having just watched the PDC World Darts Championship, Adam has become inspired to become the next Gerwyn Price and takes to the dartboard.

Create a function convert the text information of what Adam has thrown in his three darts into the number of points scored.

For those familiar to watching darts on TV...

You will see a string with three passages of text in the same format as the bar that comes on the screen when a player is on a checkout.

For those not familiar to a dartbord and/or not familiar to watching darts on TV...

You will see a string with three passages of text separated by a space. Each of the three passages of text shall be in one of the following five formats:

Format #1

  • The numbers 1 to 20 (inclusive).
  • These represent the single segments of the dartboard.
  • For example: 17 means single 17 which is 1 x 17 = 17.

Format #2

  • The numbers 1 to 20 inclusive with the letter D in front.
  • These represents the double segments of the dartboard.
  • For example: D12 means double 12 which is 2 x 12 = 24.

Format #3

  • The numbers 1 to 20 inclusive with the letter T in front.
  • These represents the treble segments of the dartboard.
  • For example: T9 means treble 9 which is 3 x 9 = 27.

Format #4

  • The number 25 which is the common name for the outer bullseye.
  • This, perhaps unsurprisingly, is worth twenty-five points.

Format #5

  • The word BULL which is the common name for the inner bullseye.
  • This is worth fifty points.

Examples

howManyScored("BULL 10 T1") ➞ 63
// 50 + (1 x 10) + (3 x 1) = 63

howManyScored("D10 T12 15") ➞ 71
// (2 x 10) + (3 x 12) + (1 x 15) = 71

howManyScored("14 25 T8") ➞ 63
// (1 x 14) + 25 + (3 x 8) = 63

Notes

  • Each passage of text is separated by a space.
  • There will always be three passages of text in the string.
  • Each passage of text shall be in one of the five valid formats mentioned above.
  • i.e. Adam will not go outside the board and score zero with any darts.
Watch a quick demo on how Edabit works.