Skip to content

Instantly share code, notes, and snippets.

@SohanChy
Created January 20, 2022 05:16
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 SohanChy/ac6436a60dd0f73011ff597b2be17cca to your computer and use it in GitHub Desktop.
Save SohanChy/ac6436a60dd0f73011ff597b2be17cca to your computer and use it in GitHub Desktop.
Movie Theater Problem
input = ['2020-01-01,Soda',
'2020-01-03,Soda',
'2020-01-02,Popcorn',
'2020-01-05,Soda',
'2020-01-06,Popcorn',
'2020-01-07,Soda',
'2020-01-02,Popcorn',
'2020-01-12,Soda',
'2020-01-03,Popcorn',
'2020-01-22,Soda',
'2020-01-05,Soda',
'2020-01-18,Popcorn',
'2020-01-13,Soda',
]
pricing = {
"Soda":20,
"Popcorn":10,
"Combo": 25
}
class DayBill:
items = []
def __init__(self,item):
self.items.append(item)
def calcPrice(self):
combo = 0
soda = 0
popcorn = 0
for item in self.items:
if item == "Soda":
soda = soda + 1
if item == "Popcorn":
popcorn = popcorn + 1
while(soda > 1 and popcorn >1):
combo = combo + 1
soda = soda - 1
popcorn = popcorn - 1
return (combo * pricing['Combo']) + (soda * pricing['Soda']) + (soda * pricing['Popcorn'])
items_by_date_dict = {}
for item in input:
date,item = item.split(',')
if date in items_by_date_dict:
items_by_date_dict[date].items.append(item)
else:
items_by_date_dict[date] = DayBill(item)
bill = 0
for date in items_by_date_dict:
bill = bill + items_by_date_dict[date].calcPrice()
print(bill)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment