Skip to content

Instantly share code, notes, and snippets.

@danieldiekmeier
Created March 3, 2017 09:04
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save danieldiekmeier/63f1f3eaedac011035ff79fa80b7eeb5 to your computer and use it in GitHub Desktop.
Save danieldiekmeier/63f1f3eaedac011035ff79fa80b7eeb5 to your computer and use it in GitHub Desktop.
prices = [9, 9, 12, 12, 12, 15, 16, 20]
new_prices = []
# The lowest price has to be a reduces price
# Then calculate the original price from that
# remove both from the prices list and do it again
def solve (prices, new_prices):
if len(prices) == 0:
return new_prices
lower = prices.pop(0)
higher = lower * (4/3)
index = prices.index(higher)
prices.pop(index)
new_prices.append(lower)
return solve(prices, new_prices)
print(solve(prices, new_prices))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment