Post by bluatigro on Aug 21, 2018 11:37:58 GMT
trying to solve a char calc puzle
this is brute force
that is verry slow
who find the solution the fastest way ?
[/p][p]''gakb - aafj = dgfj
'' + + +
'' jgf - cc = jje
''gfkj - afag = bjhd
for a = 0 to 9
for b = 1 to 9
for c = 1 to 9
for d = 1 to 9
for e = 0 to 9
for f = 0 to 9
for g = 1 to 9
for h = 0 to 9
for j = 1 to 9
for k = 0 to 9
fl = 1
if q( g , a , k , b ) - q( a , a , f , j ) <> q( d , g , f , j ) then fl = 0
if q( 0 , j , g , f ) - q( 0 , 0 , c , c ) <> q( 0 , j , j , e ) then fl = 0
if q( g , f , k , j ) - q( a , f , a , g ) <> q( b , j , h , d ) then fl = 0
if q( q , a , k , b ) + q( 0 , j , g , f ) <> q( g , f , k , j ) then fl = 0
if q( a , a , f , j ) + q( 0 , 0 , c , c ) <> q( a , f , a , g ) then fl = 0
if q( d , g , f , j ) + q( 0 , j , j , e ) <> q( b , j , h , d ) then fl = 0
if a = b or a = c or a = d or a = e or a = f or a = g or a = h or a = k or a = k then fl = 0
if b = c or b = d or b = e or b = f or b = g or b = h or b = j or b = k then fl = 0
if c = d or c = e or c = f or c = g or c = h or c = j or c = k then fl = 0
if d = e or d = f or d = g or d = h or d = j or d = k then fl = 0
if e = f or e = g or e = h or e = j or e = k then fl = 0
if f = g or f = h or f = j or f = k then fl = 0
if g = h or g = j or g = k then fl = 0
if h = j or h = k then fl = 0
if j = k then fl = 0
if fl then
print q( g , a , k , b ) ; " -" , q( a , a , f , j ) ; " =" , q( d , g , f , j )
print "+" , "+" , "+"
print q( 0 , j , g , f ) ; " -" , q( 0 , 0 , c , c ) ; " =" , q( 0 , j , j , e )
print "--------------------------------------------------------------"
print q( g , f , k , j ) ; " -" , q( a , f , a , g ) ; " =" , q( b , j , h , d )
end if
next k
next j
next h
next g
next f
next e
next d
next c
next b
next a
end
function q( q1 , q2 , q3 , q4 )
q = q1 * 1000 + q2 * 100 + q3 * 10 + q4
end function
[/p][p]