Skip to content

Instantly share code, notes, and snippets.

@mrfrostikcz
Created June 7, 2022 08:51
Show Gist options
  • Save mrfrostikcz/5c2d4c751498586b65d6c62ff27bb206 to your computer and use it in GitHub Desktop.
Save mrfrostikcz/5c2d4c751498586b65d6c62ff27bb206 to your computer and use it in GitHub Desktop.
<?php
public function battleResult(string $good, string $evil): string
{
$good = $this->getFormattedResult($good);
$evil = $this->getFormattedResult($evil);
if ($good > $evil) {
return 'Battle Result: Good triumphs over Evil';
}
if ($evil > $good) {
return 'Battle Result: Evil eradicates all trace of Good';
}
return 'Battle Result: No victor on this battle field';
}
private function getFormattedResult(string $score): int
{
return array_sum(array_map(static fn(string $part) => (int) $part, explode(' ', $score)));
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment