Created
May 21, 2018 20:23
-
-
Save chrisdel101/55965ad2413dfe5b1ae5ea8a3d24a8f6 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import cs50 | |
# Pseudo | |
# - divide total by a coin amount | |
# - keep dividing it by increments of that coin, count each time | |
# - subtract from total each time, amount left undivided | |
# - move the amount left from coin to coin | |
def greedy(): | |
# set to two arbitraily to run | |
# total to divide in change | |
amount = cs50.get_float("Enter amount:") | |
amount = amount * 100 | |
print(f"amount {amount}") | |
# amount of coins | |
change = 0 | |
# coin | |
quarter = 25 | |
# amount after each interation left | |
left = amount | |
# total being accumulated against amount | |
totalDivider = quarter | |
divQuarterCheck = 0 | |
# get 25s | |
# if amount is disible by 25, set checker | |
if(amount == quarter): | |
change += 1 | |
print(f"change: {change}") | |
return change | |
elif(amount / quarter > 1): | |
divQuarterCheck = amount /quarter | |
else: | |
print("not divisible by 25") | |
divQuarterCheck = amount /quarter | |
while (divQuarterCheck >= 1): | |
# each time divided check more than one | |
# add double adder | |
divQuarterCheck = (amount - totalDivider) / quarter | |
# add another value to itself | |
# if still divisible, go on, if not stop | |
totalDivider += quarter | |
# print(f"totalDivide: {totalDivider}") | |
# print (divQuarterCheck) | |
change += 1 | |
left -= quarter | |
# print(left) | |
print(f"{left} after quarters") | |
dime = 10 | |
totalDivider = dime | |
divDimeCheck = 0 | |
if(left == dime): | |
change += 1 | |
print(f"change: {change}") | |
return change | |
elif(left / dime > 1): | |
divDimeCheck = left /dime | |
else: | |
print("not divisible by 10") | |
while (divDimeCheck >= 1): | |
# each time divided check more than one | |
# add double adder | |
divDimeCheck = (left - totalDivider) / dime | |
# add another value to itself | |
# if still divisible, go on, if not stop | |
totalDivider += dime | |
# print(f"totalDivide: {totalDivider}") | |
# print (divDimeCheck) | |
change += 1 | |
left -= dime | |
# print(f"left:{left}") | |
# divDimeCheck = 0 | |
print(f"{left} after dimes") | |
nickel = 5 | |
# if(left == nickel): | |
# print("true") | |
totalDivider = nickel | |
divNickelCheck = 0 | |
if(left == nickel): | |
change += 1 | |
print("true") | |
print(f"change: {change}") | |
return change | |
elif(left / nickel > 1): | |
divNickelCheck = left / nickel | |
print("true") | |
else: | |
print("not divisible by 5") | |
while (divNickelCheck >= 1): | |
# each time divided check more than one | |
# add double adder | |
divNickelCheck = (left - totalDivider) / nickel | |
# add another value to itself | |
# if still divisible, go on, if not stop | |
totalDivider += nickel | |
# print(f"totalDivide: {totalDivider}") | |
# print (divNickelCheck) | |
change += 1 | |
left -= nickel | |
# print(f"left:{left}") | |
print(f"{left} after nickels") | |
penny = 1 | |
divPennyCheck = 0 | |
totalDivider = penny | |
if(left == penny): | |
change += 1 | |
print(f"change: {change}") | |
return change | |
elif(left / penny > penny): | |
divPennyCheck = left / penny | |
else: | |
print('not divisible by 1') | |
while (left): | |
# each time divided check more than one | |
# add double adder | |
divPennyCheck = (left - totalDivider) / penny | |
# add another value to itself | |
# if still divisible, go on, if not stop | |
totalDivider += penny | |
# print(f"totalDivide: {totalDivider}") | |
print (divPennyCheck) | |
change += 1 | |
left -= penny | |
print(f"{left} after > penny") | |
# if(left == penny): | |
# left = left - penny | |
# change += 1 | |
# print(f"change:{change}") | |
# print(f"{left} after == penny") | |
print(f"change: {change}") | |
return change | |
greedy() | |
# def get_input(): | |
# amount = cs50.get_float("Enter amount:") | |
# amount = amount * 100 | |
# print(f"amount {amount}") | |
# get_input() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment