- 01
- 02
- 03
- 04
- 05
- 06
- 07
- 08
- 09
- 10
- 11
- 12
- 13
- 14
- 15
- 16
- 17
- 18
- 19
- 20
- 21
- 22
- 23
- 24
- 25
F[numbers_, setNumber_, ParenNum_] :=
Block[{func = {"+", "-", "*", "/"}[[setNumber]],
parens = {{"", "", "", "", "", ""}, {"", "(", "", "", ")",
""}, {"", "", "", "(", "", ")"}, {"", "(", "", "", "",
")"}, {"(", "", ")", "(", "", ")"}}[[ParenNum]], e},
e = ToExpression[
ToString[
StringJoin[parens[[1]], ToString[numbers[[1]]], func[[1]],
parens[[2]], ToString[numbers[[2]]], parens[[3]], func[[2]],
parens[[4]], ToString[numbers[[3]]], parens[[5]], func[[3]],
ToString[numbers[[4]]], parens[[6]]]]]; e];Timing[c = 0; d = 0;
b = Permutations[{1, 2, 3, 4, 1, 2, 3, 4, 1, 2, 3, 4}, {3}];
For[n1 = 1, n1 < 10, n1++,
For[n2 = 1, n2 < n1, n2++,
For[n3 = 1, n3 < n2, n3++,
For[n4 = 1, n4 < n3, n4++,
a = Permutations[{n1, n2, n3, n4}, {4}]; sol = {};
For[i = 1, i <= Length[a], i++,
For[j = 1, j <= 64, j++,
For[n = 1, n <= 5, n++, g = F[a[[i]], b[[j]], n];
If[IntegerQ[g] && g > 0, AppendTo[sol, g]]]];
m = Sort[DeleteDuplicates[sol]];
l = Complement[Range[1000], m][[1]];
If[l > c, c = l; d = {n1, n2, n3, n4}]]]]]];
FromDigits[Reverse[d]]]