-
Notifications
You must be signed in to change notification settings - Fork 0
/
LatinSquare.java
56 lines (49 loc) · 1.67 KB
/
LatinSquare.java
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
import java.util.*;
class LatinSquare extends Block{
static List<LatinSquare> sq;
static {
sq = new ArrayList<LatinSquare>();
sq.add(new LatinSquare(new int[] {0,1,2,1,2,0,2,0,1}));
sq.add(new LatinSquare(new int[] {1,0,2,0,2,1,2,1,0}));
sq.add(new LatinSquare(new int[] {2,1,0,0,2,1,1,0,2}));
sq.add(new LatinSquare(new int[] {0,1,2,2,0,1,1,2,0}));
sq.add(new LatinSquare(new int[] {1,0,2,2,1,0,0,2,1}));
sq.add(new LatinSquare(new int[] {2,1,0,1,0,2,0,2,1}));
sq.add(new LatinSquare(new int[] {0,2,1,1,0,2,2,1,0}));
sq.add(new LatinSquare(new int[] {1,2,0,0,1,2,2,0,1}));
sq.add(new LatinSquare(new int[] {2,0,1,0,1,2,1,2,0}));
sq.add(new LatinSquare(new int[] {0,2,1,2,1,0,1,0,2}));
sq.add(new LatinSquare(new int[] {1,2,0,2,0,1,0,1,2}));
sq.add(new LatinSquare(new int[] {2,0,1,1,2,0,0,1,2}));
}
static LatinSquare getById(int n){
LatinSquare lsNew = new LatinSquare();
LatinSquare lsOld = sq.get(n);
for(int i = 0; i < Block.SIZE; i++)
for (int j = 0; j < Block.SIZE; j++)
lsNew.setValue(i, j, lsOld.getValue(i, j));
return lsNew;
}
static LatinSquare getRandom(){
return getById(new Random().nextInt(sq.size()));
}
static void swap_rows(LatinSquare s1, LatinSquare s2, int r1, int r2){
int tmp;
for(int i = 0; i < Block.SIZE; i++){
tmp = s1.getValue(r1, i);
s1.setValue(r1, i, s2.getValue(r2, i));
s2.setValue(r2, i, tmp);
}
}
public LatinSquare(int[] v){
super(v);
}
public LatinSquare(){
super();
}
void add(int k){
for(int i = 0; i< super.SIZE; i++)
for(int j = 0; j< super.SIZE; j++)
super.value[i][j] += k;
}
}