The solution is short as it leverages three utility classes, hash for speedy sets, parse for extracting integers from surrounding text and point for two dimensional rotations and translations.
hash
parse
point