local function linear_combo(c) local sb = "" local i = 0 for c as n do if n != 0 then local op = (n < 0 and sb == "") ? "-" : (n < 0) ? " - " : (n > 0 and sb == "") ? "" : " + " local av = math.abs(n) local coeff = (av == 1) ? "" : $"{av}*" sb ..= $"{op}{coeff}e({i + 1})" end ++i end return (sb == "") ? "0" : sb end local combos = { {1, 2, 3}, {0, 1, 2, 3}, {1, 0, 3, 4}, {1, 2, 0}, {0, 0, 0}, {0}, {1, 1, 1}, {-1, -1, -1}, {-1, -2, 0, -3}, {-1} } for combos as c do print(string.format("%-13s -> %s", c:concat(", "), linear_combo(c))) end