Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <?php
- $input = <<<END
- 10
- 10 750
- 1.8 0
- 3.5 0
- 10 0
- 10 71.428571428571428571428571428571
- 5.5 1000
- 10 1220
- 16.5 500
- 22 600
- 26 1000
- END;
- $input = explode("\n", $input);
- array_shift($input);
- foreach($input as $key => $value){
- $input[$key] = explode(" ", $value);
- }
- //distance km, ascention m
- function roundnum($num, $nearest = 5){
- return round($num / $nearest) * $nearest;
- }
- function rule_times($d, $a){
- $time1 = $d/3.5 + $a/500;
- if($time1 > 3){
- $time2 = 0.02*pow($time1, 2) + 1.19*$time1 - 0.75;
- }else{
- $time2 = $time1;
- }
- //round to the nearest 5
- $time1_min = str_pad(roundnum(($time1 - floor($time1))*60), 2, '0', STR_PAD_LEFT);
- $time2_min = str_pad(roundnum(($time2 - floor($time2))*60), 2, '0', STR_PAD_LEFT);
- $time1 = floor($time1).':'.$time1_min;
- $time2 = floor($time2).':'.$time2_min;
- return array($time1, $time2);
- }
- foreach($input as $key => $value){
- $times = rule_times($value[0], $value[1]);
- $d = str_pad(number_format($value[0], 1, '.', '').'km', 7, ' ', STR_PAD_LEFT);
- $a = str_pad(number_format($value[1], 0, '.', '').'m', 7, ' ', STR_PAD_LEFT);
- $n_time = str_pad($times[0], 6, ' ', STR_PAD_LEFT);
- $a_time = str_pad($times[1], 6, ' ', STR_PAD_LEFT);
- echo 'Distance:'.$d.' ascent:'.$a.' Naismith:'.$n_time.' adjusted time:'.$a_time."\n";
- }
Advertisement
Add Comment
Please, Sign In to add comment