3 ms·
Even if that's the problem they intended to solve, they're using an inefficient solution. (Could you point to where they say they intend to count the unique rea
by Strilanc 12y ago
Even if that's the problem they intended to solve, they're using an inefficient solution. (Could you point to where they say they intend to count the unique reachable forests? Their javascript code [1] does enumerate stable forests.)
If you want to enumerate stable forests, you only need to know the largest pure lion/goat/wolf forests. You get all the other stables one by repeatedly subtracting 2 from those. Takes linear time to yield everything, and constant space.
If you want to enumerate all reachable forests, stable or not, you just do a triple loop over how many times to apply each operation and yield the results. The results you get won't overlap because the operations are linearly independent. Takes cubic time to yield everything, but only constant space.
1: http://www.unisoftwareplus.com/download/blog/2014-06/magicForest.js http://www.unisoftwareplus.com/download/blog/2014-06/magicFo...