The Beer Money Problem - MLUG Coding Challenge (Intro)

I like a good coding challenge, and this one is particularly fun. It was set by the wonderful folks at MLUG and goes like this:

I went to the supermarket to get some beers for the Euros final and my bill came to £11.99. With the money detailed [below], how many combinations are there that make up the exact change to pay my bill? 

 

Coin/Note

Quantity

Sub Total

 £      10.00

1

 £    10.00

 £        5.00

1

 £       5.00

 £        2.00

4

 £       8.00

 £        1.00

5

 £       5.00

 £        0.50

3

 £       1.50

 £        0.20

6

 £       1.20

 £        0.10

4

 £       0.40

 £        0.05

3

 £       0.15

 £        0.02

10

 £       0.20

 £        0.01

5

 £       0.05

 Total

 42

 £    31.50


Now's a great time to open up LabVIEW and try it out - see if you can get an answer!

I actually spent a good week of evenings hunched over my (paper) notebook and computer playing with different approaches. Some of my colleagues had a go too, and it was interesting to see the different ways we had of solving it.

In Post 1 I will talk about my first simple approach, then Post 2 how I made it recursive, and Post 3 other approaches. I'm hoping to speak about this briefly at the next MLUG - will put up a link if it gets in.

Cheers,

Leah


Comments