2
$\begingroup$

I enconter a problem about number:

If we have

5+3+2=151022

9+2+4=183652

8+6+3=482466

5+4+5=202541

then 7+2+5=?

It is easy to get the first two group of numbers? for the last, it is not so easy to observe, what's more, it is even harder to show that the answer is uniqe in some sense.

So I just work it out with mma:

var = {x, y, z};
biop[x_, y_] := {x + y, x - y, x*y}
lis[0] = var;
op[0] = var;
lis[n_] := 
 Union[Subsets[op[n - 1], {2}], 
  First[Table[{i, j}, {i, var}, {j, op[n - 1]}]]]
op[n_] := 
 Union[Flatten[
   Table[ExpandAll[biop[#1, #2]] & @@ elem, {elem, lis[n]}]]]
f[a_, b_, c_] := # /. {x -> a, y -> b, z -> c} &
Reap[Map[If[
     f[5, 3, 2][#] == 22 && f[9, 2, 4][#] == 52 && 
      f[8, 6, 3][#] == 66 && f[5, 4, 5][#] == 41, Sow[#]] &, 
   op[3]]][[-1, 1]]

Let me explain the code a litter. Firstly we define three variables and a function f, which represent 5+3+2=22 as x+y+z=f[5,3,2]=22. Then we construct all the bineary-operator I need as in biop (I didn't consider x/y). Next, we encounter the situation of construcing all possiable ways of combine x,y,z with the bineary operator.

To do this, I first define a function lis[n], which will give all the pairs of elements, that will be applied to the biop, here n represens the number of biop. In case the list is constructed, the possiable expression which contain n biop is easy to get by apply biop to op[n-1].

The last reap function is to output all the expression that satisfies the condition of the question. In fact, I just copy it from the older post here.

Now, my problem is that, when I try to get all the possibility 4 combination of biop satisfies the condition, mma tell me that The current computation was aborted because there was insufficient memory available to complete the computation. But my ram is only used 50% of 2G.

I think we can work this without list all the possibal combination, and verify it as soon as I get the expression of biop. But How?

$\endgroup$
5
  • 1
    $\begingroup$ Let me explain the code a litter sounds like a confession:) $\endgroup$ Nov 26, 2014 at 16:45
  • 2
    $\begingroup$ 7+2+5=143547 (mah brain faster than mma) $\endgroup$
    – wolfies
    Nov 26, 2014 at 17:58
  • $\begingroup$ @belisarius your mean my grammar is wrong? $\endgroup$
    – van abel
    Nov 27, 2014 at 1:41
  • 1
    $\begingroup$ en.wikipedia.org/wiki/Litter $\endgroup$ Nov 27, 2014 at 1:56
  • $\begingroup$ hah, I see. It should be a little. $\endgroup$
    – van abel
    Nov 28, 2014 at 2:47

0

Browse other questions tagged or ask your own question.