A neuron can operate as a logic gate, and thus a Neural Network can perform any calculation a computer can. However in that sense it simply emulates logic gates inefficiently, using high level code, so is not a good solution for this problem.
In general, neural networks are good with 'real' or 'natural' data. They also generally operate with floats, not integers. So if there is a pattern to be learnt, a NN might learn it, but the output answer you will get will be eg 0.783267. You could then denormalize this to 89743, but its unlikely to be exactly right. For your requirement, one integer off the right answer is completely wrong.
By contrast, for a face recognition NN returning 0.787 or 0.786 for a particular image, both could be considered correct.
Your problem is better suited to a traditional, procedural code solution, with only one correct answer for each input. Generally in AI, you are looking for the correct answer, within a certain range or probability distribution.
Regarding implementing algorithms with NNs:
You can have many neurons acting as logic gates, so now you have neuron nand gate / flipflops etc acting as adders/multipliers/latches etc, until you have essentially built a turing machine, but explicitly using high level code. It will in no way resemble a normal NN as they are used by the majority of the AI world. Further, you already have a perfectly good turing machine right in front of you.
Here is the code for a Neural Network AND gate in Matlab. No training is required. I've used configure
instead of train
, and just set the weights manually. So making the other logic types you could build an entire turing machine.
and = feedforwardnet(1);
truthTable = [0 0 1 1; 0 1 0 1];
and_out = [0 0 0 1];
and = configure(and, truthTable, and_out);
vals = [-2 -2 -1 2 0];
and.IW{1} = vals(1:2); % input1 to hidden, input2 to hidden
and.LW{2,1} = vals(3); % hidden to output
and.b{1} = vals(4); % bias to hidden
and.b{2} = vals(5); % bias to output
y = sim(and, truthTable)
round (y)
mse = mean ((y - and_out) .^ 2)
y =
0.0000 0.0180 0.0180 0.9820
ans =
0 0 0 1
mse =
2.4263e-04