What is the optimal Jewish toenail cutting algorithm?

前端 未结 6 1880
暖寄归人
暖寄归人 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:15

    There is a finite number of sequences that satisfy your requirements.

    1. Generate all permutations of {1,2,3,4,5}. There are only 120.
    2. Reject the ones that don't satisfy the requirements and store the remaining set (permanently).
    3. Randomly pick two different sequences. Remember which ones you used last time.

    EDIT: If this isn't really about toes, but about some random problem where the set can be much larger than 5, the sequence space becomes very large and the chance of repeating the same sequence on the second foot becomes very small. So randomly generating sequences and rejecting them if they match is a good idea. Generating random sequences according to some rule like "hop by twos or threes, then fill in the blanks" will probably be faster than generating random permutations and testing, and the chance of overlap will still be small if the number of "toes" is large.

提交回复
热议问题