#!/usr/bin/env cscript
#include <inttypes.h>
#include <stdio.h>
#include <string.h>
#define ALPHABET "ABCDEFGHIJKLMNOPQRSTUVWXYZ"

int
power(int x, int y) {
	int n, value;

	value = 1;

	for (n = 1; n <= y; n++) {
		value *= x;
	}

	return value;
}

int
scan_column_index(const char column_string[3 + 1]) {
	int index, value;
	char *needle;

	for (index = 0, value = 0, needle = &column_string[strlen(column_string) - 1];
	     needle >= column_string; needle--) {
printf("@ %ld\n", (1 + strchr(ALPHABET, *needle) - ALPHABET));
		value += (1 + strchr(ALPHABET, *needle) - ALPHABET) * power(strlen(ALPHABET), index);
	}

	return value;
}


int
main(int argc, const char *argv[]) {
	printf("XFD -> %d\n", scan_column_index("XFD"));
	return 0;
}