(05-13-2014 08:20 PM)Jeff_Kearns Wrote: I finally got around to entering Valentin Albillo's 160 line program to solve Karl Schneider's A modest arithmetical challenge, posted in April 2007. A worthwhile thread to re-read.
For some reasons this little problem kept my attention and sorry if I'm a bit off topic now. I suspected there were more solutions than those listed and checked that with a quick and dirty C++ app. Here are my findings.
There are 3 patterns of digits to consider:
P1: d/dd + d/dd + d/dd
P2: dd/dd + d/dd + d/d
P3: dd/ddd + d/d + d/d
P3 doesn't seem to produce results.
Code:
P2 - 1 : 12/48 + 7/36 + 5/9
P2 - 1 : 12/84 + 5/63 + 7/9
P2 - 1 : 12/84 + 9/63 + 5/7
P2 - 1 : 13/52 + 7/84 + 6/9
P2 - 1 : 14/56 + 9/28 + 3/7
P2 - 1 : 16/48 + 3/27 + 5/9
P2 - 1 : 19/72 + 4/36 + 5/8
P2 - 1 : 19/76 + 3/24 + 5/8
P2 - 1 : 19/76 + 4/32 + 5/8
P2 - 1 : 21/49 + 8/56 + 3/7
P2 - 1 : 21/84 + 7/36 + 5/9
P2 - 1 : 27/81 + 4/36 + 5/9
P2 - 1 : 27/81 + 9/54 + 3/6
P2 - 1 : 29/38 + 4/57 + 1/6
P2 - 1 : 37/56 + 9/42 + 1/8
P2 - 1 : 39/52 + 7/84 + 1/6
P2 - 1 : 39/54 + 8/72 + 1/6
P2 - 1 : 45/72 + 9/36 + 1/8
P2 - 1 : 45/76 + 3/19 + 2/8
P1 - 1 : 5/34 + 7/68 + 9/12
P1 - 1 : 5/34 + 9/12 + 7/68
P2 - 1 : 54/81 + 7/63 + 2/9
P1 - 1 : 7/68 + 5/34 + 9/12
P1 - 1 : 7/68 + 9/12 + 5/34
P1 - 1 : 9/12 + 5/34 + 7/68
P1 - 1 : 9/12 + 7/68 + 5/34
And some C++ snippets for those interested in gory details (using Qt cuz it is so simple but STL on its own would totally do here).
Code:
#include <QDebug>
#include <algorithm>
#include <math.h>
#define ARGS \
arg(digits.at(0)).arg(digits.at(1)) \
.arg(digits.at(2)).arg(digits.at(3)) \
.arg(digits.at(4)).arg(digits.at(5)) \
.arg(digits.at(6)).arg(digits.at(7)) \
.arg(digits.at(8))
/*
somewhere in a function
*/
// List of all the digits
QList<int> digits;
// Builds the list
for (int i=1; i<10; i++) digits << i;
do {
double v;
// Pattern 1 (3x3x3)
v = 0;
for (int i=0; i<9; i+=3) v += digits.at(i)/(digits.at(i+1)*10.+digits.at(i+2));
if (fabs(1-v)<1e-5) qDebug() << QString("P1 - %10 : %1/%2%3 + %4/%5%6 + %7/%8%9").ARGS.arg(v);
// Pattern 2 (4 3 2)
v = (digits.at(0)*10.+digits.at(1))/(digits.at(2)*10.+digits.at(3));
v += digits.at(4)/(digits.at(5)*10.+digits.at(6));
v += double(digits.at(7))/digits.at(8);
if (fabs(1-v)<1e-5) qDebug() << QString("P2 - %10 : %1%2/%3%4 + %5/%6%7 + %8/%9").ARGS.arg(v);
// Pattern 3 (5 2 2)
v = digits.at(0)*10.+digits.at(1)/(digits.at(2)*100.+digits.at(3)*10.+digits.at(4));
v += double(digits.at(5))/digits.at(6);
v += double(digits.at(7))/digits.at(8);
if (fabs(1-v)<1e-5) qDebug() << QString("P3 - %10 : %1%2/%3%4%5 + %6/%7 + %8/%9").ARGS.arg(v);
} while (std::next_permutation(digits.begin(), digits.end()));