Тут товарищ рекурсия нужна
CIRCLES = [
[7, 2, 3, 5, 16, 50, 25, 40],
[2, 5, 10, 30, 25, 3, 10, 25],
[25, 10, 2, 10, 5, 2, 10, 5],
[7, 2, 3, 20, 3, 7, 2, 5],
[2, 20, 1, 7, 25, 1, 25],
[3]
]
condidats = [0,0,0,0,0,0]
R = [];
function get_sum(s, ind){
if (ind >= CIRCLES.length) {
if (s == 136) {
alert(condidats)
}
}
else {
for (let i in CIRCLES[ind] ){
item = CIRCLES[ind][i];
condidats[ind] = item;
get_sum(s+item, ind+1);
}
}
}
get_sum(0, 0)
думаю псевдокод понятен
упд: исправил
вот и js говнокод
https://jsfiddle.net/m1nsra5d/4/