Pairing up Socks

On a nice day, Babai, a computer scientist, received back all 6 pairs of my blue\color{#3D99F6}{blue} and red\color{#D61F06}{red} socks in a laundry basket. He needed to pair them up into pairs of same color for me.

Being a computer scientist, he wondered what would be a good way to sort them out. Can you help him by figuring out the faster way to sort these?

Swap and Go:

  1. Lay the socks on the table side by side.
  2. While there are some blue\color{#3D99F6}{blue} socks in the last 6 socks, do the following:
    • Going from left to right, if there is a red\color{#D61F06}{red} sock to the right of a blue\color{#3D99F6}{blue} sock, exchange them.
  3. Now, all 6 pairs of adjacent socks are each of the same color. So, take two at a time and pair them up.

Throw into Buckets:

  1. Lay the socks on the table side by side. Take two buckets, red\color{#D61F06}{red} and blue\color{#3D99F6}{blue}.
  2. For all the socks on the table, check which of them are red\color{#D61F06}{red}, one by one:
    • if a sock is red\color{#D61F06}{red}, put it in the red\color{#D61F06}{red} bucket;
    • if a sock is blue\color{#3D99F6}{blue}, put it in the blue\color{#3D99F6}{blue} bucket.
  3. Now, we know that all the red\color{#D61F06}{red} and blue\color{#3D99F6}{blue} socks are each in the bucket of the same color. Taking two of them at a time from the same bucket, pair them up.

Problem Loading...

Note Loading...

Set Loading...