Advertisement
emodev

Untitled

Feb 15th, 2019
116
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 0.60 KB | None | 0 0
  1. <?php
  2. /**
  3.  * Created by PhpStorm.
  4.  * User: emotu
  5.  * Date: 013 13.2.2019 г.
  6.  * Time: 21:23
  7.  */
  8.  
  9. $array = explode(" ", readline());
  10.  
  11. if (count($array) == 1){
  12.     echo $array[0];
  13.     return;
  14. }
  15.  
  16. //$size = count(arr)
  17.  
  18. for ($i = 0; $i < count($array); $i++) {
  19.     $array = condense($array);
  20. }
  21.  
  22.  
  23. $sum = $array[0];
  24. if (count($array) > 1) {
  25.     $sum += $array[1];
  26. }
  27. echo $sum;
  28. //echo $array[1];
  29.  
  30. function condense($array2)
  31. {
  32.     $condensed = [];
  33.     for ($i = 0; $i < count($array2) -1; $i++) {
  34.         $condensed[$i] = intval($array2[$i] + $array2[$i + 1]);
  35.     }
  36.     return $condensed;
  37. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement