Ludic numbers: Difference between revisions

Initial implementation in PL/I
(+Java)
(Initial implementation in PL/I)
Line 323:
Ludic numbers 2000..2005: 21475 21481 21487 21493 21503 21511
Ludic triples < 250: <1 3 7> <5 7 11> <11 13 17> <23 25 29> <41 43 47> <173 175 179> <221 223 227> <233 235 239></pre>
 
=={{header|PL/I}}==
<lang PL/I>Ludic_numbers: procedure options (main); /* 18 April 2014 */
declare V(2:22000) fixed, L(2200) fixed;
declare (step, i, j, k, n) fixed binary;
 
Ludic: procedure;
n = hbound(V,1); k = 1; L(1) = 1;
do i = 2 to n; V(i) = i; end;
 
do forever;
k = k + 1; L(k), step = V(2);
 
do i = 2 to n by step;
V(i) = 0;
end;
call compress;
if L(k) >= 21511 then leave;
end;
 
put skip list ('The first 25 Ludic numbers are:');
put skip edit ( (L(i) do i = 1 to 25) ) (F(4));
 
k = 0;
do i = 1 by 1;
if L(i) < 1000 then k = k + 1; else leave;
end;
 
put skip list ('There are ' || trim(k) || ' Ludic numbers < 1000');
put skip list ('Six Ludic numbers from the 2000-th:');
put skip edit ( (L(i) do i = 2000 to 2005) ) (f(7));
/* Triples are values of the form x, x+2, x+6 */
put skip list ('Triples are:');
put skip;
i = 1;
do i = 1 by 1 while (L(i+2) <= 250);
if (L(i) = L(i+1) - 2) & (L(i) = L(i+2) - 6) then
put edit ('(', L(i), L(i+1), L(i+2), ') ' ) (A, 3 F(4), A);
end;
 
compress: procedure;
j = 2;
do i = 2 to n;
if V(i) ^= 0 then do; V(j) = V(i); j = j + 1; end;
end;
n = j-1;
end compress;
 
end Ludic;
 
call Ludic;
 
end Ludic_numbers;</lang>
Output:
<pre>The first 25 Ludic numbers are:
1 2 3 5 7 11 13 17 23 25 29 37 41 43 47
53 61 67 71 77 83 89 91 97 107
There are 142 Ludic numbers < 1000
Six Ludic numbers from the 2000-th:
21475 21481 21487 21493 21503 21511
Triples are:
( 5 7 11) ( 11 13 17) ( 23 25 29) ( 41 43 47)
( 173 175 179) ( 221 223 227) ( 233 235 239)</pre>
 
=={{header|Python}}==