Skip to content

Instantly share code, notes, and snippets.

@ellbur
Created November 1, 2011 18:42
Show Gist options
  • Select an option

  • Save ellbur/1331494 to your computer and use it in GitHub Desktop.

Select an option

Save ellbur/1331494 to your computer and use it in GitHub Desktop.
Pattern
public class Pattern {
public static void main(String[] args) {
int width = 150;
int height = 70;
int[][] grid = new int[width][height];
grid[width/2][0] = 1;
for (int f=1; f<height; f++) {
for (int i=1; i<width-1; i++) {
if (grid[i-1][f-1] == 1 && grid[i+1][f-1] == 0) {
grid[i][f] = 1;
}
if (grid[i-1][f-1] == 0 && grid[i+1][f-1] == 1) {
grid[i][f] = 1;
}
}
}
// Print it out
for (int i=0; i<height; i++) {
for (int j=0; j<width; j++) {
if (grid[j][i] == 1) {
System.out.print("X");
}
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