objective 是为了防止subject/user 记忆学习,你明白那是什么吗?
The objective is to prevent subject/user learning from memory, do you understand what that is?
附件是开发的合并排序代码,它能够对给定数组进行的比较进行计数并打印出每个比较。我希望它能够有效地防止用户学习,以便比较的数字间隔足够大,这样人们就不会记得也看到了过去的数字。现在我们需要让它以不同的顺序进行这些比较。代码可能不再漂亮和递归,而是一些巨大的丑陋循环,我预计。
public class MyMergeSort {
private int[] array; //array declared
private int[] tempMergArr; //temporary array
private int length; //counting length of array
private int ncompare=0;
public static void main(String a[]){
int[] inputArr = {9, 2, 56, 5, 4, 6, 60, 8, 1, //the array, given 60
32, 21, 12, 42, 57, 15, 16, 50, 18, 19,
20, 11, 34, 23, 48, 25, 26, 27, 51, 29,
30, 31, 10, 33, 22, 35, 39, 37, 38, 36,
40, 41, 13, 43, 44, 53, 46, 47, 24, 49,
17, 28, 52, 45, 54, 55, 3, 14, 58, 59,
7};
MyMergeSort mms = new MyMergeSort(); //declaring the merge sort for the array
mms.sort(inputArr);
System.out.print("\n\n");
for(int i:inputArr){
System.out.print(i);
System.out.print(" ");
}
System.out.print("\n Number of comparisons "+mms.ncompare+"\n");
}
public void sort(int inputArr[]) { //sort method uses 'this' for array input
this.array = inputArr;
this.length = inputArr.length;
this.tempMergArr = new int[length];
doMergeSort(0, length - 1);
}
private void doMergeSort(int lowerIndex, int higherIndex) { //indexed method for merge sort, states each step and case
if (lowerIndex < higherIndex) {
int middle = lowerIndex + (higherIndex - lowerIndex) / 2;
// Below step sorts the left side of the array
doMergeSort(lowerIndex, middle);
// Below step sorts the right side of the array
doMergeSort(middle + 1, higherIndex);
// Now merge both sides
mergeParts(lowerIndex, middle, higherIndex);
}
}
private void mergeParts(int lowerIndex, int middle, int higherIndex) { //merge method using 'for' case,
for (int i = lowerIndex; i <= higherIndex; i++) {
tempMergArr[i] = array[i];
}
int i = lowerIndex; //declaring index variables for different cases
int j = middle + 1;
int k = lowerIndex;
while (i <= middle && j <= higherIndex) { //define loops for steps of different cases
System.out.print(" C "+i+" "+j);
ncompare=ncompare+1;
if (tempMergArr[i] <= tempMergArr[j]) {
array[k] = tempMergArr[i];
i++;
} else {
array[k] = tempMergArr[j];
j++;
}
k++;
}
while (i <= middle) {
array[k] = tempMergArr[i];
k++;
i++;
}
}
C 0 1
C 2 3
C 0 2
C 1 2
C 1 3
这些是我现有算法中进行的前五次比较。我想阻止它比较 0 和 2,然后比较 1 和 2,因为用户可能会记住 2,就像比较 1 和 2,然后比较 1 和 3 时,用户会记住 1。
我想尽量让比较的数字不那么容易被用户记住,以免他们做出有偏见的比较
比较顺序由合并排序算法定义。如果您以不可预测的或 "not memorable" 顺序比较索引,则您不再进行合并排序。您实际上必须发明一种新的排序算法才能获得这种行为。
但是,您可以在正常进行比较后打印 以随机顺序进行比较。只需将它们存储在列表字段中,然后在排序后打乱并打印它们。例如:
public List<int[]> comparisons = new ArrayList<>();
将 mergeParts
中的打印替换为:
comparisons.add(new int[] { i, j });
排序后:
mms.sort(inputArr);
Collections.shuffle(mms.comparisons);
for (int[] c : mms.comparisons) {
System.out.print(" C "+c[0]+" "+c[1]);
}
附件是开发的合并排序代码,它能够对给定数组进行的比较进行计数并打印出每个比较。我希望它能够有效地防止用户学习,以便比较的数字间隔足够大,这样人们就不会记得也看到了过去的数字。现在我们需要让它以不同的顺序进行这些比较。代码可能不再漂亮和递归,而是一些巨大的丑陋循环,我预计。
public class MyMergeSort {
private int[] array; //array declared
private int[] tempMergArr; //temporary array
private int length; //counting length of array
private int ncompare=0;
public static void main(String a[]){
int[] inputArr = {9, 2, 56, 5, 4, 6, 60, 8, 1, //the array, given 60
32, 21, 12, 42, 57, 15, 16, 50, 18, 19,
20, 11, 34, 23, 48, 25, 26, 27, 51, 29,
30, 31, 10, 33, 22, 35, 39, 37, 38, 36,
40, 41, 13, 43, 44, 53, 46, 47, 24, 49,
17, 28, 52, 45, 54, 55, 3, 14, 58, 59,
7};
MyMergeSort mms = new MyMergeSort(); //declaring the merge sort for the array
mms.sort(inputArr);
System.out.print("\n\n");
for(int i:inputArr){
System.out.print(i);
System.out.print(" ");
}
System.out.print("\n Number of comparisons "+mms.ncompare+"\n");
}
public void sort(int inputArr[]) { //sort method uses 'this' for array input
this.array = inputArr;
this.length = inputArr.length;
this.tempMergArr = new int[length];
doMergeSort(0, length - 1);
}
private void doMergeSort(int lowerIndex, int higherIndex) { //indexed method for merge sort, states each step and case
if (lowerIndex < higherIndex) {
int middle = lowerIndex + (higherIndex - lowerIndex) / 2;
// Below step sorts the left side of the array
doMergeSort(lowerIndex, middle);
// Below step sorts the right side of the array
doMergeSort(middle + 1, higherIndex);
// Now merge both sides
mergeParts(lowerIndex, middle, higherIndex);
}
}
private void mergeParts(int lowerIndex, int middle, int higherIndex) { //merge method using 'for' case,
for (int i = lowerIndex; i <= higherIndex; i++) {
tempMergArr[i] = array[i];
}
int i = lowerIndex; //declaring index variables for different cases
int j = middle + 1;
int k = lowerIndex;
while (i <= middle && j <= higherIndex) { //define loops for steps of different cases
System.out.print(" C "+i+" "+j);
ncompare=ncompare+1;
if (tempMergArr[i] <= tempMergArr[j]) {
array[k] = tempMergArr[i];
i++;
} else {
array[k] = tempMergArr[j];
j++;
}
k++;
}
while (i <= middle) {
array[k] = tempMergArr[i];
k++;
i++;
}
}
C 0 1 C 2 3 C 0 2 C 1 2 C 1 3
这些是我现有算法中进行的前五次比较。我想阻止它比较 0 和 2,然后比较 1 和 2,因为用户可能会记住 2,就像比较 1 和 2,然后比较 1 和 3 时,用户会记住 1。
我想尽量让比较的数字不那么容易被用户记住,以免他们做出有偏见的比较
比较顺序由合并排序算法定义。如果您以不可预测的或 "not memorable" 顺序比较索引,则您不再进行合并排序。您实际上必须发明一种新的排序算法才能获得这种行为。
但是,您可以在正常进行比较后打印 以随机顺序进行比较。只需将它们存储在列表字段中,然后在排序后打乱并打印它们。例如:
public List<int[]> comparisons = new ArrayList<>();
将 mergeParts
中的打印替换为:
comparisons.add(new int[] { i, j });
排序后:
mms.sort(inputArr);
Collections.shuffle(mms.comparisons);
for (int[] c : mms.comparisons) {
System.out.print(" C "+c[0]+" "+c[1]);
}