tested brute force subroutine
added some code for misc. hard cases