LogoWCF

Day 22: Present Preparation

It’s almost Christmas!!! Final preparations are underway for the big day! One of the slowdowns has been the need to get presents ordered after creation so that they are packed in the correct spot.

Presents are completed in batches and deposited to a central location before being sent along to be loaded into the correct bags. We only have the elf-power to have one elf putting these packages in order (there are several batch-sorting areas, but only one elf actual doing the sorting in each area). Another problem is that some of the presents are very large, so an elf can only move one at a time and drop it at the present he is going to pick up. Essentially “Swapping” those presents.

Problem: A text file presents.txt contains one batch of presents per line. Figure out what the least number of “Swaps” the elf can do to get these presents in order for each batch.

Example:

Input:

5 2 12 3
7 4 9 10

Output:

3
1

Challenge:

Include the mapping of necessary swaps.

Example Challenge output:
3 (5:2,12:3,5:3)
1 (7:4)

Solutions