Introduction
So my boss is making me do some manual labor...urgh...I have to take a part out a box of parts, process it and put it back in the box. To make this more interesting I try to sort the parts as I do this, as each part has a unique alphanumeric serial number.
Unfortunately, I only have room to have four parts out the box at a time and I'm not taking each part out of the box more than once (that'd be even more work!) so my sorting capabilities are limited.
Challenge
Your challenge is to write a full program or function that rates my sorting of a given box of parts.
The Sorting Process
- Take 4 parts out of the box
- Take the part that comes first by serial number
- Process the part
- Put the part back in the box
- Take another part out of the box (if there are any left)
- Repeat steps 2-6 until all parts are processed (moved only once).
Input
A set of serial numbers in the format [A-Z][A-Z][0-9][0-9][0-9]
Input can be an array/list or deliminated string, python example...
['DT064', 'SW938', 'LB439', 'KG338', 'ZW753', 'FL170', 'QW374', 'GJ697', 'CX284', 'YW017']
Output:
The score of the sorted/processed box (see scoring below)
Scoring
For each part note how far away it is from where it would be in a perfectly sorted box. The score is the total of this value for all parts in the box.
Examples/Test cases
input ['AA111', 'AA222', 'AA333', 'AA444', 'AA000', 'AA555']
my sorted list ['AA111', 'AA000', 'AA222', 'AA333', 'AA444', 'AA555'] (no need to output)
perfect sort ['AA000', 'AA111', 'AA222', 'AA333', 'AA444', 'AA555'] (no need to output)
output 2 (because first two elements are out of sequence by 1 position each)
input ['GF836', 'DL482', 'XZ908', 'KG103', 'PY897', 'EY613', 'JX087', 'XA056', 'HR936', 'LK200']
my sorted list ['DL482', 'GF836', 'EY613', 'JX087', 'KG103', 'HR936', 'LK200', 'PY897', 'XA056', 'XZ908']
perfect sort ['DL482', 'EY613', 'GF836', 'HR936', 'JX087', 'KG103', 'LK200', 'PY897', 'XA056', 'XZ908']
output 6
input ['UL963', 'PJ134', 'AY976', 'RG701', 'AU214', 'HM923', 'TE820', 'RP893', 'CC037', 'VK701']
output 8
input ['DE578', 'BA476', 'TP241', 'RU293', 'NQ369', 'YE849', 'KS028', 'KX960', 'OU752', 'OQ570']
output 6
input ['BZ606', 'LJ644', 'VJ078', 'IK737', 'JR979', 'TY181', 'RJ990', 'ZQ302', 'AH702', 'EL539']
output 18
AA000
come afterAA111
? \$\endgroup\$2
? \$\endgroup\$AA000
didn't come out the box until the second iteration so the best position it could achieve is second in the sorted box. I've added a bit more explanation to the test case. \$\endgroup\$