# munten.py
#
# MIT-License
#
# Copyright © 2023 Theo van Haandel  py39@x4a.nl
#
# Permission is hereby granted, free of charge, to any person
# obtaining a copy of this software and associated documentation
# files (the "Software"), to deal in the Software without
# restriction, including without limitation the rights to use,
# copy, modify, merge, publish, distribute, sublicense, and/or sell
# copies of the Software, and to permit persons to whom the
# Software is furnished to do so, subject to the following
# conditions:
#
# The above copyright notice and this permission notice shall be
# included in all copies or substantial portions of the Software.
#
# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
# EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES
# OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
# NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT
# HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
# WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
# FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
# OTHER DEALINGS IN THE SOFTWARE.

# versie 1.0  2023-10-19

# munten voor bedrag
#   met recursie

# gebaseerd op opgave 4.3
#  van De Programmeursleerling door Pieter Spronck

munten = 50, 25, 10, 5, 1
# munten = 50, 25, 10, 5, 2
# munten = 1, 5, 10, 25, 50
# munten = 5, 1
# munten = 51, 3  # lukt niet, 49 niet deelbaar door 3
# munten = 51, 7  # lukt net 1x

begin = 100

def betaal(bedrag, index, aantallen, totaal):
    if bedrag == 0:
        print(aantallen)
        totaal = totaal + 1
        return totaal
    if bedrag >= munten[index]:
        # aantallen2 = aantallen[:]
        # aantallen2[index] += 1
        # totaal = betaal(bedrag - munten[index], index, aantallen2, totaal)
        aantallen[index] += 1
        totaal = betaal(bedrag - munten[index], index, aantallen, totaal)
        aantallen[index] -= 1
    if index + 1 < len(munten):
        totaal = betaal(bedrag, index + 1, aantallen, totaal)
    return totaal

aantallen = [ 0 ] * len(munten)
totaal = betaal(begin, 0, aantallen, 0)
print('Totaal', totaal)

