# [BangPypers] golf problem

steve steve at lonetwin.net
Sun Dec 25 09:36:36 CET 2011

```Hi,

On 12/25/2011 12:52 PM, Kenneth Gonsalves wrote:
> hi,
>
> a golf course has 18 holes. There are three types of hole - par 3, par 4
> and par 5. For a certain type of tournament it is necessary to generate
> a random list of 6 holes. The only condition is that this list should
> contain at least one of each type of hole. What would be an elegant way
> of doing this. Sample data for Ooty golf course is given below. The hole
> number is the first element of each tuple and the par is the second
> element.
>

I am sorry, I didn't quite understand this bit "it is necessary to generate a
random list of 6 holes.", since the list below has 18 elements. In any case,
whether you need 6 or 18 -- the simplest way to do this would be:

>>> l = []
>>> for i in range(6):
...     l.append(random.choice([3,4,5]))
...
>>> l
[4, 5, 3, 4, 5, 5]

# ...where the index is the hole number and the element is the par, or if you
# need it in the format you showed:

>>> l = []
>>> for i in range(1, 19):
...     l.append((i, random.choice([3,4,5])))
...
>>> l
[(1, 5), (2, 3), (3, 4), (4, 5), (5, 3), (6, 3), (7, 5), (8, 4), (9, 3),
(10, 5), (11, 5), (12, 5), (13, 4), (14, 5), (15, 3), (16, 5), (17, 3), (18, 5)]
>>>

cheers,
- steve

--
random spiel: http://lonetwin.net/
what i'm stumbling into: http://lonetwin.stumbleupon.com/
```