在Matlab中推断集映射

时间:2017-03-26 08:12:09

标签: algorithm matlab combinatorics decoding

我试图推断从集合AB的映射方案(如下所示)。有没有办法(工具箱,长期遗忘的文件交换宝石,...)在Matlab中做到这一点?

我的AB是:

A = [8955573624 8727174542 6144057737 6697647320 1335549467 6669202192...
     9276317113 5048034450 4757279524 1423969226 9729294957 4332046813...
     0681780168 8231841017 9809242207 5584677643 6193476760 7203972648...
     7286156579 5669792887 6789954237 8042954283 7426511939 4053045131...
     8629149977 2997522935 9363344270 9890870146 9426932555 5755262458...
     8327043690 0162545530 6451719711 5376165082 0595003112 5172323540...
     9314878787 6822370777 8236826223 3097377830];

B = [000 001 001 003 003 004...
     004 005 005 005 005 007...
     007 009 009 009 010 010...
     013 013 013 018 018 018...
     018 019 019 019 020 020...
     020 024 024 024 024 027...
     027 027 027 028];

1 个答案:

答案 0 :(得分:1)

蛮力方法可能是一个很好的起点。它至少给一个地方开始思考问题。我包含了我用来找出的代码,对于前四个数字,下面的每个10位数的操作顺序给出了3位数代码。

@mod, @times, @rem, @mod, @times, @plus, @rem, @rem, @mod

然而

Elapsed time is 391.706191 seconds.

代码

data = [8955573624 000
        8727174542 001
        6144057737 001];

operations = {@plus, @minus, @times, @rdivide, @mod, @rem};

tic;
j = 1; % start from 1st row
while true
    a = data(j,1);
    digits = arrayfun(@str2mat,b(:)); b = num2str(a(1)); % Digits
    if j == 1; % Find a set of operations which converts from digits to the code
        value = NaN;
        trials = 0;
        while value ~= data(j,2) || trials > 1e3
            ops = datasample(operations,numel(digits)-1); % Random operations
            value = digits(1);
            for jj = 1:numel(digits)-1
                value = arrayfun(ops{jj},value,digits(jj+1));
            end
            trials = trials + 1;
        end
    else % Test whether it works for j > 1
        value = digits(1);
        for jj = 1:numel(digits)-1
            value = arrayfun(ops{jj},value,digits(jj+1));
        end
    end

    if value == data(j,2);
        if j == size(data,1); break; end;
        j = j + 1;
    else
        j = 1;
    end
end
toc; 

就在此代码框架中尝试的其他事项而言:

  • 允许将数字作为代码的较大部分进行测试。例如。将第一个代码拆分为89,5,55,736,2,4而不是仅转换为单个数字
  • 允许其他/更多操作
  • 并行尝试
  • 在while循环之前将代码拆分成数字(< - 可能是最简单的优化)
  • 一次尝试对所有代码进行操作(矢量化)
  • 将代码和答案都更改为二进制文件并尝试在那里找到地图

希望有所帮助。即使它没有直接解决你的问题,它可能会帮助你以一种新的方式思考它。