"Avoiding a configuration like 1,1,1" isn't enabled by backtracking. Rather, it's a constraint placed on the search space (domain), for which, the generator wont need generating solutions that needlessly gets tested.
Your son would probably really enjoy Prolog (and Logic Programming in general) where these concepts are much more developed.
Check out the channel "The Power of Prolog" on YouTube to get your mind blown: https://www.youtube.com/channel/UCFFeNyzCEQDS4KCecugmotg/vid...