> But this solution is not finding

Yes, much-too-clever version 1 doesn't scale. Anyway, I still suspect
though you could use some interesting shortcuts.