Ludic numbers: Difference between revisions
Content added Content deleted
(Ada version) |
m (→{{header|Ada}}) |
||
Line 367: | Line 367: | ||
end Fill; |
end Fill; |
||
procedure |
procedure Put_Lucid (First, Last : in Natural) is |
||
use Ada.Text_IO; |
use Ada.Text_IO; |
||
begin |
begin |
||
Put_Line ("First |
Put_Line ("Lucid numbers " & First'Image & " to " & Last'Image & ":"); |
||
for I in |
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 |
end Put_Lucid; |
||
procedure |
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 <= |
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 |
Ada.Text_IO.Put_Line ("There are " & Count'Image & " lucid numbers <=" & Below'Image); |
||
end |
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 |
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 |
end Is_Lucid; |
||
use Ada.Text_IO; |
use Ada.Text_IO; |
||
Index : Natural; |
|||
Lucid : Natural; |
|||
begin |
begin |
||
Put_Line ("All triplets of lucid numbers <" & Limit'Image); |
Put_Line ("All triplets of lucid numbers <" & Limit'Image); |
||
Index := First_Index (List); |
|||
while List ( |
while List (Index) < Limit loop |
||
Lucid := List (Index); |
|||
if |
if Is_Lucid (Lucid + 2) and Is_Lucid (Lucid + 6) then |
||
Put ("("); |
Put ("("); |
||
Put ( |
Put (Lucid'Image); |
||
Put (Natural'( |
Put (Natural'(Lucid + 2)'Image); |
||
Put (Natural'( |
Put (Natural'(Lucid + 6)'Image); |
||
Put_Line (")"); |
Put_Line (")"); |
||
end if; |
end if; |
||
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, |
|||
⚫ | |||
Last => 2005); |
|||
⚫ | |||
end Ludic_Numbers;</lang> |
end Ludic_Numbers;</lang> |
||
{{out}} |
{{out}} |
||
<pre> |
<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 |
There are 142 lucid numbers <= 1000 |
||
Lucid |
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 |