My friend John likes to go to the cinema. He can choose between system A and system B.
```
System A : he buys a ticket (15 dollars) every time
System B : he buys a card (500 dollars) and a first ticket for 0.90 times the ticket price, 
then for each additional ticket he pays 0.90 times the price paid for the previous ticket.
```
#Example: 
If John goes to the cinema 3 times:
```
System A : 15 * 3 = 45
System B : 500 + 15 * 0.90 + (15 * 0.90) * 0.90 + (15 * 0.90 * 0.90) * 0.90 ( = 536.5849999999999, no rounding for each ticket)
```
John wants to know how many times he must go to the cinema so that the *final result* of System B, when rounded *up* to the next dollar, will be cheaper than System A.

The function `movie` has 3 parameters: `card` (price of the card), `ticket` (normal price of 
a ticket), `perc` (fraction of what he paid for the previous ticket) and returns the first `n` such that
```
ceil(price of System B) < price of System A.
```
More examples:
```
movie(500, 15, 0.9) should return 43 
    (with card the total price is 634, with tickets 645)
movie(100, 10, 0.95) should return 24 
    (with card the total price is 235, with tickets 240)
```

Difficulty: EASY
Tags: Fundamentals

Starter code:
def movie(card, ticket, perc):
	

Solutions:
import math

def movie(card, ticket, perc):
	num = 0
	priceA = 0
	priceB = card
	while math.ceil(priceB) >= priceA:
		num += 1
		priceA += ticket
		priceB += ticket * perc ** num
	return num


from itertools import takewhile, count, accumulate

def movie(card, ticket, perc):
	sys_b = accumulate((ticket * perc ** n for n in count(1)))
	sys_a = accumulate((ticket for m in count(1)))
	return sum((1 for a in takewhile(lambda x: round(x[0] + card + 0.49) >= x[1], zip(sys_b, sys_a)))) + 1


from itertools import count
from math import ceil

def movie(card, ticket, perc):
	return next((n for n in count(1) if ceil(card + ticket * perc * (1 - perc ** n) / (1 - perc)) < ticket * n))


import math

def movie(card, ticket, perc):
	(sysA, sysB, count) = (ticket, card + ticket * perc, 1)
	while sysA <= math.ceil(sysB):
		sysA += ticket
		sysB += ticket * perc ** (count + 1)
		count += 1
	return count


from math import ceil

def movie(card, ticket, rate):
	count = 0
	totalA = 0.0
	totalB = 0.0
	while ceil(card + totalB) >= totalA:
		totalA += ticket
		totalB = (totalB + ticket) * rate
		count += 1
	return count


from math import ceil

def movie(card, ticket, perc):
	n = 0
	while 1:
		n += 1
		if ticket * n > ceil(card + ticket * perc * (1 - perc ** n) / (1 - perc)):
			return n


def movie(card, ticket, perc, n=1):
	while card + ticket * perc * (1 - perc ** n) / (1 - perc) - ticket * n > -1:
		n += 1
	return n


def movie(card, ticket, perc, cnt=0):
	while card > -1:
		card += ticket * perc ** cnt * perc - ticket
		cnt += 1
	return cnt


import math

def movie(card, ticket, perc):
	total = card
	n = 1
	while True:
		total += ticket * perc ** n
		if math.ceil(total) < ticket * n:
			break
		n += 1
	return n


import math

def movie(card, ticket, perc):
	sysa = n = 0
	sysb = card
	while math.ceil(sysb) >= sysa:
		n += 1
		sysa += ticket
		sysb += ticket * math.pow(perc, n)
	else:
		return n


import math

def movie(card, ticket, perc):
	n = 0
	a_price = 0
	b_price = card
	perc_multiplier = perc
	while math.ceil(b_price) >= a_price:
		a_price += ticket
		b_price += ticket * perc_multiplier
		perc_multiplier *= perc
		n += 1
	return n


import math

def movie(card, ticket, perc):
	pc = card
	pt = 0
	count = 0
	while not math.ceil(pc) < math.ceil(pt):
		count += 1
		pc += ticket * perc ** count
		pt += ticket
	return count


from math import ceil

def movie(card, ticket, perc):
	i = 0
	sb = card
	sa = 0
	prev = ticket
	while True:
		i += 1
		nou = prev * perc
		sb += nou
		prev = nou
		sa += ticket
		if ceil(sb) < sa:
			return i


from scipy.special import lambertw
from math import ceil, log

def movie(a, b, c):
	log_c = log(c)
	w = lambertw(c ** (a / b + c / (1 - c) + 1 / b + 1) * log_c / (1 - c)).real
	return int(ceil((b * w - b * c * w - a * log(c) + a * c * log_c - b * c * log_c + c * log_c - log_c) / (b * (c - 1) * log_c)))


from itertools import count
from scipy.special import lambertw
from math import log

def movie(a, b, c):
	if a > 0:
		w = lambertw(-c ** (a / b + c / (1 - c) + 1) * log(c) / (c - 1))
		x = (b * w - b * c * w - a * log(c) + a * c * log(c) - b * c * log(c)) / (b * (c - 1) * log(c))
		x = int(x.real + 1)
		A = b * x
		B = a + b * sum((c ** e for e in range(1, x + 1)))
		for i in range(x, x + 5):
			print(i, A, int(B + 1))
			if A > int(B + 1):
				return i
			A += x
			B += b * c ** i
	return 2


def movie(card, ticket, perc):
	return next((n for n in range(9 ** 99) if card + ticket * perc * (1 - perc ** n) / (1 - perc) - ticket * n < -1))


from math import ceil

def movie(card, ticket, perc):
	discount_ticket = ticket
	system_a_price = 0
	system_b_price = card
	days = 0
	while ceil(system_b_price) >= system_a_price:
		days = days + 1
		discount_ticket = discount_ticket * perc
		system_a_price = days * ticket
		system_b_price = system_b_price + discount_ticket
	return days


def movie(card, ticketA, perc):
	assert perc < 1
	ticketB = ticketA
	priceA = times = 0
	priceB = card
	while not priceA > -(-priceB // 1):
		ticketB *= perc
		priceA += ticketA
		priceB += ticketB
		times += 1
	return times


import math

def movie(card, ticket, perc):
	n = 0
	while True:
		n += 1
		A = ticket * n
		B = card + ticket * (perc * (1 - perc ** n) / (1 - perc))
		if math.ceil(B) < A:
			break
	return n


import math

def movie(card, ticket, perc):
	(a, b, n) = (0, card, 0)
	while math.ceil(b) >= a:
		n += 1
		a += ticket
		b += ticket * perc ** n
	return n


import math

def movie(card, ticket, perc):
	n = 1
	while 1:
		if ticket * n > card + math.ceil(ticket * (1 - pow(perc, n)) / (1 - perc)):
			return n - 1
		n = n + 1


import math

def movie(card, ticket, perc):
	x = 1
	systema = 0
	systemb = card
	while systemb >= systema:
		systema = ticket * x
		systemb += ticket * perc ** x
		if math.ceil(systemb) < systema:
			break
		else:
			x += 1
	return x


from math import ceil

def movie(card, ticket, perc):
	prevPrice = ticket
	i = 0
	while True:
		if ceil(card) < ticket * i:
			return i
		prevPrice *= perc
		card += prevPrice
		i += 1


import math

def movie(card, ticket, perc):
	n = card // ticket
	system_go = True
	while system_go:
		system_A = ticket * n
		system_B = card + sum([ticket * perc ** x for x in range(1, n + 1)])
		if system_A < card:
			n += 1
			continue
		if system_A > math.ceil(system_B):
			return n
			break
		else:
			n += 1


import math

def movie(card, ticket, perc):
	tiks = 0
	sysA = 0
	sysB = card
	Bticket = ticket
	while math.ceil(sysB) >= sysA:
		sysA += ticket
		tiks += 1
		Bticket *= perc
		sysB += Bticket
	return tiks


def movie(card, ticket, perc):
	import math
	count = 1
	priceA = card
	priceB = 0
	while True:
		priceB += ticket
		priceDecrease = ticket * pow(perc, count)
		priceA += priceDecrease
		if priceB > math.ceil(priceA):
			return count
		count += 1


import math

def system_a(ticket, times):
	price_a = ticket * times
	return price_a

def system_b(card, ticket, perc, times):
	price_b = 0
	it = perc * ticket
	for i in range(0, times):
		price_b = price_b + it
		it = it * perc
	price_b = price_b + card
	return price_b

def movie(card, ticket, perc):
	times = 1
	systemb = card + ticket * perc
	while math.ceil(systemb) >= system_a(ticket, times):
		systemb = systemb + perc ** (times + 1) * ticket
		times = times + 1
	return times


from math import ceil

def movie(card, ticket, perc):
	n = 0
	ap = 0
	bp = card
	price = ticket
	while ap <= ceil(bp):
		n += 1
		ap += ticket
		price = price * perc
		bp += price
	return n


from math import ceil

def movie(card, ticket, perc):
	(a, b, c) = (0, card, 0)
	while ceil(b) >= ceil(a):
		a += ticket
		b += ticket * perc ** c
		c += 1
	return c - 1


from math import ceil

def movie(card, ticket, perc):
	true = ticket
	sys_b = card
	count = 0
	while True:
		count += 1
		sys_a = count * true
		ticket = perc * ticket
		sys_b += ticket
		if ceil(sys_b) < sys_a:
			return count
	return count


import math

def movie(card, ticket, perc):
	curr_card_price = card
	curr_ticket_price = 0
	next_card_purchase = ticket * perc
	trips = 0
	while math.ceil(curr_card_price) >= curr_ticket_price:
		curr_card_price += next_card_purchase
		curr_ticket_price += ticket
		trips += 1
		next_card_purchase *= perc
	return trips


import math

def movie(card, ticket, perc):
	(Aval, Bval, res) = (ticket, card + ticket * perc, 1)
	while math.ceil(Bval) >= Aval:
		res += 1
		Aval += ticket
		Bval += ticket * perc ** res
	return res


from math import ceil

def movie(card, ticket, perc):
	N = 1
	while ticket * N <= ceil(card + ticket * perc * (1 - perc ** N) / (1 - perc)):
		N += 1
	return N


import math

def movie(card, ticket, perc):
	finnished = False
	n = 0
	previous_total = 0
	while not finnished:
		n += 1
		a = ticket * n
		previous_total += ticket * perc ** n
		b = math.ceil(card + previous_total)
		if a > b:
			finnished = True
	return n


from math import ceil

def movie(card, ticket, perc):
	counter = 0
	sum = card
	perc_ = perc
	while ceil(sum) >= ticket * counter:
		sum += ticket * perc_
		perc_ *= perc
		counter += 1
	return counter


def movie(card, ticket, perc):
	print((card, ticket, perc))
	import math
	total_ticket = 0.0
	total_card = card
	count = 0
	movieprice_bycard = ticket
	while total_ticket <= math.ceil(total_card):
		count += 1
		movieprice_bycard *= perc
		total_ticket += ticket
		total_card += movieprice_bycard
	return count


import math

def movie(card, ticket, perc):
	sys_a = 0
	sys_b = card
	i = 1
	while sys_a <= math.ceil(sys_b):
		sys_a += ticket
		sys_b += ticket * perc ** i
		i += 1
	return i - 1


def movie(card, ticket, perc):
	temp = ticket
	rA = 0
	rB = card
	while rB > rA - 1:
		temp = temp * perc
		rB += temp
		rA += ticket
	print((str(rB), ':', str(rA)))
	return int(rA / ticket)


from math import ceil

def movie(card, ticket, perc):
	(cs, ts, i) = (card + ticket * perc, ticket, 2)
	while ceil(ts) <= ceil(cs):
		(cs, ts, i) = (cs + ticket * perc ** i, ts + ticket, i + 1)
	return i - 1


import math

def movie(crd, tkt, pcnt):
	tktCnt = TotalA = TotalB = 0
	while math.ceil(TotalB) >= TotalA:
		tktCnt += 1
		TotalA = tkt * tktCnt
		TotalB = crd + tkt * (pcnt * (pcnt ** tktCnt - 1) / (pcnt - 1))
	return tktCnt


from math import ceil

def movie(card, ticket, perc):
	priceA = ticket
	priceB = card + ticket * perc
	n = 1
	while ceil(priceB) >= priceA:
		n += 1
		priceA += ticket
		priceB += ticket * perc ** n
	return n


from math import *

def movie(card, ticket, perc):
	n = 0
	seance = 0
	a = card
	ticket_abonnement = 0
	while ceil(a + ticket_abonnement) >= ticket * seance:
		ticket_abonnement += ticket * perc * perc ** n
		n += 1
		seance += 1
	return seance


from math import ceil

def movie(card, ticket, perc):
	(priceOfSystemA, priceOfSystemB, n, ticketPriceB) = (0, card, 0, ticket)
	while ceil(priceOfSystemB) >= priceOfSystemA:
		n += 1
		priceOfSystemA += ticket
		ticketPriceB *= perc
		priceOfSystemB += ticketPriceB
	return n


import math

def movie(card, ticket, perc):
	num_trips = 0
	card_cost = card
	ticket_cost = 0
	while math.ceil(card_cost) >= ticket_cost:
		num_trips += 1
		card_cost += ticket * perc ** num_trips
		ticket_cost += ticket
	return num_trips


import math

def movie(card, ticket, perc):
	reduced = ticket * perc
	total = card + reduced
	n = 1
	while math.ceil(total) >= ticket * n:
		reduced *= perc
		total += reduced
		n += 1
	return n


def movie(card, ticket, perc):
	import math
	n = 1
	s1 = ticket
	s2 = card + ticket * perc
	while s1 <= math.ceil(s2):
		n += 1
		s1 = ticket * n
		s2 += ticket * perc ** n
	return n


import math

def movie(card, ticket, perc):
	n = 1
	ticket_b = ticket
	ticket_total = 0
	sys_a = ticket
	sys_b = card + ticket
	c = sys_b / sys_a
	if c < 1:
		return 1
		exit
	else:
		while True:
			sys_a = n * ticket
			ticket_b = ticket_b * perc
			ticket_total = ticket_total + ticket_b
			sys_b = card + ticket_total
			if math.ceil(sys_b) < sys_a:
				return n
			else:
				n += 1
	return n


import math

def movie(card, ticket, perc):
	i = 1
	lhs = lambda : ticket * i
	rhs = lambda : math.ceil(card + ticket * (1 - perc ** i) / (1 - perc))
	while lhs() <= rhs():
		i *= 2
	low = i / 2 - 1
	high = i + 1
	while low + 1 != high:
		i = (low + high) // 2
		if lhs() <= rhs():
			low = i
		else:
			high = i
	p_lhs = lhs()
	i += 1
	if p_lhs > rhs():
		return i - 2
	return i - 1


import math

def movie(card, ticket, perc):
	i = 1
	lhs = lambda : ticket * i
	rhs = lambda : math.ceil(card + ticket * (1 - perc ** i) / (1 - perc))
	while lhs() <= rhs():
		i += 1
	return i - 1


import math

def movie(card, ticket, perc):
	number_of_tickets = 0
	scenario_a = 0
	scenario_b = 1
	while scenario_a <= scenario_b:
		number_of_tickets += 1
		scenario_a = number_of_tickets * ticket
		scenario_b = math.ceil(card + ticket * (1 - perc ** number_of_tickets) / (1 - perc))
	return number_of_tickets - 1


import math

def movie(card, ticket, perc):
	n = 0
	A = 0.0
	B = card
	while math.ceil(B) >= A:
		n += 1
		A += ticket
		B += ticket * perc ** n
	return n


def movie(card, ticket, perc):
	from math import ceil
	b = card
	n = 1
	while True:
		a = ticket * n
		b = b + ticket * perc ** n
		if b + 1 < a:
			return n
		else:
			n = n + 1


import math

def movie(card, ticket, perc):
	(sys_A, sys_B, count) = (ticket, card + ticket * perc, 1)
	while sys_A <= math.ceil(sys_B):
		sys_A += ticket
		sys_B += ticket * perc ** (count + 1)
		count += 1
	return count


import math

def movie(card, ticket, perc):
	times = 0
	price_A = 0
	price_B = card
	while math.ceil(price_B) >= price_A:
		times += 1
		price_A += ticket
		price_B += ticket * perc ** times
	return times


import math

def movie(card, ticket, perc):
	x = 0
	price1 = 0
	price2 = card
	while math.ceil(price2) >= price1:
		x += 1
		price1 += ticket
		price2 += ticket * perc ** x
	return x


import math

def movie(card, ticket, perc):
	(temp, spend_a, spend_b) = (1, 0, 0)
	while spend_a <= math.ceil(spend_b):
		spend_a += ticket
		if temp == 1:
			spend_b += card + ticket * perc
		else:
			spend_b += ticket * math.pow(perc, temp)
		temp += 1
	return temp - 1


from math import ceil

def movie(card, ticket, perc):
	answer = 1
	systemA = 0
	systemB = card
	while answer > 0:
		systemA += ticket
		systemB += ticket * perc ** answer
		if ceil(systemA) > ceil(systemB):
			return answer
		answer += 1


def movie(card, ticket, perc):
	result = 1
	B = card + ticket * perc
	while ticket * result < B + 1:
		result += 1
		B += ticket * perc ** result
	return result


import math

def movie(card, ticket, perc):
	PriceA = 0
	PriceB = card
	n = 0
	while PriceA <= math.ceil(PriceB):
		n += 1
		PriceA += ticket
		PriceB += ticket * perc ** n
	return n


def movie(card, ticket, perc):
	B = card
	A = 0
	n = 0
	t = ticket
	while A <= int(B) + 1:
		A += ticket
		t *= perc
		B += t
		n += 1
	return n


import numpy as np

def movie(card, ticket, perc):
	licznik = 0
	sysA = 0
	sysB = card
	tic_B = ticket
	while np.ceil(sysA) <= np.ceil(sysB):
		licznik += 1
		sysA += ticket
		tic_B *= perc
		sysB += tic_B
	return licznik


from math import ceil

def movie(card, ticket, perc):
	i = 1
	card = card + ticket * perc
	while True:
		if ceil(card) < i * ticket:
			return i
		else:
			i += 1
			card += ticket * perc ** i


from math import ceil

def movie(card, ticket, perc):
	sysa = 0
	sysb = card
	ratio = ticket * perc
	times = 0
	while sysa <= ceil(sysb):
		sysa += ticket
		sysb += ratio
		ratio *= perc
		times += 1
	return times


import math

def movie(card, ticket, perc):
	(a, tc) = (0, 0)
	tc2 = ticket
	while math.ceil(card) >= tc:
		a += 1
		ticket = ticket * perc
		tc += tc2
		card += ticket
	return a


def movie(card, ticket, perc):
	ticketsBought = 0
	a = 0
	b = card
	while round(b, 0) >= a:
		discount = pow(perc, ticketsBought)
		b += ticket * discount
		ticketsBought += 1
		a += ticket
	if b > round(b, 0):
		b += 1
	if a > b:
		return ticketsBought - 1
	else:
		ticketsBought += 1
		return ticketsBought - 1
	print(f'a:{a}, b:{b}')
	print(f'ticketsBought:{ticketsBought - 1}')
	return ticketsBought - 1


def movie(card, ticket, perc):
	import math
	i = 0
	sys_A = 0
	sys_B = card
	while True:
		i += 1
		sys_B += ticket * perc ** i
		sys_A += ticket
		if math.ceil(sys_B) < sys_A:
			return i


import math

def movie(card, ticket, perc):
	n = 0
	c = 0
	x = ticket
	while c <= math.ceil(card):
		n += 1
		c += ticket
		x *= perc
		card += x
	return n


from math import ceil

def movie(c, t, p):
	n = 1
	while ceil(c + p * t * ((p ** n - 1) / (p - 1))) >= n * t:
		n += 1
	return n


def movie(c, t, p):
	s = c
	n = 1
	while True:
		summation = (1 - p ** (n + 1)) / (1 - p) - 1
		if int(s + t * summation) + 1 < n * t:
			break
		n += 1
	return n


import math

def movie(card, ticket, perc):
	price_A = 0
	visits = 0
	while math.ceil(card) >= price_A:
		price_A += ticket
		card += ticket * perc ** visits
		visits += 1
	return visits - 1


def movie(card, ticket, perc):
	numero_de_tickets = 0
	novo_valor_do_ticket = ticket * perc
	valor_inteiro_do_ticket = 0
	while valor_inteiro_do_ticket <= int(card) + 1:
		card += novo_valor_do_ticket
		valor_inteiro_do_ticket += ticket
		novo_valor_do_ticket *= perc
		numero_de_tickets += 1
	return numero_de_tickets


import math

def movie(card, ticket, perc):
	tickets = 1
	system_a = ticket
	system_b = card + ticket * perc
	while True:
		if math.ceil(system_b) < system_a:
			return tickets
		tickets += 1
		system_a += ticket
		system_b += ticket * perc ** tickets


def movie(card, ticket, perc):
	import math
	sysa = 0
	sysb = card
	tickets = 0
	while True:
		tickets += 1
		sysa += ticket
		sysb += ticket * perc ** tickets
		if math.ceil(sysb) < sysa:
			return tickets


import math

def movie(card, ticket, perc):
	tickets = 1
	ticket_a = ticket
	ticket_b = card + ticket * perc
	while True:
		if math.ceil(ticket_b) < ticket_a:
			return tickets
		ticket_a += ticket
		ticket_b += ticket * perc ** (tickets + 1)
		tickets += 1


from math import ceil

def movie(card, ticket, perc):
	n = 1
	p = card + ticket * perc
	while ceil(p) >= n * ticket:
		n += 1
		p += ticket * pow(perc, n)
	return n


import math

def movie(card, ticket, perc):
	v = 0
	i = 0
	while 1:
		i = i + 1
		if i == 1:
			v = ticket * perc
		elif i > 1:
			v = v * perc
		card += v
		if math.ceil(card) < ticket * i:
			return i


def movie(card, ticket, perc):
	import math
	SystemB = card
	for num in range(1, 500000):
		SystemB += ticket * perc ** num
		if num * ticket > math.ceil(SystemB):
			break
	return num


def movie(card, ticket, perc):
	(A, B) = (ticket, card + ticket * perc)
	(prev, count) = (ticket * perc, 1)
	while A <= int(B) + 1:
		count += 1
		prev = prev * perc
		A += ticket
		B += prev
	return count


from math import ceil

def movie(card, ticket, perc):
	n = 1
	while True:
		card = card + ticket * perc ** n
		ticket_price = ticket * n
		if ticket_price > ceil(card):
			return n
		n += 1


from math import ceil

def movie(card, ticket, perc):
	n = 0
	while True:
		n += 1
		sysA = ticket * n
		sysB = ceil(card + ticket * perc * (1 - perc ** n) / (1 - perc))
		if sysA > sysB:
			return n


import math

def movie(card, ticket, perc):
	system_a: int = 0
	n: int = 0
	system_b = card
	ticket_b = ticket * perc
	while system_a <= math.ceil(system_b):
		n += 1
		system_a = ticket * n
		system_b += ticket_b
		ticket_b = ticket_b * perc
	system_b = math.ceil(system_b)
	print(f'system A price is {system_a}')
	print(f'system B price is {system_b}')
	return n


def movie(a, b, c):
	import math
	for n in range(500000):
		if n * b > math.ceil(a + b * (1 - c ** n) / (1 - c)):
			return n - 1


from math import ceil

def movie(card, ticket, rate):
	count = 0
	totala = 0.0
	totalb = 0.0
	while ceil(card + totalb) >= totala:
		totala += ticket
		totalb = (totalb + ticket) * rate
		count += 1
	return count


import math

def movie(card, ticket, perc):
	count = 0
	system_A = 0
	system_B = card
	while math.ceil(system_B) >= system_A:
		count += 1
		system_A += ticket
		system_B += ticket * perc ** count
	return count


import math

def movie(card, ticket, perc):
	(a, count) = (ticket, 1)
	ticket_p = perc * ticket
	b = card + ticket_p
	while a <= math.ceil(b):
		a += ticket
		ticket_p *= perc
		b += ticket_p
		count += 1
	return count