#include "_.h"

int main(int argc, char **argv) {
	
	if (argc != 2)
		return 1;

	char *input = argv[1];
	char **inputs = str_split(strdup(input), '\n');

    int count = 0;
    int max_y = strslen(inputs);
    int max_x = strlen(inputs[0]);
    int signals[4096][2] = { [0 ... 4095] = {-1, -1} };
	for (int y = 0; inputs[y] != NULL; y++) {
	    for (int x = 0; inputs[y][x] != '\0'; x++) {

            if (isalpha(inputs[y][x]) || isdigit(inputs[y][x])) {
                for (int i = 0; inputs[i] != NULL; i++) {
                    for (int j = 0; inputs[i][j] != '\0'; j++) {
                        if (i == y && j == x)
                            continue;
                        if (inputs[i][j] != inputs[y][x])
                            continue;

                        int signal_y = i - y + i;
                        int signal_x = j - x + j;

                        if (signal_y >= max_y ||
                            signal_y < 0 ||
                            signal_x >= max_x ||
                            signal_x < 0)
                            continue;

                        int continu = 0;
                        for (int v = 0; signals[v][0] != -1; v++) {
                           if (signals[v][0] == signal_y &&
                               signals[v][1] == signal_x) {
                                continu = 1;
                                break;
                           }
                        }
                        if (continu == 1)
                            continue;

                        signals[count][0] = signal_y;
                        signals[count][1] = signal_x;
                        count++;
                    }
                }
            }

        }
	}

    printf("count: %d\n", count);
	return 0;
}
