I am currently preparing this exercise for wasm; I wondered if I should include the error handling (minFactor > maxFactor) and how the return value should look like then (e.g. -1 product or negative factors offset).
If we are returning a product and an offset/length, we could return -1 as the “product”. The example solution could return 0 as offset/length. For this exercise, Rust treats no result and error the same way:
Also possible would be using -1 and -2 to distinguish the situations.
WASM all-your-base uses a separate status-code result, this would be yet another option.
1 Like
I dislike having an additional status code when there are already three then unused values. Also, an empty list of factors already shows there is no product.
So after a bit of deliberation, I prefer
- value: positive number, factors offset, factors length > 0: normal solution
- value: zero, factors offset irrelevant, length 0: no palindrome product found
- value: -1, factors offset irrelevant, length 0: min > max
Obviously, this should be documented in instructions.append.md.
2 Likes