The Pony Express was a mail service that operated from 1859-60 in the United States. It was made completely obsolete by the intercontinental telegraph.
There were a number of stations where a rider would stop to switch to a fresh horse, or pass the mail bag along to another rider to continue the trek.
stations
is an array/list of distances in miles from one station to the next along the route.
Implement a riders
function, to return how many riders it would take to get from point A to point B. Riders will never agree to riding more than 100 miles.
example: stations = [43, 23, 40, 13]
output: 2 riders
Good luck!
This challenge comes from dinglemouse on CodeWars. Thank you to CodeWars, who has licensed redistribution of this challenge under the 2-Clause BSD License!
Want to propose a challenge idea for a future post? Email yo+challenge@dev.to with your suggestions!
Latest comments (14)
My challenge is writing this is Haskell on the phone without running the code.
My code in JS
Gotta love that
.reduce()
It could also be done as a one-liner with something like this, but it's a lot less clear:
In reason:
Here on sketch: sketch.sh/s/uYFZAhtZSc2Ya4r6t1GNKM/
This is a Swift solution:
In Python:
c#:
Clojure:
Elm
Tests
Playground
Hosted here on Ellie App.
My solution in js
is the + !!stations just to add one?
Nice your solution is a little bit on an expert level here my JS solution
Good approach. Taking the total and dividing by 100 to see how many riders.
The question is a bit unclear: it speaks about getting from A to B and then lists 4 points. I assume that A is the first and B the last.
So then...
APL (Dyalog APL)
The complete program:
Testing...
Try it online!