Last active
August 29, 2015 14:21
-
-
Save 4lun/949b4abd1ee56845d6bc to your computer and use it in GitHub Desktop.
Generates solutions for the maths puzzle for Vietnamese eight-year-olds. UPDATE: Missing quite a few answer combinations, see comment thread here: http://www.theguardian.com/science/alexs-adventures-in-numberland/2015/may/20/can-you-do-the-maths-puzzle-for-vietnamese-eight-year-olds-that-has-stumped-parents-and-teachers#comment-52484375
This file contains 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
8, 9, 6, 1, 3, 4, 7, 5, 2 | |
8, 9, 3, 6, 5, 1, 2, 7, 4 | |
7, 9, 3, 1, 2, 5, 6, 8, 4 | |
9, 8, 2, 4, 5, 7, 6, 1, 3 | |
7, 6, 1, 9, 5, 4, 2, 8, 3 | |
9, 8, 6, 4, 5, 1, 7, 2, 3 | |
7, 6, 1, 4, 3, 8, 9, 5, 2 | |
5, 7, 1, 3, 4, 9, 8, 2, 6 | |
7, 6, 4, 1, 3, 8, 5, 9, 2 | |
8, 9, 6, 3, 5, 1, 2, 7, 4 | |
7, 8, 4, 2, 5, 6, 9, 1, 3 | |
9, 3, 6, 1, 5, 2, 7, 4, 8 | |
7, 9, 1, 3, 2, 5, 6, 8, 4 | |
7, 6, 4, 1, 3, 8, 9, 5, 2 | |
7, 8, 2, 4, 3, 9, 6, 5, 1 | |
7, 6, 1, 4, 3, 8, 5, 9, 2 | |
7, 2, 1, 3, 5, 4, 8, 6, 9 | |
5, 7, 3, 1, 4, 9, 8, 2, 6 | |
9, 3, 6, 1, 5, 2, 4, 7, 8 | |
1, 9, 4, 3, 6, 7, 5, 2, 8 | |
4, 8, 6, 1, 5, 9, 7, 2, 3 | |
8, 9, 1, 6, 3, 4, 7, 5, 2 | |
8, 9, 6, 3, 5, 1, 7, 2, 4 | |
7, 2, 8, 1, 6, 9, 5, 3, 4 | |
9, 4, 1, 8, 5, 2, 3, 7, 6 | |
7, 2, 1, 8, 6, 9, 5,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9, 4, 8, 1, 5, 2, 7, 3, 6 | |
7, 9, 1, 3, 2, 5, 8, 6, 4 | |
8, 9, 3, 6, 5, 1, 7, 2, 4 | |
7, 8, 4, 2, 5, 6, 1, 9, 3 | |
7, 8, 4, 2, 3, 9, 5, 6, 1 | |
7, 2, 1, 8, 6, 9, 3, 5, 4 | |
4, 8, 1, 6, 5, 9, 2, 7, 3 | |
9, 3, 1, 6, 5, 2, 4, 7, 8 | |
9, 8, 6, 4, 5, 1, 2, 7, 3 | |
7, 2, 3, 1, 5, 4, 6, 8, 9 | |
7, 8, 4, 2, 3, 9, 6, 5, 1 | |
Total answers: 72 |
This file contains 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 | |
/* | |
Solve: __ + 13 * __ / __ / __ + 12 * __ - __ - 11 + __ * __ / __ == 66 | |
From: http://www.theguardian.com/science/alexs-adventures-in-numberland/2015/may/20/can-you-do-the-maths-puzzle-for-vietnamese-eight-year-olds-that-has-stumped-parents-and-teachers | |
Thrown together in 15mins, pretty far from optimal | |
*/ | |
ini_set('memory_limit', '512M'); // Told you | |
function equals($a) { | |
$result = $a[0] + 13 * $a[1] / $a[2] / $a[3] + 12 * $a[4] - $a[5] - 11 + $a[6] * $a[7] / $a[8]; | |
return $result; | |
} | |
function permutationCount($a) { | |
$num = 1; | |
$count = count($a); | |
if ($count > 1) { | |
for ($i = 1; $i <= $count; $i++) { | |
$num *= $i; | |
} | |
} | |
return $num; | |
} | |
$nums = []; | |
for($i = 1; $i <= 9; $i++) { | |
$nums[] = $i; | |
} | |
$premutations = []; | |
$premutationCount = permutationCount($nums); | |
while(count($premutations) < $premutationCount) { | |
shuffle($nums); // Hit it with a hammer until it works | |
$hash = serialize($nums); | |
if(!isset($premutations[$hash])) { | |
$premutations[$hash] = $nums; | |
} | |
} | |
$answers = []; | |
foreach($premutations as $premutation) { | |
$equals = equals($premutation); | |
if($equals == 66) { | |
$answers[] = $premutation; | |
} | |
} | |
foreach($answers as $answer) { | |
echo implode(', ', $answer) . "\n"; | |
} | |
echo "\nTotal answers: ". count($answers); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment