Gapful numbers: Difference between revisions

Added Easylang
(Added Easylang)
 
(35 intermediate revisions by 23 users not shown)
Line 38:
:*   numbersaplenty [http://www.numbersaplenty.com/set/gapful_number/ gapful numbers]
<br><br>
 
=={{header|11l}}==
{{trans|Python}}
 
<syntaxhighlight lang="11l">L(start, n) [(100, 30), (1'000'000, 15), (1'000'000'000, 10)]
print("\nFirst "n‘ gapful numbers from ’start)
[Int] l
L(x) start..
I x % (Int(String(x)[0]) * 10 + (x % 10)) == 0
l.append(x)
I l.len == n
L.break
print(l)</syntaxhighlight>
 
{{out}}
<pre>
 
First 30 gapful numbers from 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 from 1000000
[1000000, 1000005, 1000008, 1000010, 1000016, 1000020, 1000021, 1000030, 1000032, 1000034, 1000035, 1000040, 1000050, 1000060, 1000065]
 
First 10 gapful numbers from 1000000000
[1000000000, 1000000001, 1000000005, 1000000008, 1000000010, 1000000016, 1000000020, 1000000027, 1000000030, 1000000032]
</pre>
 
=={{header|Ada}}==
<syntaxhighlight 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;</syntaxhighlight>
{{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>
 
=={{header|ALGOL 68}}==
<syntaxhighlight lang="algol68">BEGIN # find some gapful numbers - numbers divisible by f*10 + b #
# where f is the first digit and b is the final digit #
# unary GAPFUL operator - returns TRUE if n is gapful #
# FALSE otherwise #
OP GAPFUL = ( INT n )BOOL:
BEGIN
INT abs n = ABS n;
INT back = abs n MOD 10; # final digit #
INT front := abs n OVER 10;
WHILE front > 9 DO front OVERAB 10 OD;
abs n MOD ( ( front * 10 ) + back ) = 0
END; # GAPFUL #
# dyadic GAPFUL operator - returns an array of n gapful #
# numbers starting from first #
PRIO GAPFUL = 9;
OP GAPFUL = ( INT n, INT first )[]INT:
BEGIN
[ 1 : n ]INT result;
INT g pos := 0;
FOR i FROM first WHILE g pos < n DO
IF GAPFUL i THEN result[ g pos +:= 1 ] := i FI
OD;
result
END; # GAPFUL #
# prints a sequence of gapful numbers #
PROC print gapful = ( []INT seq, INT start )VOID:
BEGIN
print( ( "First ", whole( ( UPB seq + 1 ) - LWB seq, 0 )
, " gapful numbers starting from ", whole( start, 0 )
, ":", newline
)
);
FOR i FROM LWB seq TO UPB seq DO print( ( " ", whole( seq[ i ], 0 ) ) ) OD;
print( ( newline ) )
END; # print gapful #
print gapful( 30 GAPFUL 100, 100 );
print gapful( 15 GAPFUL 1 000 000, 1 000 000 );
print gapful( 10 GAPFUL 1 000 000 000, 1 000 000 000 )
END</syntaxhighlight>
{{out}}
<pre>
First 30 gapful numbers starting from 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 starting from 1000000:
1000000 1000005 1000008 1000010 1000016 1000020 1000021 1000030 1000032 1000034 1000035 1000040 1000050 1000060 1000065
First 10 gapful numbers starting from 1000000000:
1000000000 1000000001 1000000005 1000000008 1000000010 1000000016 1000000020 1000000027 1000000030 1000000032
</pre>
 
=={{header|AppleScript}}==
 
<langsyntaxhighlight lang="applescript">on isGapful(n)
set units to n mod 10
set temp to n div 10
Line 71 ⟶ 203:
set output to output as text
set AppleScript's text item delimiters to astid
return output</langsyntaxhighlight>
 
{{output}}
<langsyntaxhighlight lang="applescript">"First 30 gapful numbers ≥ 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
 
Line 81 ⟶ 213:
 
First 10 gapful numbers ≥ 1,000,000,000:
1.0E+9 1.000000001E+9 1.000000005E+9 1.000000008E+9 1.00000001E+9 1.000000016E+9 1.00000002E+9 1.000000027E+9 1.00000003E+9 1.000000032E+9"</langsyntaxhighlight>
 
=={{header|Arturo}}==
<syntaxhighlight lang="rebol">gapful?: function [n][
 
<lang rebol>gapful?: function [n][
s: to :string n
divisor: to :integer (first s) ++ last s
Line 108 ⟶ 239:
]
print "\n"
]</langsyntaxhighlight>
 
{{out}}
 
<pre>----------------------------------------------------------------
first 30 gapful numbers starting from 100
Line 133 ⟶ 262:
 
=={{header|AutoHotkey}}==
<langsyntaxhighlight AutoHotkeylang="autohotkey">Gapful_numbers(Min, Qty){
counter:= 0, output := ""
while (counter < Qty){
Line 142 ⟶ 271:
}
return output
}</langsyntaxhighlight>
Examples:<langsyntaxhighlight AutoHotkeylang="autohotkey">MsgBox, 262144, , % Gapful_numbers(100, 30)
MsgBox, 262144, , % Gapful_numbers(1000000, 15)
MsgBox, 262144, , % Gapful_numbers(1000000000, 10)</langsyntaxhighlight>
{{out}}
<pre>
Line 208 ⟶ 337:
 
=={{header|AWK}}==
<syntaxhighlight lang="awk">
<lang AWK>
# syntax: GAWK -f GAPFUL_NUMBERS.AWK
# converted from C++
Line 234 ⟶ 363:
}
printf("\n")
}</syntaxhighlight>
}
</lang>
{{out}}
<pre>first 30 gapful numbers >= 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
<pre>
first 30 gapful numbers >= 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 >= 1000000: 1000000 1000005 1000008 1000010 1000016 1000020 1000021 1000030 1000032 1000034 1000035 1000040 1000050 1000060 1000065
first 10 gapful numbers >= 1000000000: 1000000000 1000000001 1000000005 1000000008 1000000010 1000000016 1000000020 1000000027 1000000030 1000000032
first 25 gapful numbers >= 7123: 7125 7140 7171 7189 7210 7272 7275 7280 7296 7350 7373 7420 7425 7474 7488 7490 7560 7575 7630 7632 7676 7700 7725 7770 7777</pre>
</pre>
 
=={{header|BASIC}}==
==={{header|Applesoft BASIC}}===
{{trans|C}}
Numbers are printed digit by digit so that we can see what they actually are because large numbers would normally be printed in scientific notation.
<syntaxhighlight lang="gwbasic"> 100 START = 100
110 COUNT = 30
120 GOSUB 230"GENERATE GAPS"
130 PRINT
140 START = 1000000
150 COUNT = 15
160 GOSUB 230"GENERATE GAPS"
170 PRINT
180 START = 1000000000
190 COUNT = 15
200 GOSUB 230"GENERATE GAPS"
210 PRINT
220 END
230 GOSUB 340"PRINT START"
240 PRINT " :"M$
250 LET C = 0
260 FOR START = START TO 1E38
270 LET I$ = STR$ (START)
280 LET N = VAL ( LEFT$ (I$,1) + STR$ (START - INT (START / B) * B))
290 LET GAPFUL = START - INT (START / N) * N = 0
300 IF GAPFUL THEN GOSUB 370"PRINT GAPFUL"
310 IF C = COUNT THEN RETURN
320 NEXT START
330 STOP
340 LET M$ = CHR$ (13)
350 PRINT M$"FIRST "COUNT" ";
360 PRINT "GAPFUL NUMBERS >=";
370 LET C = C + 1
380 LET B = 10
390 LET P$ = ""
400 FOR P = START TO 0 STEP 0
410 LET Q = INT (P / B)
420 LET P$ = STR$ (P - Q * B) + P$
430 LET P = Q
440 NEXT P
450 PRINT MID$(M$ + " " + P$, 2 - (POS(0) + LEN(P$) + 1 > PEEK(33))) ;
460 RETURN</syntaxhighlight>
 
==={{header|BASIC256}}===
{{trans|Yabasic}}
<langsyntaxhighlight BASIC256lang="basic256">function is_gapful(n)
m = n
l = n mod 10
Line 258 ⟶ 425:
subroutine muestra_gapful(n, gaps)
inc = 0
print "PrimerosFirst "; gaps; " números gapful numbers >= "; n
while inc < gaps
if n mod is_gapful(n) = 0 then
Line 273 ⟶ 440:
call muestra_gapful(1000000000, 10)
call muestra_gapful(7123,25)
end</langsyntaxhighlight>
{{out}}
<pre>Same as FreeBASIC entry.</pre>
 
==={{header|Chipmunk Basic}}===
{{works with|Chipmunk Basic|3.6.4}}
{{trans|FreeBASIC}}
<syntaxhighlight lang="qbasic">100 muestragapful(100,30)
110 muestragapful(1000000,15)
120 muestragapful(1000000000,10)
130 muestragapful(7123,25)
140 end
150 function isgapful(n)
160 m = n
170 l = n mod 10
180 while (m >= 10)
190 m = int(m/10)
200 wend
210 isgapful = (m*10)+l
220 end function
230 sub muestragapful(n,gaps)
240 inc = 0
250 print "First ";gaps;" gapful numbers >= ";n
260 while inc < gaps
270 if n mod isgapful(n) = 0 then
280 print " ";n;
290 inc = inc+1
300 endif
310 n = n+1
320 wend
330 print chr$(10)
340 end sub</syntaxhighlight>
{{out}}
<pre>Same as FreeBASIC entry.</pre>
 
==={{header|Commodore BASIC}}===
{{trans|Clojure}}
Numbers >= 1,000,000,000 are printed out in scientific notation and we can't see what they actually are, so I used 100,000,000 instead.
 
<syntaxhighlight lang="basic">100 DEF FNFD(N) = VAL(MID$(STR$(N),2,1))
110 DEF FNLD(N) = N - 10 * INT(N/10)
120 DEF FNBE(N) = 10 * FNFD(N) + FNLD(N)
130 DEF FNGF(N) = (N >= 100) AND (N - FNBE(N)*INT(N/FNBE(N)) = 0)
140 READ S:IF S<0 THEN 260
150 READ C
160 PRINT"THE FIRST"C"GAPFUL NUMBERS >="S":"
170 I=S:F=0
180 IF NOT FNGF(I) THEN 220
190 PRINT I,
200 F=F+1
210 IF F>=C THEN 240
220 I=I+1
230 GOTO 180
240 PRINT:PRINT
250 GOTO 140
260 END
270 DATA 1,30, 1000000,15, 100000000,10
280 DATA -1</syntaxhighlight>
 
{{Out}}
<pre>THE FIRST 30 GAPFUL NUMBERS >= 1 :
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
 
THE FIRST 15 GAPFUL NUMBERS >= 1000000 :
1000000 1000005 1000008 1000010
1000016 1000020 1000021 1000030
1000032 1000034 1000035 1000040
1000050 1000060 1000065
 
THE FIRST 10 GAPFUL NUMBERS >= 100000000 :
100000000 100000005
100000008 100000010
100000016 100000020
100000021 100000030
100000032 100000035</pre>
 
==={{header|FreeBASIC}}===
<syntaxhighlight lang="freebasic">
function is_gapful( n as uinteger ) as boolean
if n<100 then return false
dim as string ns = str(n)
dim as uinteger gap = 10*val(mid(ns,1,1)) + val(mid(ns,len(ns),1))
if n mod gap = 0 then return true else return false
end function
 
dim as ulongint i = 100
dim as ushort c
print "The first thirty gapful numbers:"
while c<30
if is_gapful(i) then
c += 1
print i;" ";
end if
i += 1
wend
print : print
i = 1000000 : c = 0
print "The first fifteen gapful numbers above 999,999:"
while c<15
if is_gapful(i) then
c += 1
print i;" ";
end if
i += 1
wend
print : print
i = 1000000000 : c = 0
print "The first ten gapful numbers above 999,999,999:"
while c<10
if is_gapful(i) then
c += 1
print i;" ";
end if
i += 1
wend
print</syntaxhighlight>
{{out}}
<pre>
The first thirty gapful numbers:
Igual que la entrada de Yabasic.
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
 
The first fifteen gapful numbers above 999,999
1000000 1000005 1000008 1000010 1000016 1000020 1000021 1000030 1000032 1000034 1000035 1000040 1000050 1000060 1000065
 
The first ten gapful numbers above 999,999,999
1000000000 1000000001 1000000005 1000000008 1000000010 1000000016 1000000020 1000000027 1000000030 1000000032
</pre>
 
==={{header|FutureBasic}}===
<syntaxhighlight lang="futurebasic">
include "NSLog.incl"
 
_0 = 48 // ASCII code for 0 = 48
 
void local fn GenerateGaps( start as UInt64, count as NSInteger )
NSInteger counter = 0
UInt64 i = start
NSLog( @"First %d Gapful numbers >= %llu:", count, start )
while ( counter < count )
CFStringRef string = fn StringWithFormat( @"%llu", i )
UniChar character = fn StringCharacterAtIndex( string, 0 )
if( ( i mod ( 10 * ( character - _0 ) + i mod 10 ) ) == 0 )
NSLog( @"%3d : %llu", counter + 1, i )
counter++
end if
i++
wend
end fn
 
local fn DoIt
fn generateGaps( 100, 30 ) : NSLog( @"\n" )
fn generateGaps( 1000000, 15 ) : NSLog( @"\n" )
fn generateGaps( 1000000000, 15 ) : NSLog( @"\n" )
end fn
 
fn DoIt
 
HandleEvents
</syntaxhighlight>
{{output}}
<pre>
First 30 Gapful numbers >= 100:
1 : 100
2 : 105
3 : 108
4 : 110
5 : 120
6 : 121
7 : 130
8 : 132
9 : 135
10 : 140
11 : 143
12 : 150
13 : 154
14 : 160
15 : 165
16 : 170
17 : 176
18 : 180
19 : 187
20 : 190
21 : 192
22 : 195
23 : 198
24 : 200
25 : 220
26 : 225
27 : 231
28 : 240
29 : 242
30 : 253
 
First 15 Gapful numbers >= 1000000:
1 : 1000000
2 : 1000005
3 : 1000008
4 : 1000010
5 : 1000016
6 : 1000020
7 : 1000021
8 : 1000030
9 : 1000032
10 : 1000034
11 : 1000035
12 : 1000040
13 : 1000050
14 : 1000060
15 : 1000065
 
First 15 Gapful numbers >= 1000000000:
1 : 1000000000
2 : 1000000001
3 : 1000000005
4 : 1000000008
5 : 1000000010
6 : 1000000016
7 : 1000000020
8 : 1000000027
9 : 1000000030
10 : 1000000032
11 : 1000000035
12 : 1000000039
13 : 1000000040
14 : 1000000050
15 : 1000000053
</pre>
 
==={{header|Gambas}}===
{{trans|FreeBASIC}}
<syntaxhighlight lang="vbnet">Public Sub Main()
muestraGapful(100, 30)
muestraGapful(1000000, 15)
muestraGapful(1000000000, 10)
muestraGapful(7123, 25)
End
 
Function isGapful(n As Integer) As Integer
Dim m As Integer = n, l As Integer = n Mod 10
 
While (m >= 10)
m \= 10 'm = Int(m / 10)
Wend
Return (m * 10) + l
End Function
 
Sub muestraGapful(n As Integer, gaps As Integer)
Dim incr As Integer = 0
 
Print "First "; gaps; " gapful numbers >= "; n; ": "
While incr < gaps
If n Mod isGapful(n) = 0 Then
Print n; " ";
Inc incr '+= 1
End If
n += 1
Wend
Print Chr(10)
End Sub</syntaxhighlight>
{{out}}
<pre>Same as FreeBASIC entry.</pre>
 
==={{header|GW-BASIC}}===
{{works with|Chipmunk Basic}}
{{works with|PC-BASIC|any}}
{{works with|QBasic}}
<syntaxhighlight lang="qbasic">100 CLS
110 N = 100 : GAPS = 30 : GOSUB 230
120 N = 10000 : GAPS = 15 : GOSUB 230
130 N = 7123 : GAPS = 25 : GOSUB 230
140 END
150 REM isgapful(n)
160 M = N
170 L = N MOD 10
180 WHILE (M >= 10)
190 M = INT(M/10)
200 WEND
210 ISGAPFUL = (M*10)+L
220 RETURN 'end function
230 REM muestragapful(n,gaps)
240 INC = 0
250 PRINT "First "; GAPS; " gapful numbers >= "; N
260 WHILE INC < GAPS
270 GOSUB 150
280 IF N MOD ISGAPFUL = 0 THEN PRINT " "; N; : INC = INC + 1
290 N = N+1
300 WEND
310 PRINT CHR$(10)
320 RETURN</syntaxhighlight>
 
==={{header|PureBasic}}===
<syntaxhighlight lang="purebasic">Procedure.b isGapNum(n.i)
n1.i=n%10
n2.i=Val(Left(Str(n),1))
If n%(n2*10+n1)=0
ProcedureReturn #True
Else
ProcedureReturn #False
EndIf
EndProcedure
 
Procedure PutGapNum(start.i,rep.i,lfi.i=10)
n.i=start
While rep
If isGapNum(n)
Print(Str(n)+" ")
rep-1
If rep%lfi=0 : PrintN("") : EndIf
EndIf
n+1
Wend
EndProcedure
 
OpenConsole()
PrintN("First 30 gapful numbers ≥ 100:")
PutGapNum(100,30)
PrintN(~"\nFirst 15 gapful numbers ≥ 1,000,000:")
PutGapNum(1000000,15,5)
PrintN(~"\nFirst 10 gapful numbers ≥ 1,000,000,000:")
PutGapNum(1000000000,10,5)
Input()</syntaxhighlight>
{{out}}
<pre>First 30 gapful numbers ≥ 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 ≥ 1,000,000:
1000000 1000005 1000008 1000010 1000016
1000020 1000021 1000030 1000032 1000034
1000035 1000040 1000050 1000060 1000065
 
First 10 gapful numbers ≥ 1,000,000,000:
1000000000 1000000001 1000000005 1000000008 1000000010
1000000016 1000000020 1000000027 1000000030 1000000032</pre>
 
==={{header|QBasic}}===
{{works with|QBasic|1.1}}
{{works with|QuickBasic|4.5}}
{{trans|FreeBASIC}}
<syntaxhighlight lang="qbasic">FUNCTION isGapful (n)
m = n
l = n MOD 10
WHILE (m >= 10)
m = INT(m / 10)
WEND
isGapful = (m * 10) + l
END FUNCTION
 
SUB muestraGapful (n, gaps)
inc = 0
PRINT "First "; gaps; "gapful numbers >= "; n; ":"
WHILE inc < gaps
IF n MOD isGapful(n) = 0 THEN
PRINT ; n; " ";
inc = inc + 1
END IF
n = n + 1
WEND
PRINT CHR$(10)
END SUB
 
CALL muestraGapful(100, 30)
CALL muestraGapful(1000000, 15)
CALL muestraGapful(1000000000, 10)
CALL muestraGapful(7123, 25)</syntaxhighlight>
 
==={{header|Run BASIC}}===
{{works with|Just BASIC}}
{{works with|Liberty BASIC}}
{{trans|BASIC256}}
<syntaxhighlight lang="vb">call muestraGapful 100, 30
call muestraGapful 1000000, 15
call muestraGapful 1000000000, 10
call muestraGapful 7123,25
end
 
function isGapful(n)
m = n
l = n mod 10
while (m >= 10)
m = int(m / 10)
wend
isGapful = (m * 10) + l
end function
 
sub muestraGapful n, gaps
inc = 0
print
print "First "; gaps; " gapful numbers >= "; n
while inc < gaps
if n mod isGapful(n) = 0 then
print " " ; n ;
inc = inc + 1
end if
n = n + 1
wend
print
end sub</syntaxhighlight>
 
==={{header|True BASIC}}===
{{trans|QBasic}}
<syntaxhighlight lang="qbasic">FUNCTION isgapful(n)
LET m = n
LET l = remainder(n,10)
DO WHILE (m >= 10)
LET m = INT(m/10)
LOOP
LET isgapful = (m*10)+l
END FUNCTION
 
SUB muestragapful (n,gaps)
LET inc = 0
PRINT
PRINT "First"; gaps; "gapful numbers >="; n
DO WHILE inc < gaps
IF remainder(n, isgapful(n)) = 0 THEN
PRINT ; n; " ";
LET inc = inc+1
END IF
LET n = n+1
LOOP
PRINT
END SUB
 
CALL muestragapful (100, 30)
CALL muestragapful (1000000, 15)
CALL muestragapful (1000000000, 10)
CALL muestragapful (7123, 25)
END</syntaxhighlight>
 
==={{header|Visual Basic .NET}}===
{{trans|C#}}
<syntaxhighlight lang="vbnet">Module Module1
 
Function FirstNum(n As Integer) As Integer
REM Divide by ten until the leading digit remains.
While n >= 10
n /= 10
End While
Return n
End Function
 
Function LastNum(n As Integer) As Integer
REM Modulo gives you the last digit.
Return n Mod 10
End Function
 
Sub FindGap(n As Integer, gaps As Integer)
Dim count = 0
While count < gaps
Dim i = FirstNum(n) * 10 + LastNum(n)
 
REM Modulo with our new integer and output the result.
If n Mod i = 0 Then
Console.Write("{0} ", n)
count += 1
End If
 
n += 1
End While
Console.WriteLine()
Console.WriteLine()
End Sub
 
Sub Main()
Console.WriteLine("The first 30 gapful numbers are: ")
FindGap(100, 30)
 
Console.WriteLine("The first 15 gapful numbers > 1,000,000 are: ")
FindGap(1000000, 15)
 
Console.WriteLine("The first 10 gapful numbers > 1,000,000,000 are: ")
FindGap(1000000000, 10)
End Sub
 
End Module</syntaxhighlight>
{{out}}
<pre>The first 30 gapful numbers are:
100 105 108 110 120 121 130 132 135 140 143 156 160 168 175 180 200 220 225 231 240 242 253 270 300 315 330 341 360 400
 
The first 15 gapful numbers > 1,000,000 are:
1000000 1000005 1000008 1000010 1000016 1000020 1000021 1000030 1000032 1000034 1000035 1000040 1000050 1000060 1000065
 
The first 10 gapful numbers > 1,000,000,000 are:
1000000000 1000000001 1000000005 1000000008 1000000010 1000000016 1000000020 1000000027 1000000030 1000000032</pre>
 
==={{header|Yabasic}}===
<syntaxhighlight lang="yabasic">sub is_gapful(n)
m = n
l = mod(n, 10)
while (m >= 10)
m = int(m / 10)
wend
return (m * 10) + l
end sub
 
sub muestra_gapful(n, gaps)
inc = 0
print "Primeros ", gaps, " numeros gapful >= ", n
while inc < gaps
if mod(n, is_gapful(n)) = 0 then
print " " , n ,
inc = inc + 1
end if
n = n + 1
wend
print chr$(10)
end sub
 
muestra_gapful(100, 30)
muestra_gapful(1000000, 15)
muestra_gapful(1000000000, 10)
muestra_gapful(7123,25)
end</syntaxhighlight>
{{out}}
<pre>
Primeros 30 numeros gapful >= 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
 
Primeros 15 numeros gapful >= 1000000
1000000 1000005 1000008 1000010 1000016 1000020 1000021 1000030 1000032 1000034 1000035 1000040 1000050 1000060 1000065
 
Primeros 10 numeros gapful >= 1000000000
1000000000 1000000001 1000000005 1000000008 1000000010 1000000016 1000000020 1000000027 1000000030 1000000032
 
Primeros 25 numeros gapful >= 7123
7125 7140 7171 7189 7210 7272 7275 7280 7296 7350 7373 7420 7425 7474 7488 7490 7560 7575 7630 7632 7676 7700 7725 7770 7777
 
---Program done, press RETURN---</pre>
 
=={{header|C}}==
<syntaxhighlight lang="c">
<lang C>
#include<stdio.h>
 
Line 317 ⟶ 1,023:
return 0;
}
</syntaxhighlight>
</lang>
{{out}}
Output :
<pre>First 30 Gapful numbers >= 100 :
<pre>
abhishek_ghosh@Azure:~/doodles$ ./a.out
 
First 30 Gapful numbers >= 100 :
 
1 : 100
Line 393 ⟶ 1,096:
 
=={{header|C++}}==
<langsyntaxhighlight lang="cpp">#include <iostream>
 
bool gapful(int n) {
Line 420 ⟶ 1,123:
show_gapful_numbers(1000000000, 10);
return 0;
}</langsyntaxhighlight>
 
{{out}}
<pre>First 30 gapful numbers >= 100:
<pre>
First 30 gapful numbers >= 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 >= 1000000:
1000000, 1000005, 1000008, 1000010, 1000016, 1000020, 1000021, 1000030, 1000032, 1000034, 1000035, 1000040, 1000050, 1000060, 1000065
First 10 gapful numbers >= 1000000000:
1000000000, 1000000001, 1000000005, 1000000008, 1000000010, 1000000016, 1000000020, 1000000027, 1000000030, 1000000032</pre>
</pre>
 
=={{header|C#}}==
<langsyntaxhighlight lang="csharp">
using System;
 
Line 497 ⟶ 1,197:
}
}
}</syntaxhighlight>
}
 
 
</lang>
{{out}}
<pre>The first 30 gapful numbers are:
<pre>
The first 30 gapful numbers are:
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
 
Line 510 ⟶ 1,206:
 
The first 10 gapful numbers > 1,000,000,000 are:
1000000000 1000000001 1000000005 1000000008 1000000010 1000000016 1000000020 1000000027 1000000030 1000000032</pre>
</pre>
 
 
=={{header|Clojure}}==
<langsyntaxhighlight lang="clojure">(defn first-digit [n] (Integer/parseInt (subs (str n) 0 1)))
 
(defn last-digit [n] (mod n 10))
Line 535 ⟶ 1,229:
""])))
 
(doall (map report-range [ [1 30] [1000000 15] [1000000000 10] ]))</langsyntaxhighlight>
 
{{Out}}
 
<pre>First 30 gapful numbers >= 1:
(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)
Line 552 ⟶ 1,244:
numbers have to be on separate lines.
 
<langsyntaxhighlight lang="cobol"> IDENTIFICATION DIVISION.
PROGRAM-ID. GAPFUL.
Line 599 ⟶ 1,291:
ADD 1 TO N.
IF GAP-AMOUNT IS GREATER THAN 0
GO TO CHECK-GAPFUL-NUMBER.</langsyntaxhighlight>
{{out}}
<pre style='height: 50ex;'>First 30 gapful numbers >= 100:
Line 662 ⟶ 1,354:
1000000032
</pre>
 
=={{header|Commodore BASIC}}==
{{trans|Clojure}}
 
Numbers >= 1,000,000,000 are printed out in scientific notation and we can't see what they actually are, so I used 100,000,000 instead.
 
<lang basic>100 DEF FNFD(N) = VAL(MID$(STR$(N),2,1))
110 DEF FNLD(N) = N - 10 * INT(N/10)
120 DEF FNBE(N) = 10 * FNFD(N) + FNLD(N)
130 DEF FNGF(N) = (N >= 100) AND (N - FNBE(N)*INT(N/FNBE(N)) = 0)
140 READ S:IF S<0 THEN 260
150 READ C
160 PRINT"THE FIRST"C"GAPFUL NUMBERS >="S":"
170 I=S:F=0
180 IF NOT FNGF(I) THEN 220
190 PRINT I,
200 F=F+1
210 IF F>=C THEN 240
220 I=I+1
230 GOTO 180
240 PRINT:PRINT
250 GOTO 140
260 END
270 DATA 1,30, 1000000,15, 100000000,10
280 DATA -1</lang>
 
{{Out}}
<pre>THE FIRST 30 GAPFUL NUMBERS >= 1 :
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
 
THE FIRST 15 GAPFUL NUMBERS >= 1000000 :
 
1000000 1000005 1000008 1000010
1000016 1000020 1000021 1000030
1000032 1000034 1000035 1000040
1000050 1000060 1000065
 
THE FIRST 10 GAPFUL NUMBERS >= 100000000 :
100000000 100000005
100000008 100000010
100000016 100000020
100000021 100000030
100000032 100000035</pre>
 
=={{header|Common Lisp}}==
{{trans|Clojure}}
<langsyntaxhighlight lang="lisp">(defun first-digit (n) (parse-integer (string (char (write-to-string n) 0))))
 
(defun last-digit (n) (mod n 10))
Line 735 ⟶ 1,377:
(gapfuls-in-range start size))))
 
(mapcar #'report-range '((1 30) (1000000 15) (1000000000 10)))</syntaxhighlight>
</lang>
 
{{Out}}
 
<pre>The first 30 gapful numbers >= 1:
Line 756 ⟶ 1,395:
{{trans|Ruby}}
With lazy iterator
<langsyntaxhighlight lang="ruby">struct Int
def gapful?
a = self.to_s.chars.map(&.to_i)
Line 768 ⟶ 1,407:
puts "first #{count} gapful numbers >= #{start}:"
puts (start..).each.select(&.gapful?).first(count).to_a, "\n"
end</langsyntaxhighlight>
 
Alternative
<langsyntaxhighlight lang="ruby">struct Int
def gapful?
a = self.to_s.chars.map(&.to_i)
Line 785 ⟶ 1,424:
(start..).each { |n| n.gapful? && (gapful << n; i += 1); break if i == count }
puts gapful, "\n"
end</langsyntaxhighlight>
{{out}}
<pre>first 30 gapful numbers >= 100:
Line 801 ⟶ 1,440:
=={{header|D}}==
{{trans|Go}}
<langsyntaxhighlight lang="d">import std.conv;
import std.stdio;
 
Line 842 ⟶ 1,481:
writeln("\n");
}
}</langsyntaxhighlight>
{{out}}
<pre>First 30 gapful numbers starting at 100:
Line 858 ⟶ 1,497:
First 25 gapful numbers starting at 7,123:
7125 7140 7171 7189 7210 7272 7275 7280 7296 7350 7373 7420 7425 7474 7488 7490 7560 7575 7630 7632 7676 7700 7725 7770 7777</pre>
 
=={{header|Delphi}}==
See [https://rosettacode.org/wiki/Gapful_numbers#Pascal Pascal].
 
=={{header|EasyLang}}==
<syntaxhighlight>
func gapful n .
m = n
l = n mod 10
while m >= 10
m = m div 10
.
return if n mod (m * 10 + l) = 0
.
proc show n gaps . .
print "First " & gaps & " gapful numbers >= " & n
while inc < gaps
if gapful n = 1
write n & " "
inc += 1
.
n += 1
.
print ""
print ""
.
show 100 30
show 1000000 15
show 1000000000 10
</syntaxhighlight>
{{out}}
<pre>
First 30 gapful numbers >= 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 >= 1000000
1000000 1000005 1000008 1000010 1000016 1000020 1000021 1000030 1000032 1000034 1000035 1000040 1000050 1000060 1000065
 
First 10 gapful numbers >= 1000000000
1000000000 1000000001 1000000005 1000000008 1000000010 1000000016 1000000020 1000000027 1000000030 1000000032
</pre>
 
=={{header|Elixir}}==
<syntaxhighlight lang="elixir">
def gapful(st,se,n) do
gp=for g <- st..se, d=Integer.undigits([List.first(Integer.digits(g)),List.last(Integer.digits(g))]),Integer.mod(g,d)==0, do: g
Enum.take(gp,n)
end
iex(2)> Rosetta.gapful(101,500,30)
[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, 260]
iex(3)> Rosetta.gapful(1000000,1000500,15)
[1000000, 1000005, 1000008, 1000010, 1000016, 1000020, 1000021, 1000030,
1000032, 1000034, 1000035, 1000040, 1000050, 1000060, 1000065]
iex(4)> Rosetta.gapful(1000000000,1000000500,10)
[1000000000, 1000000001, 1000000005, 1000000008, 1000000010, 1000000016,
1000000020, 1000000027, 1000000030, 1000000032]
</syntaxhighlight>
 
=={{header|Erlang}}==
Line 867 ⟶ 1,565:
 
The gapfulness implementation:
<langsyntaxhighlight lang="erlang">-module(gapful).
-export([first_digit/1, last_digit/1, bookend_number/1, is_gapful/1]).
 
Line 877 ⟶ 1,575:
bookend_number(N) -> 10 * first_digit(N) + last_digit(N).
 
is_gapful(N) -> (N >= 100) and (0 == N rem bookend_number(N)).</langsyntaxhighlight>
 
The streams implementation:
<langsyntaxhighlight lang="erlang">-module(stream).
-export([yield/1, naturals/0, naturals/1, filter/2, take/2, to_list/1]).
 
Line 918 ⟶ 1,616:
{X, Xs} -> to_list(Xs, [X|Acc]);
halt -> lists:reverse(Acc)
end.</langsyntaxhighlight>
 
The main program that puts them together:
 
<langsyntaxhighlight lang="erlang">-module(gapful_demo).
-mode(compile).
 
report_range([Start, Size]) ->
main(_) ->
io:fwrite("The first ~w gapful numbers >= ~w:~n~w~n~n", [Size, Start,
lists:map(
stream:to_list(stream:take(Size, stream:filter(fun gapful:is_gapful/1,
fun([Start,Size]) ->
stream:naturals(Start))))]).
io:fwrite("~w~n",
[stream:to_list(stream:take(Size, stream:filter(fun gapful:is_gapful/1, stream:naturals(Start))))]) end,
[ [100,30], [1000000,15], [1000000000,10] ]).</lang>
 
main(_) -> lists:map(fun report_range/1, [[1,30],[1000000,15],[1000000000,10]]).</syntaxhighlight>
{{Out}}
<pre>The first 30 gapful numbers >= 1:
<pre>[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]
[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]
 
The first 15 gapful numbers >= 1000000:
[1000000,1000005,1000008,1000010,1000016,1000020,1000021,1000030,1000032,1000034,1000035,1000040,1000050,1000060,1000065]
 
[1000000000,1000000001,1000000005,1000000008,1000000010,1000000016,1000000020,1000000027,1000000030,1000000032]</pre>
The first 10 gapful numbers >= 1000000000:
[1000000000,1000000001,1000000005,1000000008,1000000010,1000000016,1000000020,1000000027,1000000030,1000000032]
</pre>
 
=={{header|Factor}}==
<langsyntaxhighlight lang="factor">USING: formatting kernel lists lists.lazy math math.functions
math.text.utils sequences ;
 
Line 946 ⟶ 1,650:
2dup lfrom [ gapful? ] lfilter ltake list>array
"%d gapful numbers starting at %d:\n%[%d, %]\n\n" printf
] 2tri@</langsyntaxhighlight>
{{out}}
<pre>
Line 961 ⟶ 1,665:
=={{header|Forth}}==
Developed with Gforth 0.7.9
<langsyntaxhighlight lang="forth">variable cnt
: Int>Str s>d <# #s #> ;
: firstDigit C@ [char] 0 - ;
Line 981 ⟶ 1,685:
1000000 15 main cr
1000000000 10 main cr
</syntaxhighlight>
</lang>
{{out}}
<pre>
Line 1,042 ⟶ 1,746:
9 : 1000000030
10 : 1000000032
</pre>
 
=={{header|FreeBASIC}}==
<lang freebasic>
function is_gapful( n as uinteger ) as boolean
if n<100 then return false
dim as string ns = str(n)
dim as uinteger gap = 10*val(mid(ns,1,1)) + val(mid(ns,len(ns),1))
if n mod gap = 0 then return true else return false
end function
 
dim as ulongint i = 100
dim as ushort c
print "The first thirty gapful numbers:"
while c<30
if is_gapful(i) then
c += 1
print i;" ";
end if
i += 1
wend
print : print
i = 1000000 : c = 0
print "The first fifteen gapful numbers above 999,999:"
while c<15
if is_gapful(i) then
c += 1
print i;" ";
end if
i += 1
wend
print : print
i = 1000000000 : c = 0
print "The first ten gapful numbers above 999,999,999:"
while c<10
if is_gapful(i) then
c += 1
print i;" ";
end if
i += 1
wend
print</lang>
{{out}}
<pre>
The first thirty gapful numbers:
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
 
The first fifteen gapful numbers above 999,999
1000000 1000005 1000008 1000010 1000016 1000020 1000021 1000030 1000032 1000034 1000035 1000040 1000050 1000060 1000065
 
The first ten gapful numbers above 999,999,999
1000000000 1000000001 1000000005 1000000008 1000000010 1000000016 1000000020 1000000027 1000000030 1000000032
</pre>
 
=={{header|Frink}}==
<langsyntaxhighlight lang="frink">
// Create function to calculate gapful number
gapful[num,totalCounter] :=
Line 1,119 ⟶ 1,771:
num = num + 1
}
p
println[] // Linkbreak
rintln[] // Linkbreak
}
 
Line 1,126 ⟶ 1,782:
gapful[1000000,15]
gapful[1000000000,10]
</syntaxhighlight>
</lang>
 
{{out}}
<pre>
Line 1,139 ⟶ 1,794:
 
=={{header|Fōrmulæ}}==
{{FormulaeEntry|page=https://formulae.org/?script=examples/Gapful_numbers}}
 
'''Solution'''
 
The following function return whether a given number is gapful or not
 
[[File:Fōrmulæ - Gapful numbers 01.png]]
 
The following function shows gapful numbers from a given value:
 
[[File:Fōrmulæ - Gapful numbers 02.png]]
 
'''Test case 1''' Show the first 30 gapful numbers
 
[[File:Fōrmulæ - Gapful numbers 03.png]]
 
[[File:Fōrmulæ - Gapful numbers 04.png]]
 
'''Test case 2''' Show the first 15 gapful numbers ≥ 1,000,000
 
[[File:Fōrmulæ - Gapful numbers 05.png]]
 
[[File:Fōrmulæ - Gapful numbers 06.png]]
 
'''Test case 3''' Show the first 10 gapful numbers ≥ 1,000,000,000
In [https://wiki.formulae.org/Gapful_numbers this] page you can see the solution of this task.
 
[[File:Fōrmulæ - Gapful numbers 07.png]]
Fōrmulæ programs are not textual, visualization/edition of programs is done showing/manipulating structures but not text ([http://wiki.formulae.org/Editing_F%C5%8Drmul%C3%A6_expressions more info]). Moreover, there can be multiple visual representations of the same program. Even though it is possible to have textual representation &mdash;i.e. XML, JSON&mdash; they are intended for transportation effects more than visualization and edition.
 
[[File:Fōrmulæ - Gapful numbers 08.png]]
The option to show Fōrmulæ programs and their results is showing images. Unfortunately images cannot be uploaded in Rosetta Code.
 
=={{header|Go}}==
<langsyntaxhighlight lang="go">package main
 
import "fmt"
Line 1,187 ⟶ 1,865:
fmt.Println("\n")
}
}</langsyntaxhighlight>
 
{{out}}
<pre>
Line 1,206 ⟶ 1,883:
7125 7140 7171 7189 7210 7272 7275 7280 7296 7350 7373 7420 7425 7474 7488 7490 7560 7575 7630 7632 7676 7700 7725 7770 7777
</pre>
 
=={{header|Groovy}}==
{{trans|Java}}
<syntaxhighlight lang="groovy">class GapfulNumbers {
private static String commatize(long n) {
StringBuilder sb = new StringBuilder(Long.toString(n))
int le = sb.length()
for (int i = le - 3; i >= 1; i -= 3) {
sb.insert(i, ',')
}
return sb.toString()
}
 
static void main(String[] args) {
List<Long> starts = [(long) 1e2, (long) 1e6, (long) 1e7, (long) 1e9, (long) 7123]
List<Integer> counts = [30, 15, 15, 10, 25]
for (int i = 0; i < starts.size(); ++i) {
println("First ${counts.get(i)} gapful numbers starting at ${commatize(starts.get(i))}")
 
long j = starts.get(i)
long pow = 100
while (j >= pow * 10) {
pow *= 10
}
 
int count = 0
while (count < counts.get(i)) {
long fl = ((long) (j / pow)) * 10 + (j % 10)
if (j % fl == 0) {
print("$j ")
count++
}
if (++j >= 10 * pow) {
pow *= 10
}
}
 
println()
println()
}
}
}</syntaxhighlight>
{{out}}
<pre>First 30 gapful numbers starting at 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 starting at 1,000,000
1000000 1000005 1000008 1000010 1000016 1000020 1000021 1000030 1000032 1000034 1000035 1000040 1000050 1000060 1000065
 
First 15 gapful numbers starting at 10,000,000
10000000 10000001 10000003 10000004 10000005 10000008 10000010 10000016 10000020 10000030 10000032 10000035 10000040 10000050 10000060
 
First 10 gapful numbers starting at 1,000,000,000
1000000000 1000000001 1000000005 1000000008 1000000010 1000000016 1000000020 1000000027 1000000030 1000000032
 
First 25 gapful numbers starting at 7,123
7125 7140 7171 7189 7210 7272 7275 7280 7296 7350 7373 7420 7425 7474 7488 7490 7560 7575 7630 7632 7676 7700 7725 7770 7777 </pre>
 
=={{header|Haskell}}==
<langsyntaxhighlight lang="haskell">{-# LANGUAGE NumericUnderscores #-}
 
gapful :: Int -> Bool
Line 1,220 ⟶ 1,955:
putStrLn $ "\nFirst 15 Gapful numbers >= 1,000,000 :\n" ++ r 15 [1_000_000,1_000_001..]
putStrLn $ "\nFirst 10 Gapful numbers >= 1,000,000,000 :\n" ++ r 10 [1_000_000_000,1_000_000_001..]
where r n = show . take n . filter gapful</langsyntaxhighlight>
{{out}}
<pre>
Line 1,235 ⟶ 1,970:
 
Or, defining the predicate in applicative terms, and wrapping the output:
<syntaxhighlight lang ="haskell">import Data.List.Split (chunksOfintercalate)
import Data.List.Split (intercalatechunksOf)
 
---------------------- GAPFUL NUMBERS --------------------
 
----------------------- GAPFUL NUMBERS ---------------------
 
isGapful :: Int -> Bool
isGapful =
isGapful = (0 ==) . (<*>) rem (read . (<*>) [head, last] . pure . show)
(0 ==)
 
. (<*>)
rem
(read . (<*>) [head, last] . pure . show)
 
---------------------------- TEST --------------------------
main :: IO ()
main =
mapM_
(putStrLn . showSample)
[ "First 30 gapful numbers >= 100",
, "First 15 Gapful numbers >= 1000000",
, "First 10 Gapful numbers >= 1000000000"
]
 
Line 1,258 ⟶ 1,995:
showSample k =
let ws = words k
in k <> ":\n\n" <>
<> unlines
( fmap (intercalate ", " . fmap show) $
chunksOf 5 $ take (read (ws !! 1)) [read (ws !!chunksOf 5) :: Int ..])</lang>$
take
(read (ws !! 1))
[read (ws !! 5) :: Int ..]
)</syntaxhighlight>
{{Out}}
<pre>First 30 gapful numbers >= 100:
Line 1,284 ⟶ 2,025:
 
=={{header|J}}==
<syntaxhighlight lang="text">
gapful =: 0 = (|~ ({.,{:)&.(10&#.inv))
 
Line 1,292 ⟶ 2,033:
'The first ' , (": y) , ' gapful numbers exceeding ' , (":<:x) , ' are ' , (":gn)
)
</syntaxhighlight>
</lang>
{{out}}
<pre>
task 30
Line 1,303 ⟶ 2,045:
 
=={{header|Java}}==
 
{{trans|D}}
<langsyntaxhighlight lang="java">import java.util.List;
 
public class GapfulNumbers {
Line 1,342 ⟶ 2,083:
}
}
}</langsyntaxhighlight>
{{out}}
<pre>First 30 gapful numbers starting at 100:
Line 1,362 ⟶ 2,103:
===Windows command line version===
{{works with|Windows Script Host}}
<langsyntaxhighlight lang="javascript">// Function to construct a new integer from the first and last digits of another
function gapfulness_divisor (number) {
var digit_string = number.toString(10)
Line 1,417 ⟶ 2,158:
print_gapfuls_with_header(100, 30)
print_gapfuls_with_header(1000000, 15)
print_gapfuls_with_header(1000000000, 10)</langsyntaxhighlight>
 
{{Output}}
<pre>First 100 gapful numbers starting at 30
Line 1,428 ⟶ 2,168:
 
===ES6===
<langsyntaxhighlight lang="javascript">(() => {
'use strict';
 
Line 1,635 ⟶ 2,375:
// MAIN ---
return main();
})();</langsyntaxhighlight>
{{Out}}
<pre>First 30 gapful numbers >= 100:
Line 1,656 ⟶ 2,396:
1000000000,1000000001,1000000005,1000000008,1000000010
1000000016,1000000020,1000000027,1000000030,1000000032</pre>
 
=={{header|jq}}==
The following program works with both jq and gojq; for very large integers, the latter should be used.
 
<syntaxhighlight lang="jq"># emit a stream of gapful numbers greater than or equal to $start,
# which is assumed to be an integer
def gapful($start):
range($start; infinite)
| . as $i
| tostring as $s
| (($s[:1] + $s[-1:]) | tonumber) as $x
| select($i % $x == 0);
 
"First 30 gapful numbersstarting from 100:",
([limit(30;gapful(100))] | join(" ")),
"First 15 gapful numbers starting from 1,000,000:",
([limit(15;gapful(1000000))] | join(" ")),
"First 10 gapful numbers starting from 10^9:",
([limit(10;gapful(pow(10;9)))] | join(" "))</syntaxhighlight>
{{out}}
<pre>First 30 gapful numbers starting from 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 starting from 1,000,000:
1000000 1000005 1000008 1000010 1000016 1000020 1000021 1000030 1000032 1000034 1000035 1000040 1000050 1000060 1000065
First 10 gapful numbers starting from 10^9:
1000000000 1000000001 1000000005 1000000008 1000000010 1000000016 1000000020 1000000027 1000000030 1000000032</pre>
 
=={{header|Julia}}==
<langsyntaxhighlight lang="julia">using Lazy, Formatting
 
firstlast(a) = 10 * a[end] + a[1]
Line 1,667 ⟶ 2,433:
println("First $n gapful numbers starting at ", format(x, commas=true), ":\n",
take(n, gapfuls(x)))
end</syntaxhighlight>
end
</lang>{{out}}
<pre>
First 30 gapful numbers starting at 100:
Line 1,680 ⟶ 2,446:
=={{header|Kotlin}}==
{{trans|Java}}
<langsyntaxhighlight lang="scala">private fun commatize(n: Long): String {
val sb = StringBuilder(n.toString())
val le = sb.length
Line 1,719 ⟶ 2,485:
println('\n')
}
}</langsyntaxhighlight>
{{out}}
<pre>First 30 gapful numbers starting at 100:
Line 1,737 ⟶ 2,503:
 
=={{header|Lambdatalk}}==
<syntaxhighlight lang="scheme">
<lang Scheme>
{def gapfuls
{lambda {:n :i :N}
Line 1,758 ⟶ 2,524:
-> 1000000000 1000000001 1000000005 1000000008 1000000010
1000000016 1000000020 1000000027 1000000030 1000000032
</syntaxhighlight>
</lang>
 
=={{header|Logo}}==
{{trans|Clojure}}
<langsyntaxhighlight lang="logo">to bookend_number :n
output sum product 10 first :n last :n
end
Line 1,789 ⟶ 2,555:
foreach [ [1 30] [1000000 15] [1000000000 10] ] [
apply "report_range ?
]</syntaxhighlight>
]
</lang>
 
{{Out}}
Line 1,804 ⟶ 2,569:
=={{header|LOLCODE}}==
{{trans|Clojure}}
<langsyntaxhighlight lang="lolcode">HAI 1.2
 
HOW IZ I FurstDigit YR Numbr
Line 1,850 ⟶ 2,615:
VISIBLE " Gapful numbrs starting with " !
VISIBLE Start !
VISIBLE "::"
I HAS A Anser ITZ I IZ FindGapfuls YR Start AN YR HowMany MKAY
IM IN YR Loop UPPIN YR Index TIL BOTH SAEM Index AN HowMany
Line 1,868 ⟶ 2,633:
I IZ Report YR 1000000000 AN YR 10 MKAY
KTHXBYE
</syntaxhighlight>
</lang>
 
{{Out}}
Line 1,883 ⟶ 2,648:
=={{header|Lua}}==
{{trans|C}}
<langsyntaxhighlight lang="lua">function generateGaps(start, count)
local counter = 0
local i = start
Line 1,907 ⟶ 2,672:
 
generateGaps(1000000000, 15)
print()</langsyntaxhighlight>
{{out}}
<pre>First 30 Gapful numbers >= 100 :
Line 1,976 ⟶ 2,741:
 
=={{header|Mathematica}} / {{header|Wolfram Language}}==
<langsyntaxhighlight Mathematicalang="mathematica">ClearAll[GapFulQ]
GapFulQ[n_Integer] := Divisible[n, FromDigits[IntegerDigits[n][[{1, -1}]]]]
i = 100;
Line 1,998 ⟶ 2,763:
i++
]
res</langsyntaxhighlight>
{{out}}
<pre>{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}
Line 2,006 ⟶ 2,771:
=={{header|min}}==
{{works with|min|0.19.6}}
<langsyntaxhighlight lang="min">(() 0 shorten) :new
(((10 mod) (10 div)) cleave) :moddiv
((dup 0 ==) (pop new) 'moddiv 'cons linrec) :digits
Line 2,028 ⟶ 2,793:
100 30 show-gapfuls newline
1000000 15 show-gapfuls newline
1000000000 10 show-gapfuls</langsyntaxhighlight>
{{out}}
<pre>
Line 2,042 ⟶ 2,807:
 
=={{header|newLISP}}==
<langsyntaxhighlight newLISPlang="newlisp">; Part 1: Useful functions
 
;; Create an integer out of the first and last digits of a given integer
Line 2,090 ⟶ 2,855:
(show-gapfuls 15 999999)
(show-gapfuls 10 999999999)
(exit)</langsyntaxhighlight>
 
{{out}}
<pre>The first 30 gapful numbers beyond 99 are:
Line 2,101 ⟶ 2,865:
 
=={{header|Nim}}==
<langsyntaxhighlight Nimlang="nim">import strutils
 
 
Line 2,141 ⟶ 2,905:
displayGapfulNumbers(100, 30)
displayGapfulNumbers(1_000_000, 15)
displayGapfulNumbers(1_000_000_000, 10)</langsyntaxhighlight>
 
{{out}}
<pre>
Line 2,153 ⟶ 2,916:
First 10 gapful numbers ⩾ 1000000000:
1000000000 1000000001 1000000005 1000000008 1000000010 1000000016 1000000020 1000000027 1000000030 1000000032</pre>
 
=={{header|OCaml}}==
<syntaxhighlight lang="ocaml">let rec first_digit x =
if x < 10 then x else first_digit (x / 10)
 
let is_gapful x =
x mod (10 * first_digit x + x mod 10) = 0
 
let fmt_seq x n =
Seq.(ints x |> filter is_gapful |> take n |> map string_of_int)
|> List.of_seq |> String.concat ", "
 
let () =
let fmt (x, n) =
Printf.printf "\nFirst %u gapful numbers from %u:\n%s\n" n x (fmt_seq x n)
in
List.iter fmt [100, 30; 1000000, 15; 1000000000, 10]</syntaxhighlight>
{{out}}
<pre>
First 30 gapful numbers from 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 from 1000000:
1000000, 1000005, 1000008, 1000010, 1000016, 1000020, 1000021, 1000030, 1000032, 1000034, 1000035, 1000040, 1000050, 1000060, 1000065
 
First 10 gapful numbers from 1000000000:
1000000000, 1000000001, 1000000005, 1000000008, 1000000010, 1000000016, 1000000020, 1000000027, 1000000030, 1000000032
</pre>
 
=={{header|Pascal}}==
Line 2,158 ⟶ 2,949:
Now using using en passant updated MOD-values.
Only recognizable for huge amounts of tests 100|74623687 ( up to 1 billion )-> takes 1.845s instead of 11.25s
<langsyntaxhighlight lang="pascal">program gapful;
 
 
Line 2,337 ⟶ 3,128:
end;
{$IFNDEF LINUX} readln; {$ENDIF}
end.</langsyntaxhighlight>
{{out}}
<pre style="font-size:80%">First 30, gapful numbers starting at 100
Line 2,363 ⟶ 3,154:
//100|7462360431 =>100*1000*1000*1000 </pre>
===only counting===
<langsyntaxhighlight lang="pascal">program gapful;
{$IFDEF FPC}
{$MODE DELPHI}{$OPTIMIZATION ON,ALL}
Line 2,457 ⟶ 3,248:
Main(10);
Main(100);
END.</langsyntaxhighlight>
{{out}}
<pre>Base :10
Line 2,488 ⟶ 3,279:
 
=={{header|Perl}}==
<langsyntaxhighlight lang="perl">use strict;
use warnings;
use feature 'say';
Line 2,503 ⟶ 3,294:
$g .= do { $n < $count ? (is_gapful($_) and ++$n and "$_ ") : last } for $start .. Inf;
say $g;
}</langsyntaxhighlight>
{{out}}
<pre>First 30 gapful numbers starting at 100:
Line 2,519 ⟶ 3,310:
=={{header|Phix}}==
{{trans|Go}}
<!--<langsyntaxhighlight Phixlang="phix">(phixonline)-->
<span style="color: #008080;">constant</span> <span style="color: #000000;">starts</span> <span style="color: #0000FF;">=</span> <span style="color: #0000FF;">{</span><span style="color: #000000;">1e2</span><span style="color: #0000FF;">,</span> <span style="color: #000000;">1e6</span><span style="color: #0000FF;">,</span> <span style="color: #000000;">1e7</span><span style="color: #0000FF;">,</span> <span style="color: #000000;">1e9</span><span style="color: #0000FF;">,</span> <span style="color: #000000;">7123</span><span style="color: #0000FF;">},</span>
<span style="color: #000000;">counts</span> <span style="color: #0000FF;">=</span> <span style="color: #0000FF;">{</span><span style="color: #000000;">30</span><span style="color: #0000FF;">,</span> <span style="color: #000000;">15</span><span style="color: #0000FF;">,</span> <span style="color: #000000;">15</span><span style="color: #0000FF;">,</span> <span style="color: #000000;">10</span><span style="color: #0000FF;">,</span> <span style="color: #000000;">25</span><span style="color: #0000FF;">}</span>
Line 2,541 ⟶ 3,332:
<span style="color: #7060A8;">printf</span><span style="color: #0000FF;">(</span><span style="color: #000000;">1</span><span style="color: #0000FF;">,</span><span style="color: #008000;">"\n"</span><span style="color: #0000FF;">)</span>
<span style="color: #008080;">end</span> <span style="color: #008080;">for</span>
<!--</langsyntaxhighlight>-->
{{out}}
<pre style="font-size: 10px">
Line 2,552 ⟶ 3,343:
 
=={{header|Plain English}}==
<langsyntaxhighlight lang="plainenglish">To run:
Start up.
Show the gapful numbers at various spots.
Line 2,599 ⟶ 3,390:
Show 15 of the gapful numbers starting from 1000000.
Write "10 gapful numbers starting at 1000000000:" on the console.
Show 10 of the gapful numbers starting from 1000000000.</langsyntaxhighlight>
{{out}}
<pre>
Line 2,612 ⟶ 3,403:
</pre>
 
=={{header|PureBasicPL/M}}==
This can be compiled with the original 8080 PL/M compiler and run under CP/M or a clone or emulator. Just shows the first 30 Gapful numbers >= 100, as the original 8080 PL/M only supports at most (unsigned) 16-bit numbers.
<lang PureBasic>Procedure.b isGapNum(n.i)
<syntaxhighlight lang="pli">100H: /* FIND SOME GAPFUL NUMBERS: NUMBERS DIVISIBLE BY 10F + L WHERE F IS */
n1.i=n%10
/* THE FIRST DIGIT AND L IS THE LAST DIGIT */
n2.i=Val(Left(Str(n),1))
BDOS: PROCEDURE( FN, ARG ); /* CP/M BDOS SYSTEM CALL */
If n%(n2*10+n1)=0
DECLARE FN BYTE, ARG ADDRESS;
ProcedureReturn #True
GOTO 5;
Else
END BDOS;
ProcedureReturn #False
PR$CHAR: PROCEDURE( C ); DECLARE C BYTE; CALL BDOS( 2, C ); END;
EndIf
PR$STRING: PROCEDURE( S ); DECLARE S ADDRESS; CALL BDOS( 9, S ); END;
EndProcedure
PR$NL: PROCEDURE; CALL PR$CHAR( 0DH ); CALL PR$CHAR( 0AH ); END;
PR$NUMBER: PROCEDURE( N );
DECLARE N ADDRESS;
DECLARE V ADDRESS, N$STR( 6 ) BYTE, W BYTE;
V = N;
W = LAST( N$STR );
N$STR( W ) = '$';
N$STR( W := W - 1 ) = '0' + ( V MOD 10 );
DO WHILE( ( V := V / 10 ) > 0 );
N$STR( W := W - 1 ) = '0' + ( V MOD 10 );
END;
CALL PR$STRING( .N$STR( W ) );
END PR$NUMBER;
/* RETURNS TRUE IF N IS GAPFUL, FALSE OTHERWISE */
IS$GAPFUL: PROCEDURE( N )BYTE;
DECLARE N ADDRESS;
DECLARE F ADDRESS;
F = N / 10;
DO WHILE ( F > 9 );
F = F / 10;
END;
RETURN N MOD ( ( F * 10 ) + ( N MOD 10 ) ) = 0;
END IS$GAPFUL;
/* FIND THE FIRST 30 GAPFUL NUMBERS >= 100 */
CALL PR$STRING( .'FIRST 30 GAPFUL NUMBERS STARTING FROM 100:$' );
CALL PR$NL;
DECLARE N ADDRESS, G$COUNT BYTE;
G$COUNT = 0;
N = 100;
DO WHILE ( G$COUNT < 30 );
IF IS$GAPFUL( N ) THEN DO;
/* HAVE A GAPFUL NUMBER */
G$COUNT = G$COUNT + 1;
CALL PR$CHAR( ' ' );
CALL PR$NUMBER( N );
END;
N = N + 1;
END;
CALL PR$NL;
 
EOF</syntaxhighlight>
Procedure PutGapNum(start.i,rep.i,lfi.i=10)
n.i=start
While rep
If isGapNum(n)
Print(Str(n)+" ")
rep-1
If rep%lfi=0 : PrintN("") : EndIf
EndIf
n+1
Wend
EndProcedure
 
OpenConsole()
PrintN("First 30 gapful numbers ≥ 100:")
PutGapNum(100,30)
PrintN(~"\nFirst 15 gapful numbers ≥ 1,000,000:")
PutGapNum(1000000,15,5)
PrintN(~"\nFirst 10 gapful numbers ≥ 1,000,000,000:")
PutGapNum(1000000000,10,5)
Input()</lang>
{{out}}
<pre>
<pre>First 30 gapful numbers ≥ 100:
FIRST 30 GAPFUL NUMBERS STARTING FROM 100:
100 105 108 110 120 121 130 132 135 140
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
</pre>
192 195 198 200 220 225 231 240 242 253
 
=={{header|PowerShell}}==
First 15 gapful numbers ≥ 1,000,000:
{{trans|Clojure}}
1000000 1000005 1000008 1000010 1000016
<syntaxhighlight lang="powershell">function Get-FirstDigit {
1000020 1000021 1000030 1000032 1000034
param ( [int] $Number )
1000035 1000040 1000050 1000060 1000065
[int]$Number.ToString().Substring(0,1)
}
 
function Get-LastDigit {
First 10 gapful numbers ≥ 1,000,000,000:
param ( [int] $Number )
1000000000 1000000001 1000000005 1000000008 1000000010
$Number % 10
1000000016 1000000020 1000000027 1000000030 1000000032</pre>
}
 
function Get-BookendNumber {
param ( [Int] $Number )
10 * (Get-FirstDigit $Number) + (Get-LastDigit $Number)
}
 
function Test-Gapful {
param ( [Int] $Number )
100 -lt $Number -and 0 -eq $Number % (Get-BookendNumber $Number)
}
 
function Find-Gapfuls {
param ( [Int] $Start, [Int] $Count )
$result = @()
 
While ($result.Count -lt $Count) {
If (Test-Gapful $Start) {
$result += @($Start)
}
$Start += 1
}
return $result
}
 
function Search-Range {
param ( [Int] $Start, [Int] $Count )
Write-Output "The first $Count gapful numbers >= $($Start):"
Write-Output( (Find-Gapfuls $Start $Count) -join ",")
Write-Output ""
}
 
Search-Range 1 30
Search-Range 1000000 15
Search-Range 1000000000 10
</syntaxhighlight>
{{Out}}
<pre>The first 30 gapful numbers >= 1:
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,260
 
The first 15 gapful numbers >= 1000000:
1000000,1000005,1000008,1000010,1000016,1000020,1000021,1000030,1000032,1000034,1000035,1000040,1000050,1000060,1000065
 
The first 10 gapful numbers >= 1000000000:
1000000000,1000000001,1000000005,1000000008,1000000010,1000000016,1000000020,1000000027,1000000030,1000000032
</pre>
 
=={{header|Python}}==
<langsyntaxhighlight lang="python">from itertools import islice, count
for start, n in [(100, 30), (1_000_000, 15), (1_000_000_000, 10)]:
print(f"\nFirst {n} gapful numbers from {start:_}")
print(list(islice(( x for x in count(start)
if (x % (int(str(x)[0]) * 10 + (x % 10)) == 0) )
, n)))</langsyntaxhighlight>
 
{{out}}
Line 2,676 ⟶ 3,535:
First 10 gapful numbers from 1_000_000_000
[1000000000, 1000000001, 1000000005, 1000000008, 1000000010, 1000000016, 1000000020, 1000000027, 1000000030, 1000000032]</pre>
 
=={{header|Quackery}}==
<syntaxhighlight lang="Quackery"> [ [ [] swap
[ 10 /mod
rot join swap
dup 0 = until ]
drop ] ] is digits ( n --> [ )
 
[ dup 100 < iff
[ drop false ] done
dup digits
dup 0 peek 10 *
swap -1 peek +
mod 0 = ] is gapful ( n --> b )
 
[ swap dup temp put
say "First "
echo
say " gapful numbers from "
dup echo cr
[] swap
[ dup gapful if
[ tuck join swap ]
1+
over size
temp share = until ]
drop
witheach [ echo sp ]
cr cr ] is task ( n n --> )
 
30 100 task
15 1000000 task
10 1000000000 task</syntaxhighlight>
{{out}}
<pre>First 30 gapful numbers from 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 from 1000000
1000000 1000005 1000008 1000010 1000016 1000020 1000021 1000030 1000032 1000034 1000035 1000040 1000050 1000060 1000065
 
First 10 gapful numbers from 1000000000
1000000000 1000000001 1000000005 1000000008 1000000010 1000000016 1000000020 1000000027 1000000030 1000000032
</pre>
 
=={{header|Raku}}==
Line 2,682 ⟶ 3,584:
Also test starting on a number that ''doesn't'' start with 1. Required to have titles, may as well make 'em noble. :-)
 
<syntaxhighlight lang="raku" perl6line>use Lingua::EN::Numbers;
 
for (1e2, 30, 1e6, 15, 1e9, 10, 7123, 25)».Int -> $start, $count {
Line 2,688 ⟶ 3,590:
<Sir Lord Duke King>.pick ~ ": ", ~
($start..*).grep( { $_ %% .comb[0, *-1].join } )[^$count];
}</langsyntaxhighlight>
{{out}}
<pre>First 30 gapful numbers starting at 100:
Line 2,703 ⟶ 3,605:
 
=={{header|REXX}}==
<langsyntaxhighlight lang="rexx">/*REXX program computes and displays a series of gapful numbers starting at some number.*/
numeric digits 20 /*ensure enough decimal digits gapfuls.*/
parse arg gapfuls /*obtain optional arguments from the CL*/
Line 2,720 ⟶ 3,622:
#= # + 1; $= $ j /*bump #; append ──► $ */
end /*j*/
say strip($); say; return</langsyntaxhighlight>
{{out|output|text=&nbsp; when using the default inputs:}}
 
Line 2,740 ⟶ 3,642:
 
=={{header|Ring}}==
<syntaxhighlight lang="ring">nr = 0
<lang Ring>
nr = 0
gapful1 = 99
gapful2 = 999999
Line 2,787 ⟶ 3,688:
see "" + nr + ". " + gapful3 + nl
ok
end</syntaxhighlight>
end
</lang>
{{out}}
<pre>
Line 2,798 ⟶ 3,697:
First 10 gapful numbers >= 1000000000:
1000000000, 1000000001, 1000000005, 1000000008, 1000000010, 1000000016, 1000000020, 1000000027, 1000000030, 1000000032
</pre>
 
=={{header|RPL}}==
The algorithm lies in the NXTGPF instruction, which provides the gapful number that follows the integer given as input. A significant part of the code is dedicated to display the title and to generate the required examples, within the UX/UI limits of RPL on a calculator emulator.
{{works with|Halcyon Calc|4.2.7}}
≪ DO
1 + DUP DUP DUP2
XPON ALOG / IP 10 * SWAP 10 MOD +
UNTIL MOD NOT END
'NXTGPF' STO
≪ → n from
≪ "1st " n →STR + " gapful # ≥ " + from →STR +
{ }
from 100 MAX 1 -
1 n FOR j
NXTGPF SWAP OVER + SWAP
NEXT
DROP
'GPFN' STO
 
30 1 GPFN
15 1000000 GPFN
10 1000000000 GPFN
{{out}}
<pre>
6: "1st 30 gapful # ≥ 1"
5: { 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 }
4: "1st 15 gapful # ≥ 1000000"
3: { 1000000 1000005 1000008 1000010 1000016 1000020 1000021 1000030 1000032 1000034 1000035 1000040 1000050 1000060 1000065 }
2: "1st 10 gapful # ≥ 1000000000"
1: { 1000000000 1000000001 1000000005 1000000008 1000000010 1000000016 1000000020 1000000027 1000000030 1000000032 }
</pre>
 
=={{header|Ruby}}==
<langsyntaxhighlight lang="ruby">class Integer
def gapful?
a = digits
Line 2,814 ⟶ 3,748:
p (start..).lazy.select(&:gapful?).take(num).to_a
end
</syntaxhighlight>
</lang>
{{out}}
<pre>first 30 gapful numbers >= 100:
Line 2,825 ⟶ 3,759:
[7125, 7140, 7171, 7189, 7210, 7272, 7275, 7280, 7296, 7350, 7373, 7420, 7425, 7474, 7488, 7490, 7560, 7575, 7630, 7632, 7676, 7700, 7725, 7770, 7777]
</pre>
 
=={{header|Scheme}}==
{{trans|Clojure}}
<syntaxhighlight lang="scheme">(define (first-digit n) (string->number (string (string-ref (number->string n) 0))))
(define (last-digit n) (modulo n 10))
(define (bookend-number n) (+ (* 10 (first-digit n)) (last-digit n)))
(define (gapful? n) (and (>= n 100) (zero? (modulo n (bookend-number n)))))
 
(define (gapfuls-in-range start size)
(let ((found 0) (result '()))
(do ((n start (+ n 1))) ((>= found size) (reverse result))
(if (gapful? n)
(begin (set! result (cons n result)) (set! found (+ found 1)))))))
 
(define (report-range range)
(apply (lambda (start size)
(newline)
(display "The first ")(display size)(display " gapful numbers >= ")
(display start)(display ":")(newline)
(display (gapfuls-in-range start size))(newline)) range))
 
(map report-range '((100 30) (1000000 15) (1000000000 10)))
</syntaxhighlight>
{{Out}}
<pre>The first 30 gapful numbers >= 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)
 
The first 15 gapful numbers >= 1000000:
(1000000 1000005 1000008 1000010 1000016 1000020 1000021 1000030 1000032 1000034 1000035 1000040 1000050 1000060 1000065)
 
The first 10 gapful numbers >= 1000000000:
(1000000000 1000000001 1000000005 1000000008 1000000010 1000000016 1000000020 1000000027 1000000030 1000000032)</pre>
 
=={{header|Sidef}}==
Concept extended to other bases:
<langsyntaxhighlight lang="ruby">func is_gapful(n, base=10) {
n.is_div(base*floor(n / base**n.ilog(base)) + n%base)
}
Line 2,843 ⟶ 3,809:
say sprintf("\n#{title} for base #{b}:", n, from.commify)
say (from..Inf -> lazy.grep{ is_gapful(_,b) }.first(n).join(' '))
})</langsyntaxhighlight>
{{out}}
<pre>
Line 2,862 ⟶ 3,828:
</pre>
 
=={{header|SwiftSQL}}==
{{works with|ORACLE 19c}}
This is not a particularly efficient solution, but it gets the job done.
 
<syntaxhighlight lang="sql">/*
<lang swift>func isGapful(n: Int) -> Bool {
This code is an implementation of gapful numbers in SQL ORACLE 19c
p_start -- start point
p_count -- total number to be found
*/
with
function gapful_numbers(p_start in integer, p_count in integer) return varchar2 is
v_start integer := p_start;
v_count integer := 0;
v_res varchar2(32767);
begin
v_res := 'First '||p_count||' gapful numbers starting from '||p_start||': ';
-- main cycle
while true loop
if mod(v_start,to_number(substr(v_start,1,1)||substr(v_start,-1))) = 0 then
v_res := v_res || v_start;
v_count := v_count + 1;
exit when v_count = p_count;
v_res := v_res || ', ';
end if;
v_start := v_start + 1;
end loop;
--
return v_res;
--
end;
 
--Test
select gapful_numbers(100,30) as res from dual
union all
select gapful_numbers(1000000,15) as res from dual
union all
select gapful_numbers(1000000000,10) as res from dual;
/</syntaxhighlight>
{{out}}
<pre>
First 30 gapful numbers starting from 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 starting from 1000000: 1000000, 1000005, 1000008, 1000010, 1000016, 1000020, 1000021, 1000030, 1000032, 1000034, 1000035, 1000040, 1000050, 1000060, 1000065
First 10 gapful numbers starting from 1000000000: 1000000000, 1000000001, 1000000005, 1000000008, 1000000010, 1000000016, 1000000020, 1000000027, 1000000030, 1000000032
</pre>
 
=={{header|Swift}}==
<syntaxhighlight lang="swift">func isGapful(n: Int) -> Bool {
guard n > 100 else {
return true
Line 2,881 ⟶ 3,891:
print("First 30 gapful numbers: \(Array(first30))")
print("First 15 >= 1,000,000: \(Array(mil))")
print("First 15 >= 1,000,000,000: \(Array(bil))")</langsyntaxhighlight>
 
{{out}}
 
<pre>First 30 gapful numbers: [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 >= 1,000,000: [1000000, 1000005, 1000008, 1000010, 1000016, 1000020, 1000021, 1000030, 1000032, 1000034, 1000035, 1000040, 1000050, 1000060, 1000065]
Line 2,890 ⟶ 3,898:
 
=={{header|Tcl}}==
<langsyntaxhighlight Tcllang="tcl">proc ungap n {
if {[string length $n] < 3} {
return $n
Line 2,920 ⟶ 3,928:
show 15 1000000
show 10 1000000000
</syntaxhighlight>
</lang>
{{out}}
The first 30 gapful >= 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
Line 2,929 ⟶ 3,937:
{{works with|Bourne Again Shell}}
{{trans|Clojure}}
<langsyntaxhighlight lang="bash">first-digit() {
printf '%s\n' "${1:0:1}"
}
Line 2,971 ⟶ 3,979:
}
 
report-ranges 1,30 1000000,15 1000000000,10</langsyntaxhighlight>
 
{{Out}}
 
<pre>The first 30 gapful numbers >= 1:
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
Line 2,985 ⟶ 3,991:
</pre>
 
=={{header|VisualV Basic .NET(Vlang)}}==
{{trans|C#go}}
<syntaxhighlight lang="v (vlang)">fn commatize(n u64) string {
<lang vbnet>Module Module1
mut s := n.str()
le := s.len
for i := le - 3; i >= 1; i -= 3 {
s = '${s[0..i]},$s[i..]'
}
return s
}
fn main() {
starts := [u64(1e2), u64(1e6), u64(1e7), u64(1e9), u64(7123)]
counts := [30, 15, 15, 10, 25]
for i in 0..starts.len {
mut count := 0
mut j := starts[i]
mut pow := u64(100)
for {
if j < pow*10 {
break
}
pow *= 10
}
println("First ${counts[i]} gapful numbers starting at ${commatize(starts[i])}:")
for count < counts[i] {
fl := (j/pow)*10 + (j % 10)
if j%fl == 0 {
print("$j ")
count++
}
j++
if j >= 10*pow {
pow *= 10
}
}
println("\n")
}
}</syntaxhighlight>
{{out}}
<pre>
First 30 gapful numbers starting at 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 starting at 1,000,000:
Function FirstNum(n As Integer) As Integer
1000000 1000005 1000008 1000010 1000016 1000020 1000021 1000030 1000032 1000034 1000035 1000040 1000050 1000060 1000065
REM Divide by ten until the leading digit remains.
While n >= 10
n /= 10
End While
Return n
End Function
 
First 15 gapful numbers starting at 10,000,000:
Function LastNum(n As Integer) As Integer
10000000 10000001 10000003 10000004 10000005 10000008 10000010 10000016 10000020 10000030 10000032 10000035 10000040 10000050 10000060
REM Modulo gives you the last digit.
Return n Mod 10
End Function
 
First 10 gapful numbers starting at 1,000,000,000:
Sub FindGap(n As Integer, gaps As Integer)
1000000000 1000000001 1000000005 1000000008 1000000010 1000000016 1000000020 1000000027 1000000030 1000000032
Dim count = 0
While count < gaps
Dim i = FirstNum(n) * 10 + LastNum(n)
 
First 25 gapful numbers starting at 7,123:
REM Modulo with our new integer and output the result.
7125 7140 7171 7189 7210 7272 7275 7280 7296 7350 7373 7420 7425 7474 7488 7490 7560 7575 7630 7632 7676 7700 7725 7770 7777
If n Mod i = 0 Then
</pre>
Console.Write("{0} ", n)
count += 1
End If
 
n += 1
End While
Console.WriteLine()
Console.WriteLine()
End Sub
 
Sub Main()
Console.WriteLine("The first 30 gapful numbers are: ")
FindGap(100, 30)
 
Console.WriteLine("The first 15 gapful numbers > 1,000,000 are: ")
FindGap(1000000, 15)
 
Console.WriteLine("The first 10 gapful numbers > 1,000,000,000 are: ")
FindGap(1000000000, 10)
End Sub
 
End Module</lang>
{{out}}
<pre>The first 30 gapful numbers are:
100 105 108 110 120 121 130 132 135 140 143 156 160 168 175 180 200 220 225 231 240 242 253 270 300 315 330 341 360 400
 
The first 15 gapful numbers > 1,000,000 are:
1000000 1000005 1000008 1000010 1000016 1000020 1000021 1000030 1000032 1000034 1000035 1000040 1000050 1000060 1000065
 
The first 10 gapful numbers > 1,000,000,000 are:
1000000000 1000000001 1000000005 1000000008 1000000010 1000000016 1000000020 1000000027 1000000030 1000000032</pre>
 
=={{header|Wren}}==
{{trans|Go}}
{{libheader|Wren-fmt}}
<langsyntaxhighlight ecmascriptlang="wren">import "./fmt" for Fmt
 
var starts = [1e2, 1e6, 1e7, 1e9, 7123]
Line 3,067 ⟶ 4,074:
}
System.print("\n")
}</langsyntaxhighlight>
 
{{out}}
<pre>
Line 3,087 ⟶ 4,093:
</pre>
 
=={{header|XBS}}==
<syntaxhighlight lang="xbs">func isgapful(n:number):boolean{
set s:string = tostring(n);
set d = toint(`{s::at(0)}{s::at(?s-1)}`);
send (n%d)==0
}
 
func findGapfulNumbers(start,amount){
=={{header|Yabasic}}==
set gapful=[];
<lang Yabasic>sub is_gapful(n)
set mind = nstart;
while(true){
l = mod(n, 10)
if(isgapful(ind)){
while (m >= 10)
gapful::insert(ind);
m = int(m / 10)
}
wend
ind++;
return (m * 10) + l
if((?gapful)>=amount){
end sub
stop;
}
}
log(`First {amount} gapful ints at {start}: {gapful::join(", ")}`);
}
 
findGapfulNumbers(100,30);
sub muestra_gapful(n, gaps)
findGapfulNumbers(1000000,15);
inc = 0
findGapfulNumbers(1000000000,15);</syntaxhighlight>
print "Primeros ", gaps, " numeros gapful >= ", n
while inc < gaps
if mod(n, is_gapful(n)) = 0 then
print " " , n ,
inc = inc + 1
end if
n = n + 1
wend
print chr$(10)
end sub
 
muestra_gapful(100, 30)
muestra_gapful(1000000, 15)
muestra_gapful(1000000000, 10)
muestra_gapful(7123,25)
end</lang>
{{out}}
<pre>
First 30 gapful ints at 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
Primeros 30 numeros gapful >= 100
First 15 gapful ints at 1000000: 1000000, 1000005, 1000008, 1000010, 1000016, 1000020, 1000021, 1000030, 1000032, 1000034, 1000035, 1000040, 1000050, 1000060, 1000065
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 ints at 1000000000: 1000000000, 1000000001, 1000000005, 1000000008, 1000000010, 1000000016, 1000000020, 1000000027, 1000000030, 1000000032, 1000000035, 1000000039, 1000000040, 1000000050, 1000000053
</pre>
 
=={{header|XPL0}}==
Primeros 15 numeros gapful >= 1000000
<syntaxhighlight lang="xpl0">func Gapful(N0); \Return 'true' if gapful number
1000000 1000005 1000008 1000010 1000016 1000020 1000021 1000030 1000032 1000034 1000035 1000040 1000050 1000060 1000065
int N0, N, First, Last;
[N:= N0;
N:= N/10;
Last:= rem(0);
repeat N:= N/10;
First:= rem(0);
until N = 0;
N:= First*10 + Last;
return rem(N0/N) = 0;
];
 
proc ShowGap(Start, Limit); \Display gapful numbers
Primeros 10 numeros gapful >= 1000000000
int Start, Limit, Count, N;
1000000000 1000000001 1000000005 1000000008 1000000010 1000000016 1000000020 1000000027 1000000030 1000000032
[Text(0, "First "); IntOut(0, Limit); Text(0, " gapful numbers starting from ");
 
IntOut(0, Start); Text(0, ":^m^j");
Primeros 25 numeros gapful >= 7123
Count:= 0; N:= Start;
7125 7140 7171 7189 7210 7272 7275 7280 7296 7350 7373 7420 7425 7474 7488 7490 7560 7575 7630 7632 7676 7700 7725 7770 7777
loop [if Gapful(N) then
 
[IntOut(0, N); ChOut(0, ^ );
---Program done, press RETURN---</pre>
Count:= Count+1;
if Count >= Limit then quit;
];
N:= N+1;
];
CrLf(0);
];
 
[ShowGap(100, 30);
ShowGap(1_000_000, 15);
ShowGap(1_000_000_000, 10);
]</syntaxhighlight>
{{out}}
<pre>
First 30 gapful numbers starting from 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 starting from 1000000:
1000000 1000005 1000008 1000010 1000016 1000020 1000021 1000030 1000032 1000034 1000035 1000040 1000050 1000060 1000065
First 10 gapful numbers starting from 1000000000:
1000000000 1000000001 1000000005 1000000008 1000000010 1000000016 1000000020 1000000027 1000000030 1000000032
</pre>
 
=={{header|zkl}}==
<langsyntaxhighlight lang="zkl">fcn gapfulW(start){ //--> iterator
[start..].tweak(
fcn(n){ if(n % (10*n.toString()[0] + n%10)) Void.Skip else n })
}</langsyntaxhighlight>
<langsyntaxhighlight lang="zkl">foreach n,z in
( T( T(100, 30), T(1_000_000, 15), T(1_000_000_000, 10), T(7_123,25) )){
println("First %d gapful numbers starting at %,d:".fmt(z,n));
gapfulW(n).walk(z).concat(", ").println("\n");
}</langsyntaxhighlight>
{{out}}
<pre>
1,983

edits