Asheeown Posted May 10, 2010 Share Posted May 10, 2010 This problem was shot my way by a friend who is curious of the answer. And it is essentially this: You are given these nine (9) letters: A, B, C, D, E, F, G, H, K The letters each represent a number (1-9) and each is unique, so if A=1 no other letter could equal 1. Given that information you have to find the set of numbers that will make the following two equations correct. A * (BC) = (DEF) = (HK) * G A * (EC) = (DBG) = (AK) * F Letters that are grouped together in parenthesis make a whole number (Ex. B=2 C=3 (BC) = 23) So I wrote this PHP script to run random sets of numbers through and see if they worked out, the thing is, it's been running for three days now and hasn't found an answer. Is my scripting incorrect or is it really just taking that long? And I've tried it with just one or two parts of the equations and it has found answers, but only for those specifically. <?php set_time_limit(0); // Start time elapsed function $mtime = microtime(); $mtime = explode(" ",$mtime); $mtime = $mtime[1] + $mtime[0]; $starttime = $mtime; //////////////////////////////////// while(true) { $a = rand(1, 9); while(true) { $b = rand(1,9); if($b != $a) { break; } } while(true) { $c = rand(1,9); if($c != $b and $c != $a) { break; } } while(true) { $d = rand(1,9); if($d != $c and $d != $b and $d != $a) { break; } } while(true) { $e = rand(1,9); if($e != $d and $e != $c and $e != $b and $e != $a) { break; } } while(true) { $f = rand(1,9); if($f != $e and $f != $d and $f != $c and $f != $b and $f != $a) { break; } } while(true) { $g = rand(1,9); if($g != $f and $g != $e and $g != $d and $g != $c and $g != $b and $g != $a) { break; } } while(true) { $h = rand(1,9); if($h != $g and $h != $f and $h != $e and $h != $d and $h != $c and $h != $b and $h != $a) { break; } } while(true) { $k = rand(1,9); if($k != $h and $k != $g and $k != $f and $k != $e and $k != $d and $k != $c and $k != $b and $k != $a) { break; } } if(($a * ($b . $c)) == ($d . $e . $f) and ($a * ($b . $c)) == (($h . $k) * $g) and ($a * ($e . $c)) == ($d . $b . $g) and ($a * ($e . $c)) == (($a . $k) * $f)) { break; } } echo "A = " . $a . "\n"; echo "B = " . $b . "\n"; echo "C = " . $c . "\n"; echo "D = " . $d . "\n"; echo "E = " . $e . "\n"; echo "F = " . $f . "\n"; echo "G = " . $g . "\n"; echo "H = " . $h . "\n"; echo "K = " . $k . "\n"; echo "\n\n"; // End time elapsed function $mtime = microtime(); $mtime = explode(" ",$mtime); $mtime = $mtime[1] + $mtime[0]; $endtime = $mtime; $totaltime = ($endtime - $starttime); echo "This page was created in ".$totaltime." seconds\n"; //////////////////////////////////////////////// ?> Quote Link to comment https://forums.phpfreaks.com/topic/201287-is-this-calculation-correct/ Share on other sites More sharing options...
Daniel0 Posted May 10, 2010 Share Posted May 10, 2010 So I wrote this PHP script to run random sets of numbers through and see if they worked out, the thing is, it's been running for three days now and hasn't found an answer. Are you sure there even is a solution? Letters that are grouped together in parenthesis make a whole number (Ex. B=2 C=3 (BC) = 23) Yeah, so what you call (BC) is what would normally be 10*B+C, which is exactly how positional number systems work. You can trivially verify if a given solution is correct in constant time. You just need to generate all 9! = 362880 different permutations and check each one until you meet a correct solution. If you don't find any doing this, there exists no solution. Quote Link to comment https://forums.phpfreaks.com/topic/201287-is-this-calculation-correct/#findComment-1056133 Share on other sites More sharing options...
roopurt18 Posted May 10, 2010 Share Posted May 10, 2010 There is no solution. Solve the first equation for A: A = (DEF) / (BC) Solve the second equation for A: A = (DBG) / (EC) Set the two equal to each other: (DEF) / (BC) = (DBG) / (EC) In order for this to be true, the following must hold: E = B F = G The problem forbids this from being the case. Therefore no solution exists. Quote Link to comment https://forums.phpfreaks.com/topic/201287-is-this-calculation-correct/#findComment-1056146 Share on other sites More sharing options...
Daniel0 Posted May 10, 2010 Share Posted May 10, 2010 (DEF) / (BC) = (DBG) / (EC) In order for this to be true, the following must hold: E = B F = G How is that true? You need to keep in mind that in his notation, (DEF) != D*E*F. Using standard mathematical notation, his equations are: A * (10*B + C) = (100*D + 10*E + F) = (10*H + K) * G A * (10*E + C) = (100*D + 10*B + G) = (10*A + K) * F Quote Link to comment https://forums.phpfreaks.com/topic/201287-is-this-calculation-correct/#findComment-1056156 Share on other sites More sharing options...
roopurt18 Posted May 10, 2010 Share Posted May 10, 2010 A = ( 100D + 10E + F ) / ( 10B + C ) A = ( 100D + 10B + G ) / ( 10E + C ) ( 100D + 10E + F ) / ( 10B + C ) = ( 100D + 10B + G ) / ( 10E + C ) Once I made it that far I jumped to: E = B, F = G. But thinking about it now I guess that's not necessarily true. Quote Link to comment https://forums.phpfreaks.com/topic/201287-is-this-calculation-correct/#findComment-1056172 Share on other sites More sharing options...
Asheeown Posted May 11, 2010 Author Share Posted May 11, 2010 Are you sure there even is a solution? Yes, positive, I just didn't ask for it because I wanted to actually see if I could script something to figure this out. As long as my script is accurate in guessing possibilities then that is fine with me. Do you think I should use your form instead of grouping? A * (10*B + C) = (100*D + 10*E + F) = (10*H + K) * G A * (10*E + C) = (100*D + 10*B + G) = (10*A + K) * F Quote Link to comment https://forums.phpfreaks.com/topic/201287-is-this-calculation-correct/#findComment-1056184 Share on other sites More sharing options...
ignace Posted May 11, 2010 Share Posted May 11, 2010 Give this a try: You can trivially verify if a given solution is correct in constant time. You just need to generate all 9! = 362880 different permutations and check each one until you meet a correct solution. If you don't find any doing this, there exists no solution. Quote Link to comment https://forums.phpfreaks.com/topic/201287-is-this-calculation-correct/#findComment-1056291 Share on other sites More sharing options...
Daniel0 Posted May 11, 2010 Share Posted May 11, 2010 If I did this correctly, the following program proves that no such number sequence exists. #!/usr/bin/env python from itertools import permutations def check(l): return l[0] * (10*l[1] + l[2]) == (100*l[3] + 10*l[4] + l[5]) == (10*l[6] + l[7]) * l[8] and \ l[0] * (10*l[4] + l[2]) == (100*l[3] + 10*l[1] + l[8]) == (10*l[0] + l[7]) * l[5] print filter(check, permutations(range(1,10))) daniel@daniel-laptop:~$ time ./test.py [] real 0m0.290s user 0m0.260s sys 0m0.010s Quote Link to comment https://forums.phpfreaks.com/topic/201287-is-this-calculation-correct/#findComment-1056390 Share on other sites More sharing options...
Asheeown Posted May 11, 2010 Author Share Posted May 11, 2010 I'll see if I can grab the answer tomorrow. He said an answer does exist so I'm not sure. I rechecked the problem setup and I did not type anything incorrectly. Quote Link to comment https://forums.phpfreaks.com/topic/201287-is-this-calculation-correct/#findComment-1056677 Share on other sites More sharing options...
Asheeown Posted May 13, 2010 Author Share Posted May 13, 2010 Okay, so you guys were right. The equation I gave you has no solution. Problem is it isn't the real equation. While transcribing it to me, my friend mistyped one of the letters in the equation. Here are the actual two equations: A * (BC) = (DEF) = (HK) * G H * (EC) = (DBG) = (AK) * F I bolded the incorrect letter. This set of equations yield two answers: A = 3 B = 5 C = 8 D = 1 E = 7 F = 4 G = 6 H = 2 K = 9 AND A = 2 B = 7 C = 8 D = 1 E = 5 F = 6 G = 4 H = 3 K = 9 Sorry about the confusion guys. I knew something was wrong, the script averaged about 500 million attempts per 12 hours, and it was running for days without posting an answer. I found these new answers in less than 10 seconds a piece. Quote Link to comment https://forums.phpfreaks.com/topic/201287-is-this-calculation-correct/#findComment-1057824 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.