Rewrote algorithm for Number12