What is the optimal Jewish toenail cutting algorithm?

前端 未结 6 1885
暖寄归人
暖寄归人 2020-12-22 18:52

I am working on the software for a machine that will automatically trim toenails, so that users can simply put their feet in it and run it instead of having to manually do i

6条回答
  •  无人及你
    2020-12-22 19:19

    The obvious: Find one order that works, and hard code it. But I don't think you want to do that.

    You can generate permutations much better than the way you are doing it. You don't need to do rejection sampling. Use a Fisher Yates shuffle on an initially sorted permutation (1, 2, .. 5), and you'll have a random permutation. http://en.wikipedia.org/wiki/Fisher%E2%80%93Yates_shuffle

    But in general, the generate and test method seems totally fine to me, so long as the probability of generating a successful entry is high enough. I am sure there any many valid sequences according to your criteria, once you switch to a random permutation, I doubt you'll have to do many rejection iterations.

提交回复
热议问题