Cal Chocolates

You might also like

Download as txt, pdf, or txt
Download as txt, pdf, or txt
You are on page 1of 2

How many chocolates?

Let's say you have m Rupees and one chocolate costs rupees c.
The shopkeeper will give you a bar of chocolate for free if you give him 3
wrappers.
Can you determine how many chocolates can you get with the m Rupees you have?

Var 1 = M i.e amount you've


Var 2= C i.e cost of each chocolate
Var 3= Wrapper i.e 3 var3= 1 c

Asking how many chocolate can I get with M ruppes?

There is no direct relationship between M and C


But we can define,
lets assume I'd spend M ruppees to get the chocolates, 1 chocolate=c

M=n*C, where n is number of chocolates


c=3W, where W is wrapper

how to solve in coding sense?

get input m,c

m/c get number of chocolates


selling wrappers of these chocolates
will again bring chocolate, then we'll get more chocolates

There are three cases that're said to be made?


how?

using 3 wrapper =1chocolate

x%3==0
x%3==1
x%3==2
first one is simple
in second case we can use- result of modulus i.e=1 as base, x//3==this value

second solution:-

given input(amount,cost_of_each_chocolate)

chocolates=amount//cost_of_each_chocolate
wrapper=0

if chocolates%3==0:
wrapper=chocolates
if wrapper%3==0:
wrapper=wrapper//3
chocolates=chocolates+wrapper
elif wrapper%3==1:
wrapper=(wrapper+1)//3
chocolates=chocolates+wrapper
elif wrapper%3==2:
wrapper=(wrapper+2)//3
chocolates=chocolates+wrapper
elif chocolates%3==1:
wrapper=chocolates
if wrapper%3==0:
wrapper=(wrapper+1)//3
chocolates=chocolates+wrapper
elif wrapper%3==1:
wrapper=(wrapper+2)//3
chocolates=chocolates+wrapper
elif wrapper%3==2:
wrapper=(wrapper+3)//3
chocolates=chocolates+wrapper

elif chocolates%3==2:
wrapper=chocolates
if wrapper%3==0:
wrapper=(wrapper+2)//3
chocolates=chocolates+wrapper
elif wrapper%3==1:
wrapper=(wrapper+3)//3
chocolates=chocolates+wrapper
elif wrapper%3==2:
wrapper=(wrapper+4)//3
chocolates=chocolates+wrapper

You might also like