Trying to make an n*n pattern of "+" and "-" when value a[i][j] == b[i][j] and value a[i][j] != b[i][j]. Unsure of why this isn't outputting expected.
Same output if I loop through a[i][j] == seq[i]. Tried assigning a[i][j] and seq[i] to variables before comparing and same result.
public class ThueMorse {
public static void main(String[] args) {
int n = Integer.parseInt(args[0]);
String thue = "0";
String morse = "1";
String[][] a = new String[n][n];
String[][] b = new String[n][n];
for (int i = 1; i <= n; i++) {
String t = thue;
String m = morse;
thue += m;
morse += t;
if (thue.length() >= n) break;
}
String [] seq = new String[n];
seq = thue.split("");
for (int i = 0; i < n; i ++) {
for (int j = 0; j < n; j ++) {
a[i][j] = seq[j];
b[i][j] = seq[i];
if (j != 0) System.out.print(" ");
if (a[i][j] == b[i][j]) {
System.out.print("+");
}
else {
System.out.print("-");
}
if (j != n) System.out.print(" ");
}
System.out.println();
}
}
}
For reference:
seq[] = [0, 1, 1, 0, 1, 0, 0, 1]
a[i][j] =
0 1 1 0 1 0 0 1
0 1 1 0 1 0 0 1
0 1 1 0 1 0 0 1
0 1 1 0 1 0 0 1
0 1 1 0 1 0 0 1
0 1 1 0 1 0 0 1
0 1 1 0 1 0 0 1
0 1 1 0 1 0 0 1
b[i][j] =
0 0 0 0 0 0 0 0
1 1 1 1 1 1 1 1
1 1 1 1 1 1 1 1
0 0 0 0 0 0 0 0
1 1 1 1 1 1 1 1
0 0 0 0 0 0 0 0
0 0 0 0 0 0 0 0
1 1 1 1 1 1 1 1
Output:
+ - - - - - - -
- + - - - - - -
- - + - - - - -
- - - + - - - -
- - - - + - - -
- - - - - + - -
- - - - - - + -
- - - - - - - +
Expected:
+ - - + - + + -
- + + - + - - +
- + + - + - - +
+ - - + - + + -
- + + - + - - +
+ - - + - + + -
+ - - + - + + -
- + + - + - - +