Twin primes: Difference between revisions

no edit summary
(add RPL)
imported>Maxima enthusiast
No edit summary
Line 1,124:
{100000000,440312}
{1000000000,3424506}</pre>
 
=={{header|Maxima}}==
Using built-in predicate function primep to detect primes and the fact that all but the first pair are of the form [6n-1,6n+1].
<syntaxhighlight lang="maxima">
/* Function to count the number of pairs below n */
twin_primes_under_n(n):=block(
L:makelist([6*i-1,6*i+1],i,1,floor(n/6)),
caching:length(L),
L1:[],
for i from 1 thru caching do if map(primep,L[i])=[true,true] then push(L[i],L1),
append([[3,5]],reverse(L1)),
length(%%));
 
/* Test cases */
twin_primes_under_n(10);
twin_primes_under_n(100);
twin_primes_under_n(1000);
twin_primes_under_n(10000);
twin_primes_under_n(100000);
</syntaxhighlight>
{{out}}
<pre>
2
8
35
205
1224
</pre>
 
=={{header|Nim}}==