Crashguard303 Lv 1
It's some time ago, when I programmed a sorting alogrithm only for a one-dimensional array, but for two, it's similar.
To get the 5 worst scores, at first you have to check ALL scores.
You have to create two 1-dimensional arrays which store ALL segment-numbers and scores.
For example, if the puzzle is 200 sgements, and we want to check the chlashing score per segment.
The array is index[1to200], score[1to200]
so, index[1]=1 and score[1]=get_segment_score_part("clashing",1),
index[2]=2 and score[2]=get_segment_score_part("clashing",2)
…
until index[200]=200 and score[200]=get_segment_score_part("clashing",200)
Then you have to run a loop from 200 to 2 backwards (let's call it k)
and IN this loop another loop, (let's call it l, running from k-1 to 1 backwards)
You have to check if score[l]>score[k]
IF so, swap score[k] with score[l] and index[k] with index[l]
QBASIC had a SWAP-function, we do this by:
temp=score[k] score[k]=score[l] score[l]=temp
temp=index[k] index[k]=index[l] index[l]=temp
to pull all worst scores AND their index-number upwards within the list.
This will give you a list with indexnumber and score, starting with index[1] and score[1] is worst and index[1] and score[1] is best.
So, fetching index[1to5] and score[1to5] will give you the 5 segment-numbers with the 5 worst scores.
I can write the algorithm this this week, but today I'm to exhausted from work, sorry :(
Btw I: To make a Best list, you ONLY have to change the condition 'score[l]>score[k]' to score[l]<score[k]!!!
Btw II: Where are the functions in the wiki gone?
regards,
Alex