Ludic numbers: Difference between revisions
Content added Content deleted
(Ada version) |
|||
Line 326: | Line 326: | ||
233 235 239 |
233 235 239 |
||
</pre> |
</pre> |
||
=={{header|Ada}}== |
|||
<lang Ada>with Ada.Text_IO; |
|||
with Ada.Containers.Vectors; |
|||
procedure Ludic_Numbers is |
|||
package Lucid_Lists is |
|||
new Ada.Containers.Vectors (Positive, Natural); |
|||
use Lucid_Lists; |
|||
List : Vector; |
|||
procedure Fill is |
|||
use type Ada.Containers.Count_Type; |
|||
Vec : Vector; |
|||
Lucid : Natural; |
|||
Index : Positive; |
|||
begin |
|||
Append (List, 1); |
|||
for I in 2 .. 22_000 loop |
|||
Append (Vec, I); |
|||
end loop; |
|||
loop |
|||
Lucid := First_Element (Vec); |
|||
Append (List, Lucid); |
|||
Index := First_Index (Vec); |
|||
loop |
|||
Delete (Vec, Index); |
|||
Index := Index + Lucid - 1; |
|||
exit when Index > Last_Index (Vec); |
|||
end loop; |
|||
exit when Length (Vec) <= 1; |
|||
end loop; |
|||
end Fill; |
|||
procedure Put_First_25 is |
|||
use Ada.Text_IO; |
|||
begin |
|||
Put_Line ("First 25 lucid nunbers:"); |
|||
for I in 1 .. 25 loop |
|||
Put (Natural'(List (I))'Image); |
|||
end loop; |
|||
New_Line; |
|||
end Put_First_25; |
|||
procedure Count_Below_1000 is |
|||
Count : Natural := 0; |
|||
begin |
|||
for Lucid of List loop |
|||
if Lucid <= 1000 then |
|||
Count := Count + 1; |
|||
end if; |
|||
end loop; |
|||
Ada.Text_IO.Put_Line ("There are " & Count'Image & " lucid numbers below 1000"); |
|||
end Count_Below_1000; |
|||
procedure Put_From_2000_To_2005 is |
|||
use Ada.Text_IO; |
|||
begin |
|||
Put_Line ("Lucid nunbers 2000 to 2005:"); |
|||
for I in 2000 .. 2005 loop |
|||
Put (Natural'(List (I))'Image); |
|||
end loop; |
|||
New_Line; |
|||
end Put_From_2000_To_2005; |
|||
procedure Find_Triplets (Limit : in Natural) is |
|||
function In_List (Value : in Natural) return Boolean is |
|||
begin |
|||
for X in 1 .. Limit loop |
|||
if List (X) = Value then |
|||
return True; |
|||
end if; |
|||
end loop; |
|||
return False; |
|||
end In_List; |
|||
use Ada.Text_IO; |
|||
X : Natural; |
|||
Lu : Natural; |
|||
begin |
|||
Put_Line ("All triplets of lucid numbers <" & Limit'Image); |
|||
X := First_Index (List); |
|||
while List (X) < Limit loop |
|||
Lu := List (X); |
|||
if In_List (Lu + 2) and In_List (Lu + 6) then |
|||
Put ("("); |
|||
Put (Lu'Image); |
|||
Put (Natural'(Lu + 2)'Image); |
|||
Put (Natural'(Lu + 6)'Image); |
|||
Put_Line (")"); |
|||
end if; |
|||
X := X + 1; |
|||
end loop; |
|||
end Find_Triplets; |
|||
begin |
|||
Fill; |
|||
Put_First_25; |
|||
Count_Below_1000; |
|||
Put_From_2000_To_2005; |
|||
Find_Triplets (250); |
|||
end Ludic_Numbers;</lang> |
|||
{{out}} |
|||
<pre>First 25 lucid nunbers: |
|||
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 lucid numbers below 1000 |
|||
Lucid nunbers 2000 to 2005: |
|||
21475 21481 21487 21493 21503 21511 |
|||
All triplets of lucid numbers < 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|ALGOL 68}}== |
=={{header|ALGOL 68}}== |