Please note, this is a STATIC archive of website www.tutorialspoint.com from 11 May 2019, cach3.com does not collect or store any user information, there is no "phishing" involved.
Tutorialspoint

Chocolate_Bars_for_Kata_001

# 4 oz and 1.5 oz
# 50% chocolate, 25% nuts and 25% raisins.

# Note: All ingredients quantities are in ounces.
#
# Use 50% of the incoming ingredients deliveries to make 4 oz bars,
# and 50% to make 1.5 oz bars.
# Whatever remains from that day moves into storage for the next day.

# There may be some inventory (in ounces) already in an incoming dictionary:

#     storage = {
#        "choco": 25, 
#        "nuts": 30,
#        "raisins": 10
#        }

# Use everything there first for big bars only (4 oz).
# If there is anything left over, make small bars (1.5 oz). 
# The rest should just stay in storage.
# Then take the 50%/50% of the incoming ingredients and make what you can. 
# Put what's left from the daily 50%/50% production into storage.


# Input:
# A dictionary of previous inventory.
# A list with sub lists for the daily deliveries.

# Process:
# Each day:
# Use inventory for big bars.
# Use leftover inventory for small bars.
# (Leave the rest in storage.)
# Split the incoming ingredients 50/50.
# Make big and small bars with incoming ingredients.
# Put the remaining imcoming ingredients into storage.


# Output:
# Return a list with two items:
# The number of big bars made and the number of small bars made.


import math

def make_bars(storage, lst):
    '''
    stoarge = {
        "choco": 25, 
        "nuts": 30,
        "raisins": 10
    }
    '''
    
    bars_split = {
        "choco": 0, 
        "nuts": 0,
        "raisins": 0
    }
    

    final_bars = {
        "big": 0,
        "small": 0
    }


    # Make what you can from inventory:
    # All the big bars possible.
    # Then, all the small bars possible.
    for i in storage:
        print(i, storage[i])
    
    print()

    # Find out how many big bars can be made from what is in inventory.
    
    # choc: 50%, nuts: 25%, raisins: 25%

    # Use whichever is smaller: chocolate, nuts or raisins.

    sm = 10000
    sm_name = "nothing yet"
    
    for i in storage:
        if storage[i] < sm:
            sm = storage[i]
            sm_name = i
    
    print(sm_name)
    print(sm)
    print()
    
    
    # If the smallest is chocolate, 
    # check to see if 1/2 the amount is in both
    # nuts and raisins.
    # If no, adjust the amount for nuts/raisins.
    #
    # If nuts or raisins are the smallest,
    # check to see if twice the amount is in chocolate.
    # If no, adjust for chocolate.
    
    
    
    
    
    for i in lst:
        print(i)

        


print(make_bars(
    {
        "choco": 50, 
        "nuts": 30,
        "raisins": 10
    }, 
    [
        [100, 70, 40],
        [200, 20, 30],
        [150, 100, 120],
        [300, 150, 100],
        [50, 10, 20]
]))





# bottom of screen

Advertisements
Loading...

We use cookies to provide and improve our services. By using our site, you consent to our Cookies Policy.