Solved

Takes forever though. There must be a better implementation