fork(1) download
  1. <?php
  2.  
  3. function f($a)
  4. {
  5. while(count($a)>1)
  6. {
  7. $l = array_shift($a); $r = array_shift($a);
  8. array_unshift($a,($j=$i++%5)==0?($l+$r):($j==1?($l-$r):($j==2?($l*$r):($j==3?($l/$r):(pow($l,$r))))));
  9. }
  10. return array_pop($a);
  11. }
  12.  
  13. echo f([1,2,3,4,5])."\n";
  14. echo f([5,12,23,2,4,4,2,6,7])."\n";
  15. echo f([-8,50,3,3,-123,4,17,99,13])."\n";
  16. echo f([2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2])."\n";
  17. echo f([1,0,1,0,1,0])."\n";
  18. echo f([-9,-8,-1])."\n";
  19. echo f([0,-3])."\n";
  20. echo f([-99])."\n";
Success #stdin #stdout #stderr 0.02s 52480KB
stdin
Standard input is empty
stdout
0
539
-1055.3569438463
256
1
-16
-3
-99
stderr
PHP Notice:  Undefined variable: i in /home/KDcWCe/prog.php on line 8
PHP Notice:  Undefined variable: i in /home/KDcWCe/prog.php on line 8
PHP Notice:  Undefined variable: i in /home/KDcWCe/prog.php on line 8
PHP Notice:  Undefined variable: i in /home/KDcWCe/prog.php on line 8
PHP Notice:  Undefined variable: i in /home/KDcWCe/prog.php on line 8
PHP Notice:  Undefined variable: i in /home/KDcWCe/prog.php on line 8
PHP Notice:  Undefined variable: i in /home/KDcWCe/prog.php on line 8