Skip to content

Instantly share code, notes, and snippets.

@jehoshua02
Created November 29, 2012 16:58
Show Gist options
  • Select an option

  • Save jehoshua02/4170373 to your computer and use it in GitHub Desktop.

Select an option

Save jehoshua02/4170373 to your computer and use it in GitHub Desktop.
Solution to mensa puzzle 51
<?php
$answer = 11;
while (!check($answer)) {
echo "{$answer} is not correct.";
$answer += 11;
echo " trying {$answer}...\n";
}
echo "answer is {$answer}\n";
function check($answer)
{
$conditions = array(
($answer % 3 == 2),
($answer % 5 == 4),
($answer % 7 == 6),
($answer % 9 == 8),
($answer % 11 == 0),
);
var_dump($conditions);
foreach ($conditions as $condition) {
if (!$condition) {
return false;
}
}
return true;
}
@jehoshua02
Copy link
Author

Any idea how to figure this out manually, faster than writing a script?

@hhatfield
Copy link

This is a good brute force way. Can you write it to be more efficient?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment