MATL, 16 bytes
liqZqtd2=)t2+h/s
Consider input 13 as an example.
l % Push 1
% STACK: 1
i % Input N
% STACK: 1, 13
q % Subtract 1
% STACK: 1, 12
Zq % Primes up to Nthat
% STACK: 1, [2 3 5 7 11]
t % Duplicate
% STACK: 1, [2 3 5 7 11], [2 3 5 7 11]
d % Consecutive differences
% STACK: 1, [2 3 5 7 11], [1 2 2 4]
2= % Compare with 2, element-wise
% STACK: 1, [2 3 5 7 11], [0 1 1 0]
) % Use as logical index to select elements from array
% STACK: 1, [3 5]
t % Duplicate
% STACK: 1, [3 5], [3 5]
2+ % Add 2, element-wise
% STACK: 1, [3 5], [5 7]
h % Concatenate horizontally
% STACK: 1, [3 5 5 7]
/ % Divide, element-wise
% STACK: [0.3333 0.2 0.2 0.1429]
s % Sum of array. Implicitly display
% STACK: 0.8762
MATL, 16 bytes
liqZqtd2=)t2+h/s
Consider input 13 as an example.
l % Push 1
% STACK: 1
i % Input N
% STACK: 1, 13
q % Subtract 1
% STACK: 1, 12
Zq % Primes up to N
% STACK: 1, [2 3 5 7 11]
t % Duplicate
% STACK: 1, [2 3 5 7 11], [2 3 5 7 11]
d % Consecutive differences
% STACK: 1, [2 3 5 7 11], [1 2 2 4]
2= % Compare with 2, element-wise
% STACK: 1, [2 3 5 7 11], [0 1 1 0]
) % Use as logical index to select elements from array
% STACK: 1, [3 5]
t % Duplicate
% STACK: 1, [3 5], [3 5]
2+ % Add 2, element-wise
% STACK: 1, [3 5], [5 7]
h % Concatenate horizontally
% STACK: 1, [3 5 5 7]
/ % Divide, element-wise
% STACK: [0.3333 0.2 0.2 0.1429]
s % Sum of array. Implicitly display
% STACK: 0.8762
MATL, 16 bytes
liqZqtd2=)t2+h/s
Consider input 13 as an example.
l % Push 1
% STACK: 1
i % Input N
% STACK: 1, 13
q % Subtract 1
% STACK: 1, 12
Zq % Primes up to that
% STACK: 1, [2 3 5 7 11]
t % Duplicate
% STACK: 1, [2 3 5 7 11], [2 3 5 7 11]
d % Consecutive differences
% STACK: 1, [2 3 5 7 11], [1 2 2 4]
2= % Compare with 2, element-wise
% STACK: 1, [2 3 5 7 11], [0 1 1 0]
) % Use as logical index to select elements from array
% STACK: 1, [3 5]
t % Duplicate
% STACK: 1, [3 5], [3 5]
2+ % Add 2, element-wise
% STACK: 1, [3 5], [5 7]
h % Concatenate horizontally
% STACK: 1, [3 5 5 7]
/ % Divide, element-wise
% STACK: [0.3333 0.2 0.2 0.1429]
s % Sum of array. Implicitly display
% STACK: 0.8762
MATL, 1516 bytes
liZqtd2=liqZqtd2=)t2+h/s
Consider input 13 as an example.
l % Push 1
% STACK: 1
i % Input N
% STACK: 1, 13
q % Subtract 1
% STACK: 1, 12
Zq % Primes up to N
% STACK: 1, [2 3 5 7 11]
t % Duplicate
% STACK: 1, [2 3 5 7 11], [2 3 5 7 11]
d % Consecutive differences
% STACK: 1, [2 3 5 7 11], [1 2 2 4]
2= % Compare with 2, element-wise
% STACK: 1, [2 3 5 7 11], [0 1 1 0]
) % Use as logical index to select elements from array
% STACK: 1, [3 5]
t % Duplicate
% STACK: 1, [3 5], [3 5]
2+ % Add 2, element-wise
% STACK: 1, [3 5], [5 7]
h % Concatenate horizontally
% STACK: 1, [3 5 5 7]
/ % Divide, element-wise
% STACK: [0.3333 0.2 0.2 0.1429]
s % Sum of array. Implicitly display
% STACK: 0.8762
MATL, 16 bytes
liqZqtd2=)t2+h/s
Consider input 13 as an example.
l % Push 1
% STACK: 1
i % Input N
% STACK: 1, 13
q % Subtract 1
% STACK: 1, 12
Zq % Primes up to N
% STACK: 1, [2 3 5 7 11]
t % Duplicate
% STACK: 1, [2 3 5 7 11], [2 3 5 7 11]
d % Consecutive differences
% STACK: 1, [2 3 5 7 11], [1 2 2 4]
2= % Compare with 2, element-wise
% STACK: 1, [2 3 5 7 11], [0 1 1 0]
) % Use as logical index to select elements from array
% STACK: 1, [3 5]
t % Duplicate
% STACK: 1, [3 5], [3 5]
2+ % Add 2, element-wise
% STACK: 1, [3 5], [5 7]
h % Concatenate horizontally
% STACK: 1, [3 5 5 7]
/ % Divide, element-wise
% STACK: [0.3333 0.2 0.2 0.1429]
s % Sum of array. Implicitly display
% STACK: 0.8762