took a while to understand what was being asked, but the solution came to me really easily... i wonder how hard it would be to do this without string processing