Strange plus numbers: Difference between revisions

Content added Content deleted
(→‎{{header|ALGOL 68}}: No need for a sieve - there's only 3 odd numbers < 18 that aren't prime)
(Added Algol W)
Line 106: Line 106:
OD
OD
END</lang>
END</lang>
{{out}}
<pre>
111 112 114 116 120 121 123 125 129 141
143 147 149 161 165 167 202 203 205 207
211 212 214 216 230 232 234 238 250 252
256 258 292 294 298 302 303 305 307 320
321 323 325 329 341 343 347 349 383 385
389 411 412 414 416 430 432 434 438 470
474 476 492 494 498
</pre>

=={{header|ALGOL W}}==
{{Trans|A:GOL 68}}
<lang pascal>begin % find numbers where the sum of the first 2 digits is prime and also %
% the sum of the second 2 digits is prime %
% considers numbers n where 100 < n < 500 %
logical procedure isSmallPrime ( integer value n ); n = 2 or ( odd( n ) and n not = 1 and n not = 9 and n not = 15 );
procedure divideBy ( integer value result n; integer value d ) ; n := n div d;
integer procedure inc ( integer value result n ); begin n := n + 1; n end;
integer sCount;
sCount := 0;
for n := 101 until 499 do begin
integer v, d1, d2, d3;
v := n;
d1 := v rem 10; divideBy( v, 10 );
d2 := v rem 10; divideBy( v, 10 );
d3 := v;
if isSmallPrime( d1 + d2 ) and isSmallPrime( d2 + d3 ) then begin
writeon( i_w := 3, s_w := 0, " ", n );
if inc( sCount ) rem 10 = 0 then write()
end if_small_primes
end for_n
end.
</lang>
{{out}}
{{out}}
<pre>
<pre>