Today's challenge comes from aryan-firouzian on Codewars. You are to figure out how many people are on the bus given the following scenario:
There is a bus moving in the city, and it takes and drop some people at each bus stop.
You are provided with a list (or array) of integer arrays (or tuples). Each integer array has two items which represent the number of people that get on the bus (The first item) and the number of people that get off the bus (The second item) at a bus stop.
Your task is to return number of people who are still left on the bus after the last bus station (after the last array).
Good luck, and happy coding!
Thank you to CodeWars, who has licensed redistribution of this challenge under the 2-Clause BSD License!
Want to propose a challenge for a future post? Email yo+challenge@dev.to with your suggestions!
Latest comments (19)
Here is the simple solution with Python:
My solution in js
Haskell:
CSS (kind of):
For the list of of integer arrays, we can use an actual HTML list with
<li>that contain CSS variables with the number of people going up (--up) and down (--down) the bus. Then using CSS counters we can keep a count of the people who are on the bus at each moment.Live demo on CodePen.
Smalltalk --- because it seems nobody did it yet:
Elixir:
Didn't see anyone else try it in C, so here's my solution in C:
JS
Haskell
R