I\'m trying to write a function that solves the below problem. I tried solving it by mapping dataframes but this seems like a much better solution, I just can\'t get the syn