neat challenge. beyond my abilities to solve generally in code, but a fun little task to solve manually.