3v4l.org

run code in 200+ php & hhvm versions
Bugs & Features
<?php function distribute ($sum, $number, $base = 130, $part2 = 30 ,$relation = 4, &$h3=12, $debug=false) { $outp = ""; $result = array(); $outp.= "SUM: $sum <br> NUM: $number <br> BASE: $base <br>"; $C2 = $relation; $p1 = min (3,$number); $p2 = floor(($number-$p1) * $part2); $outp .= "$number $p1 $part2 <br>" ; $b = $number * $base; $p3 = $number - ($p1 + $p2); $outp.= "part1: $p1<br> part2: $p2<br> part3: $p3 <br><br>"; if ($debug) echo $h3; if ($h3==-1) $h3=ceil(($number/5)*ceil($base/10)); if ($debug) echo $h3; $v3 = $h3 * ($p1+$p2); $t3=0; $hh = triangleHeights($h3,$p3); $k=0; for ($i=$p1+$p2+1; $i<=$p1+$p2+$p3; $i++) { $result[$i]=$base+$hh[$k]; $t3+=$hh[$k]; $k++; } $top = $sum - $b - $t3 - $v3; / $h2=floor($top / ($p1+0.5*$C2*$p1+0.5*$p2)); $h1=$C2*$h2; if ($h2 == 0 ) $h1=2*$top/$p1; $v2 = $h2 * $p1; $t1 = floor(($p1 * $h1) / 2.0); $t2 = floor(($p2 * $h2) / 2.0); $left = $top - ($t1+$t2+$v2); if ($left>0 && $t1>0) { $hTmp = (($t1+$left)*$h1)/$t1; $h1=$hTmp; $t1 += $left; } $outp.= "t1: $t1<br>t2: $t2<br>t3: $t3<br><br>"; if ($p2>0) { $hh = triangleHeights($h2,$p2,$t2); $sm = 0; $k=0; for ($i=$p1+1;$i<=$p1+$p2;$i++) { $result[$i]=$base+$h3+$hh[$k]; $sm += $hh[$k]; $k++; } $outp .="Sum2 is $sm! <br>"; } if ($p1>0) { $hh = triangleHeights($h1,$p1,$t1); $sm = 0; $k=0; for ($i=1;$i<=$p1;$i++) { $result[$i]=$base+$h2+$h3+$hh[$k]; $sm += $hh[$k]; $k++; } $outp .="Sum1 is $sm! <br>"; } $outp.= "h1: $h1<br>h2: $h2<br>h3: $h3<br><br>"; $outp.= "v2: $v2<br>v3: $v3 <br> b: $b <br> top: $top<br><br>"; $sum = 0; for ($i=1;$i<=$number;$i++) { $sum += $result[$i]; } $outp.= "SUM is $sum<br>"; if ($debug) echo $outp; if ($top<0) $result[1]=-1; return $result; } function triangleHeights ($h, $w, $sum=0) { $heights = array(); for ($i=0;$i<$w;$i++) { $hi = ($h*($w-$i)/$w); $hi1 = ($h*($w-($i+1))/$w); $heights [$i]=floor(($hi+$hi1)/2.0);; $sum-=$heights[$i]; } while ($sum>0) { $i=0; while ($sum>0 && $i<$w) { $heights[$i]++; $sum--; $i++; } } return $heights; } print_r(distribute(90,10,100));
Output for 5.1.0 - 5.4.34
Parse error: syntax error, unexpected '/' in /in/rvVrI on line 40
Process exited with code 255.
Output for 5.0.0 - 5.0.5
Parse error: parse error, unexpected '/' in /in/rvVrI on line 40
Process exited with code 255.
Output for 4.4.2 - 4.4.9
Parse error: syntax error, unexpected '=', expecting ')' in /in/rvVrI on line 2
Process exited with code 255.
Output for 4.3.0 - 4.3.1, 4.3.5 - 4.4.1
Parse error: parse error, unexpected '=', expecting ')' in /in/rvVrI on line 2
Process exited with code 255.
Output for 4.3.2 - 4.3.4
Parse error: parse error, expecting `')'' in /in/rvVrI on line 2
Process exited with code 255.