Jump to content

Gapful numbers: Difference between revisions

Ada version
(Added 11l)
(Ada version)
Line 63:
First 10 gapful numbers from 1000000000
[1000000000, 1000000001, 1000000005, 1000000008, 1000000010, 1000000016, 1000000020, 1000000027, 1000000030, 1000000032]
</pre>
 
=={{header|Ada}}==
<lang Ada>with Ada.Text_IO; use Ada.Text_IO;
 
procedure Gapful_Numbers is
 
function Divisor (N : in Positive) return Positive is
NN : Positive := N;
begin
while NN >= 10 loop
NN := NN / 10;
end loop;
return 10 * NN + (N mod 10);
end Divisor;
 
function Is_Gapful (N : in Positive) return Boolean is
begin
return N mod Divisor (N) = 0;
end Is_Gapful;
 
procedure Find_Gapful (Count : in Positive; From : in Positive) is
Found : Natural := 0;
begin
for Candidate in From .. Positive'Last loop
if Is_Gapful (Candidate) then
Put (Candidate'Image);
Found := Found + 1;
exit when Found = Count;
end if;
end loop;
New_Line;
end Find_Gapful;
 
begin
Put_Line ("First 30 gapful numbers over 100:");
Find_Gapful (From => 100, Count => 30);
New_Line;
 
Put_Line ("First 15 gapful numbers over 1_000_000:");
Find_Gapful (From => 1_000_000, Count => 15);
New_Line;
 
Put_Line ("First 10 gapful numbers over 1_000_000_000:");
Find_Gapful (From => 1_000_000_000, Count => 10);
New_Line;
end Gapful_Numbers;</lang>
{{out}}
<pre>First 30 gapful numbers over 100:
100 105 108 110 120 121 130 132 135 140 143 150 154 160 165 170 176 180 187 190 192 195 198 200 220 225 231 240 242 253
 
First 15 gapful numbers over 1_000_000:
1000000 1000005 1000008 1000010 1000016 1000020 1000021 1000030 1000032 1000034 1000035 1000040 1000050 1000060 1000065
 
First 10 gapful numbers over 1_000_000_000:
1000000000 1000000001 1000000005 1000000008 1000000010 1000000016 1000000020 1000000027 1000000030 1000000032
</pre>
 
211

edits

Cookies help us deliver our services. By using our services, you agree to our use of cookies.