0
$\begingroup$

I have tried to solve this system for numbers that go from 1 to 10 non-repeated integers, this occurs to me

 FindInstance[
 a + b == c + d + e + f == g + h == i + j == a + c + g + i == 
 b + f + h + i && a > 0 && b > 0 && c > 0 && d > e > 0 && f > 0 && 
 g > 0  && h > 0 && i > 0 && j > 0, {a, b, c, d, e, f, g, h, i, j}]

but I get nothing. One of the main aspects is how to indicate that the variables must be different (from 1 to 10 it is simple, but from 1 to 100 I cannot imagine) thanks for any help

Edit (Bill's suggestion) I have reformulated the problem and it works well, I just need to know which of all those results give me the maximum sum

 **Needs["Combinatorica`"]; p = 
 Range[10]; Do[{a, b, c, d, e, f, g, h, i, j} = 
 p = NextPermutation[p]; 
 If[a + b +  c + d == b + e + f + h == g + h + i + j, Print[p]], {10!}]**
$\endgroup$
  • $\begingroup$ ... b > 0 c > 0...? $\endgroup$ – ciao Jun 6 at 18:08
  • $\begingroup$ b > 0 c > 0 makes the expression False. Presumably, you mean b > 0 && c > 0 . However, the result is then { } which indicates that there is no valid solution. $\endgroup$ – Bob Hanlon Jun 6 at 18:13
  • $\begingroup$ Try Needs["Combinatorica`"]; p=Range[10]; Do[ {a,b,c,d,e,f,g,h,i,j}=p= NextPermutation[p]; If[a+b==c+d+e+f==g+h,Print[p]], {10!}] and ignore the caution about Combinatorica loading. After looking at that result insert the extra ==i+j condition and try it again. This avoids wondering whether FindInstance just didn't try hard enough and avoids 0<a<11&&0<b<11&&... (IF you have enough memory you can modify this to generate all the permutations first, but you will never be able to buy enough memory to hold 100! permutations while you can just wait longer for NextPermutation to find one) $\endgroup$ – Bill Jun 6 at 19:18
  • $\begingroup$ @Bill , Thanks, see my edition please $\endgroup$ – BeTDa Jun 6 at 21:28
  • $\begingroup$ @Bob Hanlon , thanks for your indication $\endgroup$ – BeTDa Jun 6 at 21:31
1
$\begingroup$
Clear["Global`*"]

Needs["Combinatorica`"];

p = Range[10];

sol = {};

Do[{a, b, c, d, e, f, g, h, i, j} = p = NextPermutation[p];
 If[a + b + c + d == b + e + f + h == g + h + i + j, 
  sol = Append[sol, p]], {10!}]

The number of solutions is

Length@sol

(* 7200 *)

The greatest sum is

max = Max[Total /@ sol[[All, 1 ;; 4]]]

(* 24 *)

The solutions with the greatest sum are

sol2 = Select[sol, Total[#[[1 ;; 4]]] == max &];

The number of these solutions is

Length@sol2

(* 1152 *)

Verifying the solutions,

And @@ (
  Total[#[[1 ;; 4]]] == Total[#[[{2, 5, 6, 8}]]] ==
     Total[#[[7 ;; 10]]] == max & /@ sol2)

(* True *)
| improve this answer | |
$\endgroup$
  • 1
    $\begingroup$ thanks for your time $\endgroup$ – BeTDa Jun 8 at 20:36
  • $\begingroup$ but as you can see the list of the numbers that meet this sum $\endgroup$ – BeTDa Jun 8 at 21:07

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.