Another math problem...

Q

qwweeeit

Another math problem easier to solve by hand, but, IMHO, difficult to
program in a concise way like the solution of Bill Mill
(linalg_brute.py) to the problem of engsol.

I appreciated very much the Bill Mill's solution and that inspired in
a certain way the solution for my problem.

# Problem and solution:

# ab * cb = dab 35 * 26 = 936
# + + - + + -
# ifd + chg = eaf 179 + 258 = 437
# --------------- ---------------
# cih + cge = edd 215 + 284 = 499

From that you can get 6 equations:

# equation n. 1 : (10a+b) * ( 10c+b) = 100d+10a+b
# equation n. 2 : 100i+ f d + 100c+ h g = e+ a f
# equation n. 3 : c+ i h + c g e = e d d
# equation n. 4 : ( a b) + i f d = c i h
# equation n. 5 : ( c b) + c h g = c g e
# equation n. 6 : d+ a b - e a f = e d d

(I removed most of digit part to enhance the variables).

My solution:

def Hund(w): # hundreths
.. return int(w/100)
def Ten2(w): # tenths for 2 digits
.. return int(w/10)
def Ten(w): # tenths for 3 digits
.. return int((w%100)/10)
def Unit(w): # units
.. return w%10

nc = range(100,1000) # range of 3 digits numbers
nd = range(10,100) # range of 2 digits numbers

def eq_1():
.. return [(x,y,z) for x in nd \
.. for y in nd \
.. for z in nc \
.. if x*y-z == 0 \
.. and Unit(x) == Unit(y) \
.. and Unit(x) == Unit(z) \
.. and Ten2(x) == Ten(z) \
.. and Ten2(x) != Ten2(y) ]

lResult1=eq_1()
print lResult1

From the results you can choose other equations to treat with the same
approach.

I know it's a rather long process.. but that is the best I can do.
 
Q

qwweeeit

Sorry, in writing down the problem and the corresponding solution, I
made a mistake. It's evident, but anyway...

Wrong:
# ab * cb = dab 35 * 26 = 936
# + + - + + -
# ifd + chg = eaf 179 + 258 = 437
# --------------- ---------------
# cih + cge = edd 215 + 284 = 499


Correct:
# ab * cb = dab 36 * 26 = 936
# + + - + + -
# ifd + chg = eaf 179 + 258 = 437
# --------------- ---------------
# cih + cge = edd 215 + 284 = 499

(wrong 35 correct 36)

Bye.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Similar Threads


Members online

No members online now.

Forum statistics

Threads
473,774
Messages
2,569,598
Members
45,149
Latest member
Vinay Kumar Nevatia0
Top