Skip to content

Instantly share code, notes, and snippets.

@Hc747
Created September 7, 2018 10:08
Show Gist options
  • Save Hc747/302bb876c99ddecac36e8610d7a1d930 to your computer and use it in GitHub Desktop.
Save Hc747/302bb876c99ddecac36e8610d7a1d930 to your computer and use it in GitHub Desktop.
import java.util.Arrays;
/**
* @author Harrison | Hc747
* Contact: [email protected] | [email protected] | [email protected]
* @version 1.0
* @since 2018-09-07
*/
public class Sator {
public static void main(String[] args) {
int width = 5, height = 5;
String[] input = {
"sator",
"arepo",
"tenet",
"opera",
"rotas",
};
char[][] grid = new char[height][];
for (int i = 0; i < height; i++) {
grid[i] = input[i].toCharArray();
}
for (int i = 0; i < grid.length; i++) {
System.out.println(Arrays.toString(grid[i]));
}
System.out.println();
int max = Math.min(height, width) - 1;
for (int h = 0; h < height; h++) {
for (int w = 0; w < width; w++) {
char topLeft = grid[h][w];
for (int i = max; i > 1; i--) {
if ((w + i) >= width) continue;
if ((h + i) >= height) continue;
char topRight = grid[h][w + i];
char bottomLeft = grid[h + i][w];
char bottomRight = grid[h + i][w + i];
if (topLeft == bottomRight && bottomLeft == topRight) {
if ((i - w) != (i - h)) {
throw new IllegalStateException(String.format("Not a square: h: %d, w: %d", (i - h), (i - w)));
}
int delta = i - w;
System.out.println(String.format("Height: %d, Width: %d", h, w));
System.out.println(String.format("Left: %s, Right: %s", topLeft, topRight));
System.out.println(String.format("Delta: %d", delta));
}
}
}
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment