Eating Lions, Wolves, and Goats Faster
strilanc.com
Eating Lions, Wolves, and Goats Faster
1–10 of 10 posts
Re: Eating Lions, Wolves, and Goats Faster
#2Then have all the wolves eat goats until only one of the species is left, say 2k wolves. Then do k iterations of lion eat wolf and wolf eat goat.
Re: Eating Lions, Wolves, and Goats Faster
#3Or you could do it even faster by solving it directly. First note that all the parities change together, so pick the two smallest groups with the same parity, say wolves and goats. These will be the species to try to eliminate. Then have all the wolves eat goats until only one of the species is left, say 2k wolves. Then do k iterations of lion eat wolf and wolf eat goat.
Re: Eating Lions, Wolves, and Goats Faster
#4As to the problem, the second I started reading I knew it would be an operations research problem. Though, to be honest I thought there would be a closed form solution
Re: Eating Lions, Wolves, and Goats Faster
#5Re: Eating Lions, Wolves, and Goats Faster
#6Re: Eating Lions, Wolves, and Goats Faster
#7I believe finding the single optimal solution wasn't the point - as others have pointed out ( for a very good solution, see: https://news.ycombinator.com/item?id=7856275 ), one can find that by hand - you don't need to write any code for that. The OP tried to exhaustively enumerate all possible unique forests (he considered a forest unique if the (lion,wolf,goat) triple was unique ). That obviously means some data st…
Rewriting the solution to use a single long smashes the C++ too but yet again, it feels horrid when the real solution is O(1)...
Re: Eating Lions, Wolves, and Goats Faster
#8I believe finding the single optimal solution wasn't the point - as others have pointed out ( for a very good solution, see: https://news.ycombinator.com/item?id=7856275 ), one can find that by hand - you don't need to write any code for that. The OP tried to exhaustively enumerate all possible unique forests (he considered a forest unique if the (lion,wolf,goat) triple was unique ). That obviously means some data st…
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/magicFo...
Re: Eating Lions, Wolves, and Goats Faster
#9This was surprising to see here. unRisk is a hugely technical company, doing quant finance with Mathematica. Not the type of thing you normally find here. As to the problem, the second I started reading I knew it would be an operations research problem. Though, to be honest I thought there would be a closed form solution