%% SL7
clear; clc;
a = primes(1e3);
b = 2:2:1e3; 
c = setdiff(1:1000, b);
v = intersect(a, b+c)
length(v)

%% SL8
w = setdiff(union(b, c), a)

sum(not(mod(w, 3)))

%% SL10
% script depicts number of integers 
% from 1 to 1000 in 
% dependence on division remainders
clear; clc;

M = zeros(20,1);

a = primes(1e3);
b = 2:2:1e3;
c = setdiff(1:1000, b);
w = setdiff(union(b, c), a);

for iDiv = 1:length(M)
    M(iDiv) = sum(not(mod(w, iDiv))); 
end

figure;
bar(M);

%% SL15
% bubble sort algorithm
clear; close all; clc
R = 10*rand(1,30);
for startMove = (length(R)-1):-1:1
    for pos = startMove:(length(R)-1)
        if R(pos) > R(pos+1)
            R([pos, pos+1]) = [R(pos+1) R(pos)];
        end
        figure(1);
        plot(R,'*','LineWidth',2);
        pause(0.01);
    end
end
issorted(R)

%% SL20
v  = reshape(magic(4)', [1 numel(magic(4))])
v  = sort(v, 'descend');
v1 = mod(v, 3) == 0 & v > 10
v(v1)
find(v1)

%% SL21
w = (8:-1:2)'*(1:1/2:4).*magic(7)
w50 = w(w < 50);
w50(end-2:end)
% w50 = [20; 12; 31.5]
[rw, cl] = find(w < 50, 3, 'last');

%% SL26
dta = [1 -110; 1 -140; 2 -22; 3 -2; ...
          2 -34; 1 -1300; 2 -15; 1 -730; 3 24]
K   = [1 28 21]
M   = accumarray(dta(:, 1), dta(:, 2))
acc =  dot(K,M)  % = -3806


