## DEV Community is a community of 619,270 amazing developers

We're a place where coders share, stay up-to-date and grow their careers.

# Discussion on: Daily Challenge #69 - Going to the Cinema Mihail Malo • Edited

"first" lmao

``````const movie = (card, ticket, part) => {
let i = 0
let a = 0
let b = card
do {
a += ticket
b += ticket * part ** i
i++
} while (Math.ceil(b) >= a)
return i - 1
}
``````

an "optimization" (no power)

``````const movie = (card, ticket, part) => {
let i = 0
let a = 0
let b = card
let cheap = ticket
while (true) {
a += ticket
b += cheap
cheap *= part
if (Math.ceil(b) < a) return i
i++
}
}
``````

"optimization II" (no `Math.ceil`, comparison with 0 instead of 1)

``````const movie = (card, ticket, part) => {
let i = 0
let dif = -card - 1
let cheap = ticket
while (true) {
dif += ticket - cheap
cheap *= part
if (dif > 0) return i
i++
}
}
``````

idiocy.

``````const movie = (card, ticket, part) => {
let i = 1
let dif = -card - 1
let cheap = ticket
while ((dif += ticket - (cheap *= part)) <= 0) i++
return i
}
``````