Solved 163 (with probably the ugliest code I've ever written)
Refactored problem 163