Skip to content

Instantly share code, notes, and snippets.

@yao2030
Created October 23, 2012 06:40
Show Gist options
  • Save yao2030/3937264 to your computer and use it in GitHub Desktop.
Save yao2030/3937264 to your computer and use it in GitHub Desktop.
Hadamard matrix
public class Hadamard
{
public static void main(String[] args)
{
int N = Integer.parseInt(args[0]);
boolean[][] H = new boolean[N][N];
H[0][0] = true;
for(int n = 1; n < N; n += n)
{
for(int i = 0; i < n; i++)
for(int j = 0; j < n; j++)
{
H[i+n][j] = H[i][j];
H[i][j+n] = H[i][j];
H[i+n][j+n] = !H[i][j];
}
}
for(int i = 0; i < N; i++)
{
for(int j = 0; j < N; j++)
{
if(H[i][j]) System.out.print("* ");
else System.out.print(". ");
}
System.out.println();
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment