Ludic numbers: Difference between revisions

Content added Content deleted
(Ada version)
Line 367: Line 367:
end Fill;
end Fill;


procedure Put_First_25 is
procedure Put_Lucid (First, Last : in Natural) is
use Ada.Text_IO;
use Ada.Text_IO;
begin
begin
Put_Line ("First 25 lucid nunbers:");
Put_Line ("Lucid numbers " & First'Image & " to " & Last'Image & ":");
for I in 1 .. 25 loop
for I in First .. Last loop
Put (Natural'(List (I))'Image);
Put (Natural'(List (I))'Image);
end loop;
end loop;
New_Line;
New_Line;
end Put_First_25;
end Put_Lucid;


procedure Count_Below_1000 is
procedure Count_Lucid (Below : in Natural) is
Count : Natural := 0;
Count : Natural := 0;
begin
begin
for Lucid of List loop
for Lucid of List loop
if Lucid <= 1000 then
if Lucid <= Below then
Count := Count + 1;
Count := Count + 1;
end if;
end if;
end loop;
end loop;
Ada.Text_IO.Put_Line ("There are " & Count'Image & " lucid numbers below 1000");
Ada.Text_IO.Put_Line ("There are " & Count'Image & " lucid numbers <=" & Below'Image);
end Count_Below_1000;
end Count_Lucid;

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
procedure Find_Triplets (Limit : in Natural) is


function In_List (Value : in Natural) return Boolean is
function Is_Lucid (Value : in Natural) return Boolean is
begin
begin
for X in 1 .. Limit loop
for X in 1 .. Limit loop
Line 408: Line 398:
end loop;
end loop;
return False;
return False;
end In_List;
end Is_Lucid;


use Ada.Text_IO;
use Ada.Text_IO;
X : Natural;
Index : Natural;
Lu : Natural;
Lucid : Natural;
begin
begin
Put_Line ("All triplets of lucid numbers <" & Limit'Image);
Put_Line ("All triplets of lucid numbers <" & Limit'Image);
X := First_Index (List);
Index := First_Index (List);
while List (X) < Limit loop
while List (Index) < Limit loop
Lu := List (X);
Lucid := List (Index);
if In_List (Lu + 2) and In_List (Lu + 6) then
if Is_Lucid (Lucid + 2) and Is_Lucid (Lucid + 6) then
Put ("(");
Put ("(");
Put (Lu'Image);
Put (Lucid'Image);
Put (Natural'(Lu + 2)'Image);
Put (Natural'(Lucid + 2)'Image);
Put (Natural'(Lu + 6)'Image);
Put (Natural'(Lucid + 6)'Image);
Put_Line (")");
Put_Line (")");
end if;
end if;
X := X + 1;
Index := Index + 1;
end loop;
end loop;
end Find_Triplets;
end Find_Triplets;
Line 431: Line 421:
begin
begin
Fill;
Fill;
Put_Lucid (First => 1,
Put_First_25;
Last => 25);
Count_Below_1000;
Count_Lucid (Below => 1000);
Put_From_2000_To_2005;
Put_Lucid (First => 2000,
Find_Triplets (250);
Last => 2005);
Find_Triplets (Limit => 250);
end Ludic_Numbers;</lang>
end Ludic_Numbers;</lang>


{{out}}
{{out}}
<pre>First 25 lucid nunbers:
<pre>Lucid numbers 1 to 25:
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
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
There are 142 lucid numbers <= 1000
Lucid nunbers 2000 to 2005:
Lucid numbers 2000 to 2005:
21475 21481 21487 21493 21503 21511
21475 21481 21487 21493 21503 21511
All triplets of lucid numbers < 250
All triplets of lucid numbers < 250