this was a fun one. my solution isn’t very optimized but oh well. maybe i’ll find a better one.