function tprint(tbl)
    for i,v in pairs(tbl) do
        print(v)
    end
end

function deBruijn(k, n)
    local a = {}
    for i=1, k*n do
        table.insert(a, 0)
    end

    local seq = {}
    function db(t, p)
        if t > n then
            if n % p == 0 then
                for i=1, p do
                    table.insert(seq, a[i + 1])
                end
            end
        else
            a[t + 1] = a[t - p + 1]
            db(t + 1, p)

            local j = a[t - p + 1] + 1
            while j < k do
                a[t + 1] = j % 256
                db(t + 1, t)
                j = j + 1
            end
        end
    end

    db(1, 1)

    local buf = ""
    for i,v in pairs(seq) do
        buf = buf .. tostring(v)
    end
    return buf .. buf:sub(1, n - 1)
end

function allDigits(s)
    return s:match('[0-9]+') == s
end

function validate(db)
    local le = string.len(db)
    local found = {}
    local errs = {}

    for i=1, 10000 do
        table.insert(found, 0)
    end