Numba/numpy based solution just about working. Somehow not applying the constraint on resting at the moment.