What a tragedy. I remember Bob’s code that generates certain numbers: https://www.beust.com/weblog/coding-challenge/ . Bob’s code is in Java, yet uses clever backtracking techniques to achieve the best performance among many solutions in all kinds of languanges.
It seems to me like the trick would be to find a way to generate, in order, the numbers you can't print, then you just print the gaps between them.