On Friday, 10 February 2017 at 11:27:02 UTC, Nestor wrote:
Thank you for the detailed reply. I wasn't able to follow you regarding the multilevel stuff though :(

 The idea behind it is like this (which you can scale up):

static immutable int[] QG10Matrix2 = buildMatrix2();

int[] buildMatrix2() {
    string digits = "0123456789";
    int[] l = new int[16*16*10];
    char[3] s;
    foreach(a; digits)
    foreach(b; digits)
    foreach(c; digits) {
        s[] = [a,b,c];
l[(a-'0')<< 8|(b-'0')<<4|(c-'0')]=checkDigit(cast(string) s) - '0';
    }

    return l;
}


Using that it SHOULD allow you to get the result of 2 inputs simply by using 2 characters (plus the old result)

char checkDigit2(string str) {
    int tmpdigit = 0;
    for(;str.length >= 2;str=str[2 .. $]) {
tmpdigit = QG10Matrix2[tmpdigit<<8|(str[0]-'0')<< 4|(str[1]-'0')];
    }
   // handle remainder single character and return value


While it should be easy, I'm having issues trying to get the proper results via unittests and I'm not sure why. Probably something incredibly simple on my part.

Reply via email to