# Sunday Times Teaser 3097 – Crazy Golf

*by Angela Newing*

#### Published Sunday January 30 2022 (link)

Ian was trying to entertain John and Ken, his 2 young nephews, in the local park, which had a 9-hole crazy golf course. He decided to play a round with each of them separately, and gave them money for each hole he lost on a rising scale. He would pay £1 if he lost the first hole (or the first hole after winning one), then £2 if he lost the next consecutive hole, and £3 for the third, and so on.

In the event, Ian won only 5 holes in total between the two rounds, including the first hole against John and the last hole against Ken. There were no ties. At the reckoning after both rounds, both boys received equal amounts of money.

How much did it cost Uncle Ian?

6 Comments
Leave one →

This version is slower but outputs the results of the rounds of crazy golf involved.

This should be quite fast

Nice to see you back John. You are right that it is fast – too fast to measure with Python’s profile tool.

You could simplify it a little by using a set for ‘iloss’ since you don’t make any use of indexing other than for storage.

Taking into account your comment about using a set instead of a list and using combinations instead of nested for loops to avoid using exit.

Hi John, Your version can certainly be used to produce a very short and fast solution!

Indeed! You beat me to it. This is what I was about to post: