Jump to content

Recommended Posts

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";
////////////////////////////////////////////////
?>

Link to comment
https://forums.phpfreaks.com/topic/201287-is-this-calculation-correct/
Share on other sites

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.

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.

(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

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.

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

 

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.

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

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.

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.