Python coding - i need a function
int_over_21 (count) = 0
int_fits (count) = 0
Player_Sum (int)
Dealer_Sum (int)
Deck_of_cards (list of int)
restraints: is more than or equal to 17 AND is more than or equal to Player_Sum AND is less than or equal to 21
I need a function that takes in this list of int (deck of cards) and creates a list of all the different ways the cards can be arranged. It then iterates through this list of list_of_int and for each element (list_of_int's), it adds the first number (int) to the Dealer_Sum and checks it against restraints. If the new sum is less than 21, then it adds the next number (int) to the sum and checks it against the restraints again. This should repeat until the total sum either fits the restraints or is greater than 21. If it fits the restraints, then the int_fits count should increase by one AND every pattern in our list of patters that starts with the same arrangement should be deleted from the list of list_of_int and the count for int_fits should increase by one (+1) for each element deleted from the list. If the total sum does not fit the restraints and is greater than 21, then it should add one to the int_over_21 (count) and should delete all other list_of_int's in the list that share the same starting pattern leading up to this point. For each one deleted, int_over_21 should get another plus one (+1) to its count. Through this same process, if Dealer_sum becomes equal to or greater than 17, but is still less than Player_sum (so the addition of the first element brings Dealer_sum to 18 but Player_sum is 19) then it should delete this list_of_int from the list, add one (+1) to the int_over_21 count and all the other list_of_int within the list that share the same pattern leading up to the element that put it equal to or greater than 17 and less than the Player_sum should also be deleted from the list and for each deletion, the int_over_21 count should go up by one (+1)
The output should be ((int_over_21) / ((int_over_21) + (int_fits)))
restraints: is more than or equal to Player_Sum AND is less than or equal to 21
deck is a list
player_sum is an int
dealer_sum is an int
int_over_21 is a count
int_fits is a count
the function would take in the deck, player_sum, and dealer_sum
deck = [10, 10, 2, 3, 4, 5]
player_sum = 18
dealer_sum = 9
function(deck, player_sum, dealer_sum):
# this function starts by creating a list of all the different ways the deck can be organized, in this case, with 6 elements in the list, there will be 6! = 720 different list_of_int in this list
# when the function gets to the list_of_int [10, 5, 2, 10, 3, 4], it will add the first element of this list (10) to the dealer_sum (9 +10) and check this sum against the restraints.
# dealer_sum now equals 19 -> is player_sum <= dealer_sum <= 21 and this is True
# so the function should now increase the int_fits by one (+1) and reiterates through the list of list_of_int and for every list_of_int that starts with 10 (list the one that fit) gets removed
# from the list, and for each one that gets removed, int_fits goes up by one (+1) again.
# When the function gets to a list_of_int that is [5, 10, 4, 10, 3, 2] it will take its first element (5) and add it to dealer_sum to get 14. 14 is less than 17 so it will need to add the
# next element from the list which is 10 and add it to the dealer_sum which brings it to 24. It puts the dealer sum greater than 21 so it gets deleted from the list, adds one to
# the count of int_over_21 (+1) and deletes all the other list_of_int from the list that have the same pattern sequence that starts with [5, 10, ....] and adds one (+1) to
# the int_over_21 count. It should add one (+1) to the int_over_21 count if the dealer_sum has reached 17 or more AND the dealer_sum is less than the player_sum
# aka adds one to the count, deletes from the list and deletes all matching list_of_int with the same leading pattern from the list and adds another one (+1) for each of
# the list_of_int deleted from the list
so
list1 = [10, 8, 5]
player_sum = 19
dealer_sum = 8
# int_over_21 = 0
# fits_restraint = 0
# function(list1, player_sum, dealer_sum):
# list two is the permutation of list one so list2 = [[10, 8, 5], [10, 5, 8], [8, 10, 5], [8, 5, 10], [5, 10, 8], [5, 8, 10]]
# list2[0] = greater than 17, less than player_sum, int_over_21 += 1 (int_over_21 = 1)
# this now deletes list2[1] from list2 and adds another count to int_over_21 (int_over_21 = 2)
# list2[2] = less than 17 so we add the next element from list2[2] which is 10 bringing dealer_sum up to 28 which is greater than 21 so it adds one to int_over_21 (int_over_21 = 3)
# no other list_of_int within list2 start with [8, 10, ...] so no others get deleted and the function moves on to list2[3]
# list2[3] = 8 + 5 = dealers_sum = 13 which is less than 17 so it adds the next element from list2[3] which is 5 -> dealer_sum = 18 which is greater than 17 but less than player_sum (19)
# this means that it adds a count to int_over_21 (int_over_21 = 4) and doesn't delete any other list_of_int from the list2 because none of the remaining list_of_int start with [8, 5, ...]
# list2[4] = 8 + 5 which is less than 17 -> 13 + 10 which is dealer_sum = 23 which is greater than 21 so it adds one to the int_over_21 count (int_over_21 = 5)
# list2[5] = 8 + 5 which is less than 17 -> 13 + 8 which is 21 so the fits_restraints counts will go up by 1 (fits_restraints = 1)
# then the function should output ((int_over_21) / ((int_over_21) + (fits_restraint)))
function(list1, player_sum, dealer_sum) should output 0.8333