[PyAR2] Programming Challenge III - My first cut

Greg Lindstrom gslindstrom at gmail.com
Mon Nov 17 20:20:19 CET 2008

```OK.  I played around for about 15 minutes...

import random

buttons = ['1','2','3','4','5']

def choose_button():
'''Select a button from the list and then remove it from the list'''
global buttons

button = random.choice(buttons)
buttons.pop(buttons.index(button))
return button

while len(buttons) > 0:

if len(buttons)>1:
number_of_buttons = random.randint(1, 2)

if number_of_buttons == 1:
print choose_button()
else:
print '%s, %s' % (choose_button(), choose_button())
else:
print buttons[0]
break

Also, I think there are 450 permutations.  IIRC, (5 choose 2) = 10 and (3
choose 2) = 3

For a combination with all single buttons there are 5! or 120 combinations

For a combination with with 1 "double" and 4 "singles": (x,y) is "x choose
y)
2 1 1 1 = (5,2) x 3 x 2 x 1 = 10 x 3 x 2 x 1 = 60
1 2 1 1 = 5 x (4,2) x 2 x 1 = 5 x 6 x 2 x 1 = 60
1 1 2 1 = 5 x 4 x (3,2) x 1 = 5 x 4 x 3 x 1 = 60
1 1 1 2 = 5 x 4 x 3 x (2,2) = 5 x 4 x 3 x 1 = 60

There are 240 combinations with 1 set being "doubled"

With 2 sets being doubled

2 2 1 = (5,2) x (3,2) x 1 = 10 x 3 x 1 = 30
2 1 2 = (5,2) x 3 x (2,2) = 10 x 3 x 1 = 30
1 2 2 = 5 x (4,2) x (2,2) =   5 x 6 x 1 = 30

With 2 sets doubles there are 90 combinations.

So, 120 + 240 + 90 = 450 combinations.
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.python.org/mailman/private/pyar2/attachments/20081117/ac1e90ec/attachment.htm>
```