Special neighbor primes: Difference between revisions
Added 11l
(Added solution for Action!) |
Alextretyak (talk | contribs) (Added 11l) |
||
Line 6:
Find and show here in base ten if '''p<sub>1</sub>+ p<sub>2</sub> -1''' is prime, where '''p<sub>1</sub>, p<sub>2</sub> < 100'''.
<br><br>
=={{header|11l}}==
{{trans|Nim}}
<lang 11l>F is_prime(n)
I n == 2
R 1B
I n < 2 | n % 2 == 0
R 0B
L(i) (3 .. Int(sqrt(n))).step(2)
I n % i == 0
R 0B
R 1B
V primes = (0.<100).filter(n -> is_prime(n))
L(i) 0 .< primes.len - 1
V p1 = primes[i]
V p2 = primes[i + 1]
I is_prime(p1 + p2 - 1)
print((p1, p2))</lang>
{{out}}
<pre>
(3, 5)
(5, 7)
(7, 11)
(11, 13)
(13, 17)
(19, 23)
(29, 31)
(31, 37)
(41, 43)
(43, 47)
(61, 67)
(67, 71)
(73, 79)
</pre>
=={{header|Action!}}==
|