How can I pair socks from a pile efficiently?

后端 未结 30 1178
旧巷少年郎
旧巷少年郎 2020-11-27 08:37

Yesterday I was pairing the socks from the clean laundry and figured out the way I was doing it is not very efficient. I was doing a naive search — picking one sock and

30条回答
  •  情书的邮戳
    2020-11-27 09:17

    As the architecture of the human brain is completely different than a modern CPU, this question makes no practical sense.

    Humans can win over CPU algorithms using the fact that "finding a matching pair" can be one operation for a set that isn't too big.

    My algorithm:

    spread_all_socks_on_flat_surface();
    while (socks_left_on_a_surface()) {
         // Thanks to human visual SIMD, this is one, quick operation.
         pair = notice_any_matching_pair();
         remove_socks_pair_from_surface(pair);
    }
    

    At least this is what I am using in real life, and I find it very efficient. The downside is it requires a flat surface, but it's usually abundant.

提交回复
热议问题