Advertisement
MartinGeorgiev

Condense Array to Number

Jun 1st, 2022
959
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 0.29 KB | None | 0 0
  1. <?php
  2. $array = explode(' ', readline());
  3. $condensed = $array;
  4. while (count($array) > 1) {
  5.     $condensed = [];
  6.     for ($i = 0; $i < count($array) - 1; $i++) {
  7.         $condensed[] = intval($array[$i]) + intval($array[$i + 1]);
  8.     }
  9.     $array = $condensed;
  10. }
  11. echo $condensed[0];
  12.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement