| 1 | <?php |
||
| 5 | final class Bowling |
||
| 6 | { |
||
| 7 | 7 | public function __invoke(array $tries) : int |
|
| 8 | { |
||
| 9 | 7 | $punctuation = 0; |
|
| 10 | |||
| 11 | 7 | foreach ($tries as $num_try => $try) |
|
| 12 | { |
||
| 13 | 7 | if ($this->isATryWithStrike($try)) |
|
| 14 | { |
||
| 15 | $current_punctuation = 10 + $tries[$num_try+1] + $tries[$num_try+2]; |
||
| 16 | $punctuation+= $current_punctuation; |
||
| 17 | continue; |
||
| 18 | } |
||
| 19 | |||
| 20 | 7 | if ($this->isAFrameWithSpare($tries, $num_try)) |
|
| 21 | { |
||
| 22 | 2 | $current_punctuation = 10 + $tries[$num_try+2]; |
|
| 23 | |||
| 24 | 2 | $punctuation+=$current_punctuation; |
|
| 25 | 2 | continue; |
|
| 26 | } |
||
| 27 | |||
| 28 | 7 | $punctuation+= $try; |
|
| 29 | } |
||
| 30 | |||
| 31 | return $punctuation; |
||
| 32 | } |
||
| 33 | |||
| 34 | 7 | private function isAFrameWithSpare($tries, $num_try) |
|
| 38 | |||
| 39 | 7 | private function isATryWithStrike($try) |
|
| 43 | } |
||
| 44 |