Gapful numbers: Difference between revisions

Added Easylang
No edit summary
(Added Easylang)
 
(8 intermediate revisions by 4 users not shown)
Line 215:
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"</syntaxhighlight>
 
=={{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|Arturo}}==
 
<syntaxhighlight lang="rebol">gapful?: function [n][
s: to :string n
Line 281 ⟶ 240:
print "\n"
]</syntaxhighlight>
 
{{out}}
 
<pre>----------------------------------------------------------------
first 30 gapful numbers starting from 100
Line 406 ⟶ 363:
}
printf("\n")
}</syntaxhighlight>
}
</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
<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}}
<syntaxhighlight lang="basic256">function is_gapful(n)
Line 430 ⟶ 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 446 ⟶ 441:
call muestra_gapful(7123,25)
end</syntaxhighlight>
{{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}}==
Line 490 ⟶ 1,024:
}
</syntaxhighlight>
{{out}}
Output :
<pre>First 30 Gapful numbers >= 100 :
 
Line 590 ⟶ 1,124:
return 0;
}</syntaxhighlight>
 
{{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#}}==
Line 666 ⟶ 1,197:
}
}
}</syntaxhighlight>
}
 
 
</syntaxhighlight>
{{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 679 ⟶ 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}}==
Line 705 ⟶ 1,230:
 
(doall (map report-range [ [1 30] [1000000 15] [1000000000 10] ]))</syntaxhighlight>
 
{{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 831 ⟶ 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.
 
<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|Common Lisp}}==
Line 903 ⟶ 1,377:
(gapfuls-in-range start size))))
 
(mapcar #'report-range '((1 30) (1000000 15) (1000000000 10)))</syntaxhighlight>
</syntaxhighlight>
 
{{Out}}
 
<pre>The first 30 gapful numbers >= 1:
Line 1,026 ⟶ 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 1,099 ⟶ 1,629:
 
main(_) -> lists:map(fun report_range/1, [[1,30],[1000000,15],[1000000000,10]]).</syntaxhighlight>
 
{{Out}}
<pre>The first 30 gapful numbers >= 1:
Line 1,217 ⟶ 1,746:
9 : 1000000030
10 : 1000000032
</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:
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>
 
Line 1,306 ⟶ 1,783:
gapful[1000000000,10]
</syntaxhighlight>
 
{{out}}
<pre>
Line 1,317 ⟶ 1,793:
</pre>
 
=={{header|FutureBasicFōrmulæ}}==
{{FormulaeEntry|page=https://formulae.org/?script=examples/Gapful_numbers}}
<syntaxhighlight lang="futurebasic">
include "NSLog.incl"
 
'''Solution'''
_0 = 48 // ASCII code for 0 = 48
 
The following function return whether a given number is gapful or not
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
 
[[File:Fōrmulæ - Gapful numbers 01.png]]
local fn DoIt
fn generateGaps( 100, 30 ) : NSLog( @"\n" )
fn generateGaps( 1000000, 15 ) : NSLog( @"\n" )
fn generateGaps( 1000000000, 15 ) : NSLog( @"\n" )
end fn
 
The following function shows gapful numbers from a given value:
fn DoIt
 
[[File:Fōrmulæ - Gapful numbers 02.png]]
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
 
'''Test case 1''' Show the first 30 gapful numbers
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[[File:Fōrmulæ 15- Gapful numbers >= 1000000000:03.png]]
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>
 
[[File:Fōrmulæ - Gapful numbers 04.png]]
=={{header|Fōrmulæ}}==
 
'''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
Fōrmulæ programs are not textual, visualization/edition of programs is done showing/manipulating structures but not text. 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 storage and transfer purposes more than visualization and edition.
 
[[File:Fōrmulæ - Gapful numbers 07.png]]
Programs in Fōrmulæ are created/edited online in its [https://formulae.org website], However they run on execution servers. By default remote servers are used, but they are limited in memory and processing power, since they are intended for demonstration and casual use. A local server can be downloaded and installed, it has no limitations (it runs in your own computer). Because of that, example programs can be fully visualized and edited, but some of them will not run if they require a moderate or heavy computation/memory resources, and no local server is being used.
 
[[File:Fōrmulæ - Gapful numbers 08.png]]
In '''[https://formulae.org/?example=Gapful_numbers this]''' page you can see the program(s) related to this task and their results.
 
=={{header|Go}}==
Line 1,469 ⟶ 1,866:
}
}</syntaxhighlight>
 
{{out}}
<pre>
Line 1,638 ⟶ 2,034:
)
</syntaxhighlight>
{{out}}
<pre>
task 30
Line 1,648 ⟶ 2,045:
 
=={{header|Java}}==
 
{{trans|D}}
<syntaxhighlight lang="java">import java.util.List;
Line 1,763 ⟶ 2,159:
print_gapfuls_with_header(1000000, 15)
print_gapfuls_with_header(1000000000, 10)</syntaxhighlight>
 
{{Output}}
<pre>First 100 gapful numbers starting at 30
Line 2,003 ⟶ 2,398:
 
=={{header|jq}}==
 
The following program works with both jq and gojq; for very large integers, the latter should be used.
 
Line 2,028 ⟶ 2,422:
First 10 gapful numbers starting from 10^9:
1000000000 1000000001 1000000005 1000000008 1000000010 1000000016 1000000020 1000000027 1000000030 1000000032</pre>
 
=={{header|Julia}}==
<syntaxhighlight lang="julia">using Lazy, Formatting
Line 2,038 ⟶ 2,433:
println("First $n gapful numbers starting at ", format(x, commas=true), ":\n",
take(n, gapfuls(x)))
end</syntaxhighlight>
end
</syntaxhighlight>{{out}}
<pre>
First 30 gapful numbers starting at 100:
Line 2,160 ⟶ 2,555:
foreach [ [1 30] [1000000 15] [1000000000 10] ] [
apply "report_range ?
]</syntaxhighlight>
]
</syntaxhighlight>
 
{{Out}}
Line 2,462 ⟶ 2,856:
(show-gapfuls 10 999999999)
(exit)</syntaxhighlight>
 
{{out}}
<pre>The first 30 gapful numbers beyond 99 are:
Line 2,513 ⟶ 2,906:
displayGapfulNumbers(1_000_000, 15)
displayGapfulNumbers(1_000_000_000, 10)</syntaxhighlight>
 
{{out}}
<pre>
Line 3,124 ⟶ 3,516:
1000000000,1000000001,1000000005,1000000008,1000000010,1000000016,1000000020,1000000027,1000000030,1000000032
</pre>
 
=={{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|Python}}==
Line 3,191 ⟶ 3,537:
 
=={{header|Quackery}}==
 
<syntaxhighlight lang="Quackery"> [ [ [] swap
[ 10 /mod
Line 3,223 ⟶ 3,568:
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
Line 3,234 ⟶ 3,577:
First 10 gapful numbers from 1000000000
1000000000 1000000001 1000000005 1000000008 1000000010 1000000016 1000000020 1000000027 1000000030 1000000032
 
</pre>
 
Line 3,300 ⟶ 3,642:
 
=={{header|Ring}}==
<syntaxhighlight lang="ring">nr = 0
nr = 0
gapful1 = 99
gapful2 = 999999
Line 3,347 ⟶ 3,688:
see "" + nr + ". " + gapful3 + nl
ok
end</syntaxhighlight>
end
</syntaxhighlight>
{{out}}
<pre>
Line 3,493 ⟶ 3,832:
This is not a particularly efficient solution, but it gets the job done.
 
<syntaxhighlight lang="sql">/*
/*
This code is an implementation of gapful numbers in SQL ORACLE 19c
p_start -- start point
Line 3,527 ⟶ 3,865:
union all
select gapful_numbers(1000000000,10) as res from dual;
/</syntaxhighlight>
/
</syntaxhighlight>
 
{{out}}
<pre>
Line 3,538 ⟶ 3,874:
 
=={{header|Swift}}==
 
<syntaxhighlight lang="swift">func isGapful(n: Int) -> Bool {
guard n > 100 else {
Line 3,557 ⟶ 3,892:
print("First 15 >= 1,000,000: \(Array(mil))")
print("First 15 >= 1,000,000,000: \(Array(bil))")</syntaxhighlight>
 
{{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 3,647 ⟶ 3,980:
 
report-ranges 1,30 1000000,15 1000000000,10</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
Line 3,659 ⟶ 3,990:
1000000000 1000000001 1000000005 1000000008 1000000010 1000000016 1000000020 1000000027 1000000030 1000000032
</pre>
 
=={{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|V (Vlang)}}==
Line 3,755 ⟶ 4,030:
}
}</syntaxhighlight>
 
{{out}}
<pre>
Line 3,777 ⟶ 4,051:
{{trans|Go}}
{{libheader|Wren-fmt}}
<syntaxhighlight lang="ecmascriptwren">import "./fmt" for Fmt
 
var starts = [1e2, 1e6, 1e7, 1e9, 7123]
Line 3,801 ⟶ 4,075:
System.print("\n")
}</syntaxhighlight>
 
{{out}}
<pre>
Line 3,884 ⟶ 4,157:
ShowGap(1_000_000_000, 10);
]</syntaxhighlight>
 
{{out}}
<pre>
Line 3,894 ⟶ 4,166:
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|zkl}}==
1,983

edits