Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <?php
- $nums = array_map('intval', explode(' ', readline()));
- $step = $nums[0];
- $stepPrev = 0;
- $sum = $step;
- while(true){
- if (($stepPrev + $step) < count($nums)){
- $sum += $nums[$stepPrev+$step];
- $stepPrev += $step;
- }elseif (($stepPrev + $step) > count($nums) && ($stepPrev - $step) >= 0){
- $sum += $nums[$stepPrev-$step];
- $stepPrev -= $step;
- }else{
- echo $sum;
- return;
- }
- $step = $nums[$stepPrev];
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement