id/email
password
forgot password | create account
about | help | code help+videos | done | prefs
CodingBat code practice

 

darts


In the darts game 501, players take turns shooting darts (three darts to a turn) until one player's total reaches 501. As the end of the game approaches, things get strategic. You might need, say, 62 points to win. You can't get your 62 points in one dart, but with two darts you could get a 60 (triple 20) and a 2; or a 50 (double bull) and a 12; among other possibilities. (Note to non-dart players: A dart board has scoring points for the numbers 1 to 20, and also double and triples of those numbers (that is 2, 4, 6, ... 40 and 3, 6, 9, ... 60), and the bull's eye and double-bull's eye, which score 25 and 50. You get 0 if you miss the board altogether.) Write a function darts(total) that returns a way to reach total points if possible. If it is not possible to reach total, get as close as you can. For example, for darts(501), you should return [60,60,60], because that gets as close to the goal as possible. In any case, you must return a list of three dart scores; it is ok for one or more of them to be 0. If there are multiple ways to reach total, return the one with the biggest numbers first. Usually there will be multiple ways to reach a total. In that case you should choose the sequence of three darts that has the biggest numbers first (that is, has the biggest first number, or if there are ties for biggest first number, has the biggest second number). There are several variants of the rules for 501; often there is a requirement that the final winning dart be a double; we are not using that rule. (This is a relatively hard problem. It requires about 10 lines of code; use the hint if you have to. But try to do without the hint first.)


darts(62) → [60, 2, 0]
darts(501) → [60, 60, 60]
darts(155) → [60, 57, 38]

...Save, Compile, Run (ctrl-enter)

def darts(total):

Editor font size %:
Shorter output


Forget It! -- delete my code for this problem

Progress graphs:
 Your progress graph for this problem
 Random user progress graph for this problem
 Random Epic Progress Graph

Python Help

Difficulty: 600 Post-solution available

Copyright Nick Parlante 2017 - privacy