DEV Community

Discussion on: Daily Challenge #69 - Going to the Cinema

Collapse
 
qm3ster profile image
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
}
Collapse
 
yas46 profile image
Yasser Beyer

denied on first lol

Collapse
 
qm3ster profile image
Mihail Malo

Check timestamp by hovering the date lol