Abandoned an efficient Python solution of #66 for now.
Here's a quick solution to #67.