Created
November 3, 2017 11:18
-
-
Save ekkinox/87c073bfd07dfe5d3d2f3b0e53123084 to your computer and use it in GitHub Desktop.
Magic three
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
class MagicThreeResolver | |
{ | |
/** | |
* @param array $numbers | |
* | |
* @return bool | |
*/ | |
public function resolve(array $numbers) | |
{ | |
foreach ($numbers as $n1) | |
{ | |
foreach ($numbers as $n2) | |
{ | |
foreach ($numbers as $n3) | |
{ | |
if (array_sum([$n1, $n2, $n3]) === 0) | |
{ | |
return true; | |
} | |
} | |
} | |
} | |
return false; | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment