This is somewhat complex for me to put into words properly, so I\'ll just drop an example of what I\'m trying to do in terms of input and expected output below. I\'ve tried