I have this code for sorting only those tuples that sum to 15 without repetition:
n = 15;s=11; m = 3;
ip = IntegerPartitions[n, {m}];
v = Pick[ip, Max@# < s & /@ ip];
DeleteCases[v, x_ /; x[[1]] == x[[2]] || x[[2]] == x[[3]]]
Output:
{{9, 5, 1}, {9, 4, 2}, {8, 6, 1}, {8, 5, 2}, {8, 4, 3}, {7, 6, 2}, {7, 5, 3}, {6, 5, 4}}
but with:
n = 45;s = 15;m = 8;
ip = IntegerPartitions[n, {m}];
v = Pick[ip, Max@# < s & /@ ip];
DeleteCases[v, x_ /; x[[1]] == x[[2]] || x[[2]] == x[[3]] || x[[3]] == x[[4]] ||
x[[4]] == x[[5]] || x[[5]] == x[[6]] || x[[6]] == x[[7]] ||x[[7]] == x[[8]]]
Pattern in DeleteCases[]
is too long. How to write code in a simpler and more elegant way?
Select[ip, Max @@ # < s && Length@DeleteDuplicates@# == m &]
$\endgroup$