There may well be ways of refactoring the code for the case with three inputs. I will leave that as an exercise for the reader.
There may well be ways of refactoring the code for the case with three inputs. I will leave that as an exercise for the reader.