Time waiting to buy my tickets

Imagine you are in a queue, every time you reach the first position you can buy just one ticket. Buyers have to wait through the line again if they want to buy more tickets. You are standing in line and has a number of tickets to purchase.

Given a list of buyers with the number of tickets they want to buy, determine how long it will take you to purchase your tickets if you are in the second position. Each transaction takes 1 unit of time. No time is spent moving to the back of the line.

8 replies
  1. japanfever
    japanfever says:

    //one liner solution, by japanfever (E3839EE383AAE382AAE9B3A9E38388E383ACE383AD)
    let p_queue_time = t.reduce((a, x, i) => (x p), 0);

    • Génesis
      Génesis says:

      I’m happy to see you back japanfever, I missed you 😛 what have you been doing? Hey, we thought about going to Japan’s Cherry Blossoms but finally we’re going to Boston Dynamics and the MIT, if my gf lets me haha.

  2. japanfever
    japanfever says:


    //one liner solution, by japanfever (E3839EE383AAE382AAE9B3A9E38388E383ACE383AD)
    let p_queue_time = t.reduce((a, x, i) => (x p), 0);

  3. japanfever
    japanfever says:

    //one liner solution, by japanfever (E3839EE383AAE382AAE9B3A9E38388E383ACE383AD)
    let p_queue_time = t.reduce((a, x, i) => (x p), 0);

    • Génesis
      Génesis says:

      Good point, I should have used a reduce for that, less code and it’s still easy to understand.

    • Génesis
      Génesis says:

      I see all your comments perfectly, maybe some cache issues on the browser, I don’t know but it’s true that sometimes WP sucks, at least they improved the interface (Dashboard) in the latest versions.

Comments are closed.