Fix difference of squares example

Removes recursion and uses reduce-based solution. Fixes based on comment in #1056