Guest User

yodle

a guest
Jun 25th, 2014
355
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 0.43 KB | None | 0 0
  1. <?
  2.     $data = file_get_contents("triangle.txt",TRUE);
  3.    
  4.     $rows = explode("\n", $data); //create array separate by new line
  5.  
  6.     $position = 0;
  7.  
  8.     for ($i=0; $i<count($rows); $i++)  
  9.     {
  10.         $each = explode(' ', $rows[$i]);
  11.        
  12.         //determine the position of max value
  13.         if ($each[$position] < $each[$position+1]){
  14.             $position++;
  15.         }
  16.         //and put it together
  17.         $summ = $summ + $each[$position];
  18.     }
  19.    
  20.     echo $summ."@yodle.com";
  21. ?>
Advertisement
Add Comment
Please, Sign In to add comment