Not a generic solution of course, but seems extremely effective for the Bacon case.
TIL that the 'WITH' clause in SQLite can draw the classic Mandelbrot Set:
https://www.sqlite.org/lang_with.html#outlandish_recursive_q...
(And there is a Sudoku puzzle solver below that.)
Mathematicians Daniel kleitman and Bruce Reznik both tie for top spot with a number of 3 (Erdos 1s and Bacon 2s). Danica McKellar and Elon both in there with 6s. And Mayim Bialik, Natalie Portman, and Kristen Stewart all up there with 7s.
https://en.wikipedia.org/wiki/Erd%C5%91s%E2%80%93Bacon_numbe...
I have an Erdos-Bacon number of six (having written a paper with Shing-Tung Yau and appeared in the film Windrider with Nicole Kidman).
https://profiles.imperial.ac.uk/j.gauntlett