| Conditions | 5 |
| Paths | 7 |
| Total Lines | 24 |
| Code Lines | 15 |
| Lines | 0 |
| Ratio | 0 % |
| Changes | 0 | ||
| 1 | <?php |
||
| 7 | public function solution($A) |
||
| 8 | { |
||
| 9 | $position = 0; |
||
| 10 | $count = count($A); |
||
| 11 | $minAvg = ($A[0] + $A[1]) / 2; |
||
| 12 | |||
| 13 | for ($p = 0; $p < $count - 1; $p++) { |
||
| 14 | $avg = ($A[$p] + $A[$p + 1]) / 2; |
||
| 15 | if ($avg < $minAvg) { |
||
| 16 | $minAvg = $avg; |
||
| 17 | $position = $p; |
||
| 18 | } |
||
| 19 | |||
| 20 | if (isset($A[$p + 2])) { |
||
| 21 | $avg = ($A[$p] + $A[$p + 1] + $A[$p + 2]) / 3; |
||
| 22 | if ($avg < $minAvg) { |
||
| 23 | $minAvg = $avg; |
||
| 24 | $position = $p; |
||
| 25 | } |
||
| 26 | } |
||
| 27 | } |
||
| 28 | |||
| 29 | return $position; |
||
| 30 | } |
||
| 31 | } |
||
| 32 |