This one I dreamt up when thinking about shuffling a sorted text file.
I haven't written any code yet, so it might be too easy or too hard or
too nonsense or too time-consuming (it took me a couple hours just
writing this up).
Let me know what you think.
-----------------------
Objective
-----------------------
An algorithm, implemented in C, that puts words from a unique sorted
list into a new order that maximizes the sum of the absolute shifts from
the original positions of the words.
---------------
Example N = 10 -------------------------------------------------------------------------
Initial Rand Abs Reverse Abs Rotate by 1
Words Address Algo Shift Sort Shift Pos Shift -------------------------------------------------------------------------
aaaaa 0 4 4 9 9 9 9
bbbbb 1 9 8 8 7 0 1
ccccc 2 3 1 7 5 1 1
ddddd 3 5 2 6 3 2 1
eeeee 4 7 3 5 1 3 1
fffff 5 0 5 4 1 4 1
ggggg 6 2 4 3 3 5 1
hhhhh 7 1 6 2 5 6 1
iiiii 8 6 2 1 7 7 1
jjjjj 9 8 1 0 9 8 1 -------------------------------------------------------------------------
Total 45 45 45 50 18 -------------------------------------------------------------------------
So:
1) a random shuffling gives total abs(shift) equal to the sum of 1..N-1.
2) Reversing the order gives a total abs(shift) of 50, which is
Sum(1..N-1) + (N/2)
3) "Rotate" means moving the positions up or down: last word become
the 1st word, 1st word becomes the 2nd word, 2nd word becomes the
3rd word, etc (or the other way).
Total
Rotate abs(shift)
1 18
2 32
3 42
4 48
5 50
6 48
7 42
8 32
9 18
So the formula for calculating the abs(shift) of a rotation value R is 2R(abs(N-R)) where R < N, and max abs(shift) occurs at N/2.
-----------------------
Max Score Available
-----------------------
Looks like Sum(1..N-1) + (N/2) is the max abs(shift) you can achieve if
all word positions are shifted by at least 1.
-----------------------
Challenge requirements
-----------------------
1) 0-based positioning
2) N = count of unique words
3) each 2 consecutive words from the original list must be separated by
at least N/50 places in the final shuffled list
4) each word must be moved at least N/10 places from its original
position
5) 1/2 the words must be moved up in position, and 1/2 must be moved
down in position (or rotated in either direction)
6) cannot use a random nbr generator or library in your code
7) 2 outputs, generated by your algorithm applied to the list below:
* the total abs(shift) of the shuffled word positions
* the Top 20 and Bottom 20 words after shuffling (and their original
positions)
Yes, requirements 3,4,5 are arbitrary, put in to make it more difficult
(I hope).
I debated putting this next statement in, since it will be obvious to
most, but assuming the input list is unique and sorted:
*** You don't need to sort any words. Ever. ***
You're free to do so, but it's not required to complete any part of the challenge.
If you read this far, can you think of any real-world usage for it?
Everyone's submission will be run against the same word list, which will
also be used to print your Top/Bottom 20. That 2600-word list (unique
and sorted) is:
https://filebin.net/t35q2wd67ovt97lj/2600words.txt
Enjoy!
--- PyGate Linux v1.5.13
* Origin: Dragon's Lair, PyGate NNTP<>Fido Gate (3:633/10)