Solution to Nick's Mathematical Puzzle 3. Two Logicians
The puzzle itself is on Nick's website.
I spend the whole night working on the solution. It is in form of a Python code. I must now sleep.
# See http://www.qbyte.org/puzzles/puzzle01.html 3. Two Logicians solutions = [] for x in range(2, 50): # Generate the number matrix, list of tuplets for y in range (x+1, 100-x): solutions.append((x, y, x+y, x*y)) all_numbers = solutions print print "There are %4d possible combinations." % len(solutions) # Extract sums (x+y) and products (xy) from the tuples sums, products = [], [] for i in solutions: sums.append(i[2]) products.append(i[3]) m_uniques, m_duplicates = [], [] a_uniques, a_duplicates = [], [] for i in solutions: # Eval tuples where the products are unique in regard to x and y. if sums.count(i[2]) > 1: a_duplicates.append(i) else: a_uniques.append(i) # Eval tuples with respect to sums if products.count(i[3]) > 1 : m_duplicates.append(i) else: m_uniques.append(i) print " %4d unique products (xy)." % len(m_uniques) print " %4d duplicate products. Two or more tuples " % \ len(m_duplicates) + "have the same products." print " %4d unique sums (x+y)." % len(a_uniques) print " %4d duplicate sums. Two or more tuples have " % \ len(a_duplicates) + "the same sums." # 1. The solutions do not contain m_uniques. P does not know the # combination, because of duplicity. solutions = set(solutions) - set(m_uniques) # equals m_duplicates print "1. Removal of m_uniques: %d" % len(solutions) # 2. S does not have a sum where the same sum occurs in a m_unique. # Otherwise S would be unsure, whether P knows the solution. sums_m_unique = set() for i in m_uniques: sums_m_unique.add(i[2]) for i in solutions.copy(): if i[2] in sums_m_unique: solutions.remove(i) # Only solutions are left, that are m_duplicates, and all sums occur # only in duplicates. print "2. Removes tuples with sums that occur in m_uniques: %d" % \ len(solutions) table = list() for i in solutions: table.append((i[2], i[0], i[1], i[3])) # 3. P can determine the tuple, that means it is m_unique in the # reduced solution set. # Extract products (xy) from the tuples of the reduced solution set products = [] for i in solutions: products.append(i[3]) for i in solutions.copy(): # Eval tuples with unique products (xy) if products.count(i[3]) > 1: solutions.remove(i) print "3. Eval m_uniques in the reduced solution set: %d" % \ len(solutions) # 4. S can determin the tuple, meaning the set must be a_unique # Extract sums (x+y) from the tuples of the reduced solution set sums = [] for i in solutions: sums.append(i[2]) for i in solutions.copy(): # Eval tuples with unique sums (x+y) if sums.count(i[2]) > 1: solutions.remove(i) print "4. Eval a_uniques in the reduced solution set: %d" % \ len(solutions) print " x y : x+y xy" for i in sorted(solutions): print "%2d %2d : %3d %4d" % i """ print "x+y: x y | xy > tuples containing xy" for i in sorted(table): tuples = list() for j in all_numbers: if i[3] == j[3]: tuples.append(j) print "%3d: %2d %2d | %4d > " % i + str(tuples) """ """ for i in all_numbers: if i[3] == 18 or i[2] == 9 or i[2] == 11 : print str(i) + " >" , if i in m_uniques: print " m_unique ", if i in a_uniques: print " a_unique ", print """




