Created
January 12, 2012 11:40
-
-
Save fernandomm/1600022 to your computer and use it in GitHub Desktop.
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
#!/usr/bin/php | |
<?php | |
if (!isset($argv[1])) { | |
exit('Please, choose a number.'. PHP_EOL); | |
} | |
$numero = (int) $argv[1]; | |
if ($numero < 3 || $numero > 1000) { | |
exit('Number should be between 3 and 1000.'. PHP_EOL); | |
} | |
for ($numero1 = 0; $numero1 < 1000; $numero1++) { | |
for ($numero2 = 0; $numero2 < 1000; $numero2++) { | |
for ($numero3 = 0; $numero3 < 1000; $numero3++) { | |
if (($numero1 + $numero2 + $numero3) == $numero | |
&& $numero1 != $numero2 | |
&& $numero2 != $numero3 | |
&& $numero3 != $numero1) { | |
echo $numero1 .','. $numero2 .','. $numero3 . PHP_EOL; | |
} | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment