Code covered by the BSD License  

Highlights from
Collatz and Goldbach Conjucture

image thumbnail
from Collatz and Goldbach Conjucture by RAHUL RANJAN
Verification of Collatz and Goldbach Conjucture

goldback(n)
function goldback(n)
%goldbach conjucture verification
tic
clc
if nargin==0
    n = 50;
end
if n<2 || (rem(n,2)==1)
    disp('ENTER +VE EVEN NUMBER GREATER THAN 2')
    return
end
p = primes(n);
z1 = cell(1,length(p));
for k = 1:length(p)
    x = n-p(k);
    t = and(isprime(x),isprime(p(k)));
    if t==1;
        m = p(k);
        z = {m,x};
        z1(k) = {z};
    else
        z1(k) = {0};
    end
end
for k = length(z1):-1:1
    q = z1{k};
    if isscalar(q)
        z1(k) = [];
    end
end
k = length(z1);
k3 = round(k/2);
if rem(k,2)==0
    z1(k3+1:k) = [];
else
    z1((k3+1):k) = [];
end
disp(' ')
fprintf('%d can be formed by combination\nof 2 prime numbers as follow:\n',n)
k = length(z1);
for k1 = 1:k;
    x = z1{k1};
    a = x{1};
    b = x{2};
    fprintf('%d & %d\n',a,b)
end
fprintf('Total possible combinations\nare %d whose sum is = %d\n',k,n)
disp(' ')
toc;
end

Contact us