n = <input type="number" oninput="R.textContent=f(this.value)" /><pre id="R"></pre>
Recursive function. This generates all possible permutations of
1s separated by either
- or nothing. It does this by incrementing a base-3 number, turning it into an array of digits, converting each digit
2 to an empty string, then joining them together with
1s. The resulting string is
Because the operators are joined with
1s in between (like
+1+1+1+), there are
length - 1
1s. The first operator is ignored (because
1 and it's a number so there will never be a leading
-) and the final operator is also ignored (by appending
.0 to the equation).
Higher Output Version, 96 bytes
The other version can't return outputs higher than ~10 because of the recursion call stack limit. This version uses a for loop instead of recursion, so it can return outputs up to ~33. The amount of time required increases exponentially though so I don't recommend testing it.