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!
Top comments (14)
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!
My solution in js
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.
is the + !!stations just to add one?
Gotta love that
.reduce()
It could also be done as a one-liner with something like this, but it's a lot less clear:
My challenge is writing this is Haskell on the phone without running the code.
Clojure:
In reason:
Here on sketch: sketch.sh/s/uYFZAhtZSc2Ya4r6t1GNKM/
Elm
Tests
Playground
Hosted here on Ellie App.
This is a Swift solution:
My code in JS
c#: