Naismith's rule helps to work out the length of time needed for a walk or hike, given the distance and ascent.
Given a non-empty list of the altitude at points evenly spaced along a path and the total distance of that path in metres, you should calculate the time needed according to Naismith's rule.
Naismith's rule is that you should allow one hour for every five kilometres, plus an additional hour for every 600 metres of ascent.
Input must be taken in metres, which is guaranteed to consist of non-negative integers, and output should consistently be either hours or minutes (but not both), and must be able to give decimal numbers where applicable (floating point inaccuracies are OK).
For example, given:
[100, 200, 400, 200, 700, 400], 5000
For the first two elements [100, 200]
you have 100 metres of ascent which is 10 minutes. With [200, 400]
you have 200 metres of ascent which is 20 minutes, [400, 200]
is not ascending so no time is added for that. [200, 700]
is 500 metres of ascent which is 50 minutes, and finally [700, 400]
is not ascending. One extra hour is added for the distance of five kilometres. This totals to 140 minutes or 2.333... hours.
Test Cases
[0, 600] 2500 -> 1.5 OR 90
[100, 200, 300, 0, 100, 200, 300] 10000 -> 2.8333... OR 170
[40, 5, 35] 1000 -> 0.25 OR 15
[604] 5000 -> 1 OR 60
[10, 10, 10] 2000 -> 0.4 OR 24
[10, 25, 55] 1000 -> 0.275 OR 16.5
[10], 5125
or[10, 25, 55], 1000
valid and required to be handled? \$\endgroup\$ – sundar - Reinstate Monica Aug 7 '18 at 8:44[10, 25, 55], 1000 -> 0.275 OR 16.5
\$\endgroup\$ – Khuldraeseth na'Barya Aug 8 '18 at 13:32