PROJECT EULER · #0523
First Sort I
Consider the following algorithm for sorting a list:
- 1. Starting from the beginning of the list, check each pair of adjacent elements in turn.
- 2. If the elements are out of order:
- a. Move the smallest element of the pair at the beginning of the list.
- b. Restart the process from step 1.
- 3. If all pairs are in order, stop.
For example, the list
( and are out of order so move to the front of the list) ( and are out of order so move to the front of the list) ( and are out of order so move to the front of the list) ( and are out of order so move to the front of the list) ( and are out of order so move to the front of the list) (The list is now sorted)
Let
Let
You are given
Find
Write-up coming later
The complete problem is available here. An approach, code, and answer will be added later.