6 kyu

Kata 2019: Fibonacci Bus

37 of 115myjinxin2015
Description
Loading description...
Mathematics
Algorithms
  • Please sign in or sign up to leave a comment.
  • saudiGuy Avatar

    python new test framework is required. updated in this fork

  • l2iisk Avatar

    I am not sure I really understand what is going on here. SO the first example is test.assert_equals(calc(5,7,32,4),13): But if I do it by hand I am getting nowhere to +13??? Could someone help and explain me, where my mistake is?

    station pass_get_on pass_get_off on_bus
    1 +5 0 5
    2 0 0 5
    3 +10 -5 10
    4 +15 -10 15
    5 +25 -15 25
    6 +40 -25 40
    7 +65 -32-40 33
    • Chrono79 Avatar

      I guess the problem is you don't know in the second step how many persons got on the bus, you assumed 0 and that's not the case, you should calculate it given the number of persons got off at the last station.

    • l2iisk Avatar

      In the details it says:

      "At the second station(station2), a certain number of passengers get on and the same number get off. There are still k passengers on the bus." So I know that 0 passengers got on the bus, since it is still k passengers on the bus.

    • Chrono79 Avatar

      No, you're wrong, because the same amount of people that got on got off, so it's wrong to assume it was 0. It affects the following steps, see:

      station:    1 2 3  4  5  6  7
      got on:     5 3 8  11 19 30 0 
      got off:    0 3 3  8  11 19 32
      on the bus: 5 5 10 13 21 32 0
      
    • l2iisk Avatar

      Ahhhh, now I get it :D my bad. Thanks for the quick help

  • lechevalier Avatar

    n <= 30 is really low. In my opinion, with mathematics tag, a bruteforcish solution shouldn't pass test suite. Seems reasonable to raise this upper bound to 10000 or 100000.

    • myjinxin2015 Avatar

      Perhaps Python can do this, but JS can not suport such a large range. And the main point of this kata is how to calculate it(using basic mathematical method), not how to calculate it quickly(with performance requirement). So, I think, it's not an issue ;-)

      Issue marked resolved by myjinxin2015 6 years ago
  • dinglemouse Avatar

    ?? - 10^10 passengers on a bus? Must be hard to get a seat!

  • Blind4Basics Avatar

    please, correct your description, it's a nightmare to follow what you're talking about...

    From station3 to stationn-1, the number of boarding and alighting passengers follows the following rule:

    • At stationi, the number of people getting on is the sum of the number of people getting on at the first two two previous stations(stationi-1 and stationi-2)
    • The number of people getting off is equal to the number of people getting on at the last previous station (stationi-1). At stationi stationn, all the passengers get off the bus.

    Is that what you actually mean? (edit: yes it is...)