Skip to content

Instantly share code, notes, and snippets.

@fernandomm
Created January 12, 2012 11:40
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save fernandomm/1600022 to your computer and use it in GitHub Desktop.
Save fernandomm/1600022 to your computer and use it in GitHub Desktop.
#!/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