Skip to content

Instantly share code, notes, and snippets.

@Retozi
Last active January 2, 2016 18:04
Show Gist options
  • Save Retozi/140c8c27c1e8575bd715 to your computer and use it in GitHub Desktop.
Save Retozi/140c8c27c1e8575bd715 to your computer and use it in GitHub Desktop.
darts problem
from itertools import product
CLOSING_SCORE = 167
def possible_dart_shots():
shots = []
for k, multi in enumerate(['single', 'double', 'tripple']):
for segment in range(1, 21):
shots.append((multi, (k + 1) * segment))
shots.append(('single', 25))
shots.append(('double', 50))
shots.append(('miss', 0))
return shots
def clean_misses(shot_sequence):
return tuple(s for s in shot_sequence if s != ('miss', 0))
def get_closing_sequence(shot_sequence):
score = 0
for n, s in enumerate(shot_sequence):
score = score + s[1]
if score == CLOSING_SCORE and s[0] == 'double':
return shot_sequence[:n + 1]
return None
closing_shots = set()
for shot_sequence in product(possible_dart_shots(), repeat=3):
closing_sequence = get_closing_sequence(shot_sequence)
if closing_sequence:
closing_shots.add(clean_misses(closing_sequence))
print(len(closing_shots))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment