Substring primes: Difference between revisions

Content added Content deleted
m (→‎{{header|ALGOL 68}}: The sieve generated by PRIMESIEVE now includes 0)
(Added 11l)
Line 11: Line 11:
Solve by testing at most 15 numbers for primality. Show a list of all numbers tested that were not prime.
Solve by testing at most 15 numbers for primality. Show a list of all numbers tested that were not prime.
<br><br>
<br><br>

=={{header|11l}}==
{{trans|Go}}

<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 results = [2, 3, 5, 7]
V odigits = [3, 7]
[Int] discarded
V tests = 4

V i = 0
L i < results.len
V r = results[i]
i++
L(od) odigits
I (r % 10) != od
V n = r * 10 + od
I is_prime(n)
results.append(n)
E
discarded.append(n)
tests++

print(‘There are ’results.len‘ primes where all substrings are also primes, namely:’)
print(results)
print("\nThe following numbers were also tested for primality but found to be composite:")
print(discarded)
print("\nTotal number of primality tests = "tests)</lang>

{{out}}
<pre>
There are 9 primes where all substrings are also primes, namely:
[2, 3, 5, 7, 23, 37, 53, 73, 373]

The following numbers were also tested for primality but found to be composite:
[27, 57, 237, 537, 737, 3737]

Total number of primality tests = 15
</pre>


=={{header|Action!}}==
=={{header|Action!}}==