Skip to content

Instantly share code, notes, and snippets.

@ekkinox
Created November 3, 2017 11:18
Show Gist options
  • Save ekkinox/87c073bfd07dfe5d3d2f3b0e53123084 to your computer and use it in GitHub Desktop.
Save ekkinox/87c073bfd07dfe5d3d2f3b0e53123084 to your computer and use it in GitHub Desktop.
Magic three
<?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