Gapful numbers: Difference between revisions

m
syntax highlighting fixup automation
m (syntax highlighting fixup automation)
Line 42:
{{trans|Python}}
 
<langsyntaxhighlight 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
Line 50:
I l.len == n
L.break
print(l)</langsyntaxhighlight>
 
{{out}}
Line 66:
 
=={{header|Ada}}==
<langsyntaxhighlight Adalang="ada">with Ada.Text_IO; use Ada.Text_IO;
 
procedure Gapful_Numbers is
Line 109:
Find_Gapful (From => 1_000_000_000, Count => 10);
New_Line;
end Gapful_Numbers;</langsyntaxhighlight>
{{out}}
<pre>First 30 gapful numbers over 100:
Line 122:
 
=={{header|ALGOL 68}}==
<langsyntaxhighlight 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 #
Line 160:
print gapful( 15 GAPFUL 1 000 000, 1 000 000 );
print gapful( 10 GAPFUL 1 000 000 000, 1 000 000 000 )
END</langsyntaxhighlight>
{{out}}
<pre>
Line 173:
=={{header|AppleScript}}==
 
<langsyntaxhighlight lang="applescript">on isGapful(n)
set units to n mod 10
set temp to n div 10
Line 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 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|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.
<langsyntaxhighlight lang="gwbasic"> 100 START = 100
110 COUNT = 30
120 GOSUB 230"GENERATE GAPS"
Line 254:
440 NEXT P
450 PRINT MID$(M$ + " " + P$, 2 - (POS(0) + LEN(P$) + 1 > PEEK(33))) ;
460 RETURN</langsyntaxhighlight>
=={{header|Arturo}}==
 
<langsyntaxhighlight lang="rebol">gapful?: function [n][
s: to :string n
divisor: to :integer (first s) ++ last s
Line 280:
]
print "\n"
]</langsyntaxhighlight>
 
{{out}}
Line 305:
 
=={{header|AutoHotkey}}==
<langsyntaxhighlight AutoHotkeylang="autohotkey">Gapful_numbers(Min, Qty){
counter:= 0, output := ""
while (counter < Qty){
Line 314:
}
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 380:
 
=={{header|AWK}}==
<syntaxhighlight lang="awk">
<lang AWK>
# syntax: GAWK -f GAPFUL_NUMBERS.AWK
# converted from C++
Line 407:
printf("\n")
}
</syntaxhighlight>
</lang>
{{out}}
<pre>
Line 419:
=={{header|BASIC256}}==
{{trans|Yabasic}}
<langsyntaxhighlight BASIC256lang="basic256">function is_gapful(n)
m = n
l = n mod 10
Line 445:
call muestra_gapful(1000000000, 10)
call muestra_gapful(7123,25)
end</langsyntaxhighlight>
{{out}}
<pre>
Line 453:
 
=={{header|C}}==
<syntaxhighlight lang="c">
<lang C>
#include<stdio.h>
 
Line 489:
return 0;
}
</syntaxhighlight>
</lang>
Output :
<pre>First 30 Gapful numbers >= 100 :
Line 562:
 
=={{header|C++}}==
<langsyntaxhighlight lang="cpp">#include <iostream>
 
bool gapful(int n) {
Line 589:
show_gapful_numbers(1000000000, 10);
return 0;
}</langsyntaxhighlight>
 
{{out}}
Line 602:
 
=={{header|C#}}==
<langsyntaxhighlight lang="csharp">
using System;
 
Line 669:
 
 
</syntaxhighlight>
</lang>
{{out}}
<pre>
Line 684:
 
=={{header|Clojure}}==
<langsyntaxhighlight lang="clojure">(defn first-digit [n] (Integer/parseInt (subs (str n) 0 1)))
 
(defn last-digit [n] (mod n 10))
Line 704:
""])))
 
(doall (map report-range [ [1 30] [1000000 15] [1000000000 10] ]))</langsyntaxhighlight>
 
{{Out}}
Line 721:
numbers have to be on separate lines.
 
<langsyntaxhighlight lang="cobol"> IDENTIFICATION DIVISION.
PROGRAM-ID. GAPFUL.
Line 768:
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 837:
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.
 
<langsyntaxhighlight 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)
Line 855:
260 END
270 DATA 1,30, 1000000,15, 100000000,10
280 DATA -1</langsyntaxhighlight>
 
{{Out}}
Line 883:
=={{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 904:
 
(mapcar #'report-range '((1 30) (1000000 15) (1000000000 10)))
</syntaxhighlight>
</lang>
 
{{Out}}
Line 924:
{{trans|Ruby}}
With lazy iterator
<langsyntaxhighlight lang="ruby">struct Int
def gapful?
a = self.to_s.chars.map(&.to_i)
Line 936:
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 953:
(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 969:
=={{header|D}}==
{{trans|Go}}
<langsyntaxhighlight lang="d">import std.conv;
import std.stdio;
 
Line 1,010:
writeln("\n");
}
}</langsyntaxhighlight>
{{out}}
<pre>First 30 gapful numbers starting at 100:
Line 1,035:
 
The gapfulness implementation:
<langsyntaxhighlight lang="erlang">-module(gapful).
-export([first_digit/1, last_digit/1, bookend_number/1, is_gapful/1]).
 
Line 1,045:
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 1,086:
{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).
 
Line 1,098:
stream:naturals(Start))))]).
 
main(_) -> lists:map(fun report_range/1, [[1,30],[1000000,15],[1000000000,10]]).</langsyntaxhighlight>
 
{{Out}}
Line 1,112:
 
=={{header|Factor}}==
<langsyntaxhighlight lang="factor">USING: formatting kernel lists lists.lazy math math.functions
math.text.utils sequences ;
 
Line 1,121:
2dup lfrom [ gapful? ] lfilter ltake list>array
"%d gapful numbers starting at %d:\n%[%d, %]\n\n" printf
] 2tri@</langsyntaxhighlight>
{{out}}
<pre>
Line 1,136:
=={{header|Forth}}==
Developed with Gforth 0.7.9
<langsyntaxhighlight lang="forth">variable cnt
: Int>Str s>d <# #s #> ;
: firstDigit C@ [char] 0 - ;
Line 1,156:
1000000 15 main cr
1000000000 10 main cr
</syntaxhighlight>
</lang>
{{out}}
<pre>
Line 1,220:
 
=={{header|FreeBASIC}}==
<langsyntaxhighlight lang="freebasic">
function is_gapful( n as uinteger ) as boolean
if n<100 then return false
Line 1,258:
i += 1
wend
print</langsyntaxhighlight>
{{out}}
<pre>
Line 1,272:
 
=={{header|Frink}}==
<langsyntaxhighlight lang="frink">
// Create function to calculate gapful number
gapful[num,totalCounter] :=
Line 1,301:
gapful[1000000,15]
gapful[1000000000,10]
</syntaxhighlight>
</lang>
 
{{out}}
Line 1,322:
 
=={{header|Go}}==
<langsyntaxhighlight lang="go">package main
 
import "fmt"
Line 1,362:
fmt.Println("\n")
}
}</langsyntaxhighlight>
 
{{out}}
Line 1,384:
=={{header|Groovy}}==
{{trans|Java}}
<langsyntaxhighlight lang="groovy">class GapfulNumbers {
private static String commatize(long n) {
StringBuilder sb = new StringBuilder(Long.toString(n))
Line 1,422:
}
}
}</langsyntaxhighlight>
{{out}}
<pre>First 30 gapful numbers starting at 100
Line 1,440:
 
=={{header|Haskell}}==
<langsyntaxhighlight lang="haskell">{-# LANGUAGE NumericUnderscores #-}
 
gapful :: Int -> Bool
Line 1,453:
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,468:
 
Or, defining the predicate in applicative terms, and wrapping the output:
<langsyntaxhighlight lang="haskell">import Data.List (intercalate)
import Data.List.Split (chunksOf)
 
Line 1,500:
(read (ws !! 1))
[read (ws !! 5) :: Int ..]
)</langsyntaxhighlight>
{{Out}}
<pre>First 30 gapful numbers >= 100:
Line 1,523:
 
=={{header|J}}==
<syntaxhighlight lang="text">
gapful =: 0 = (|~ ({.,{:)&.(10&#.inv))
 
Line 1,531:
'The first ' , (": y) , ' gapful numbers exceeding ' , (":<:x) , ' are ' , (":gn)
)
</syntaxhighlight>
</lang>
<pre>
task 30
Line 1,544:
 
{{trans|D}}
<langsyntaxhighlight lang="java">import java.util.List;
 
public class GapfulNumbers {
Line 1,581:
}
}
}</langsyntaxhighlight>
{{out}}
<pre>First 30 gapful numbers starting at 100:
Line 1,601:
===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,656:
print_gapfuls_with_header(100, 30)
print_gapfuls_with_header(1000000, 15)
print_gapfuls_with_header(1000000000, 10)</langsyntaxhighlight>
 
{{Output}}
Line 1,667:
 
===ES6===
<langsyntaxhighlight lang="javascript">(() => {
'use strict';
 
Line 1,874:
// MAIN ---
return main();
})();</langsyntaxhighlight>
{{Out}}
<pre>First 30 gapful numbers >= 100:
Line 1,900:
The following program works with both jq and gojq; for very large integers, the latter should be used.
 
<langsyntaxhighlight lang="jq"># emit a stream of gapful numbers greater than or equal to $start,
# which is assumed to be an integer
def gapful($start):
Line 1,914:
([limit(15;gapful(1000000))] | join(" ")),
"First 10 gapful numbers starting from 10^9:",
([limit(10;gapful(pow(10;9)))] | join(" "))</langsyntaxhighlight>
{{out}}
<pre>First 30 gapful numbers starting from 100:
Line 1,923:
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,933:
take(n, gapfuls(x)))
end
</langsyntaxhighlight>{{out}}
<pre>
First 30 gapful numbers starting at 100:
Line 1,945:
=={{header|Kotlin}}==
{{trans|Java}}
<langsyntaxhighlight lang="scala">private fun commatize(n: Long): String {
val sb = StringBuilder(n.toString())
val le = sb.length
Line 1,984:
println('\n')
}
}</langsyntaxhighlight>
{{out}}
<pre>First 30 gapful numbers starting at 100:
Line 2,002:
 
=={{header|Lambdatalk}}==
<syntaxhighlight lang="scheme">
<lang Scheme>
{def gapfuls
{lambda {:n :i :N}
Line 2,023:
-> 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 2,055:
apply "report_range ?
]
</syntaxhighlight>
</lang>
 
{{Out}}
Line 2,069:
=={{header|LOLCODE}}==
{{trans|Clojure}}
<langsyntaxhighlight lang="lolcode">HAI 1.2
 
HOW IZ I FurstDigit YR Numbr
Line 2,133:
I IZ Report YR 1000000000 AN YR 10 MKAY
KTHXBYE
</syntaxhighlight>
</lang>
 
{{Out}}
Line 2,148:
=={{header|Lua}}==
{{trans|C}}
<langsyntaxhighlight lang="lua">function generateGaps(start, count)
local counter = 0
local i = start
Line 2,172:
 
generateGaps(1000000000, 15)
print()</langsyntaxhighlight>
{{out}}
<pre>First 30 Gapful numbers >= 100 :
Line 2,241:
 
=={{header|Mathematica}} / {{header|Wolfram Language}}==
<langsyntaxhighlight Mathematicalang="mathematica">ClearAll[GapFulQ]
GapFulQ[n_Integer] := Divisible[n, FromDigits[IntegerDigits[n][[{1, -1}]]]]
i = 100;
Line 2,263:
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,271:
=={{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,293:
100 30 show-gapfuls newline
1000000 15 show-gapfuls newline
1000000000 10 show-gapfuls</langsyntaxhighlight>
{{out}}
<pre>
Line 2,307:
 
=={{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,355:
(show-gapfuls 15 999999)
(show-gapfuls 10 999999999)
(exit)</langsyntaxhighlight>
 
{{out}}
Line 2,366:
 
=={{header|Nim}}==
<langsyntaxhighlight Nimlang="nim">import strutils
 
 
Line 2,406:
displayGapfulNumbers(100, 30)
displayGapfulNumbers(1_000_000, 15)
displayGapfulNumbers(1_000_000_000, 10)</langsyntaxhighlight>
 
{{out}}
Line 2,423:
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,602:
end;
{$IFNDEF LINUX} readln; {$ENDIF}
end.</langsyntaxhighlight>
{{out}}
<pre style="font-size:80%">First 30, gapful numbers starting at 100
Line 2,628:
//100|7462360431 =>100*1000*1000*1000 </pre>
===only counting===
<langsyntaxhighlight lang="pascal">program gapful;
{$IFDEF FPC}
{$MODE DELPHI}{$OPTIMIZATION ON,ALL}
Line 2,722:
Main(10);
Main(100);
END.</langsyntaxhighlight>
{{out}}
<pre>Base :10
Line 2,753:
 
=={{header|Perl}}==
<langsyntaxhighlight lang="perl">use strict;
use warnings;
use feature 'say';
Line 2,768:
$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,784:
=={{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,806:
<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,817:
 
=={{header|Plain English}}==
<langsyntaxhighlight lang="plainenglish">To run:
Start up.
Show the gapful numbers at various spots.
Line 2,864:
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,879:
=={{header|PL/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.
<langsyntaxhighlight lang="pli">100H: /* FIND SOME GAPFUL NUMBERS: NUMBERS DIVISIBLE BY 10F + L WHERE F IS */
/* THE FIRST DIGIT AND L IS THE LAST DIGIT */
BDOS: PROCEDURE( FN, ARG ); /* CP/M BDOS SYSTEM CALL */
Line 2,927:
CALL PR$NL;
 
EOF</langsyntaxhighlight>
{{out}}
<pre>
Line 2,936:
=={{header|PowerShell}}==
{{trans|Clojure}}
<langsyntaxhighlight lang="powershell">function Get-FirstDigit {
param ( [int] $Number )
[int]$Number.ToString().Substring(0,1)
Line 2,979:
Search-Range 1000000 15
Search-Range 1000000000 10
</syntaxhighlight>
</lang>
{{Out}}
<pre>The first 30 gapful numbers >= 1:
Line 2,992:
 
=={{header|PureBasic}}==
<langsyntaxhighlight PureBasiclang="purebasic">Procedure.b isGapNum(n.i)
n1.i=n%10
n2.i=Val(Left(Str(n),1))
Line 3,021:
PrintN(~"\nFirst 10 gapful numbers ≥ 1,000,000,000:")
PutGapNum(1000000000,10,5)
Input()</langsyntaxhighlight>
{{out}}
<pre>First 30 gapful numbers ≥ 100:
Line 3,038:
 
=={{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 3,061:
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 3,067:
<Sir Lord Duke King>.pick ~ ": ", ~
($start..*).grep( { $_ %% .comb[0, *-1].join } )[^$count];
}</langsyntaxhighlight>
{{out}}
<pre>First 30 gapful numbers starting at 100:
Line 3,082:
 
=={{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 3,099:
#= # + 1; $= $ j /*bump #; append ──► $ */
end /*j*/
say strip($); say; return</langsyntaxhighlight>
{{out|output|text=&nbsp; when using the default inputs:}}
 
Line 3,119:
 
=={{header|Ring}}==
<syntaxhighlight lang="ring">
<lang Ring>
nr = 0
gapful1 = 99
Line 3,168:
end
</syntaxhighlight>
</lang>
{{out}}
<pre>
Line 3,180:
 
=={{header|Ruby}}==
<langsyntaxhighlight lang="ruby">class Integer
def gapful?
a = digits
Line 3,193:
p (start..).lazy.select(&:gapful?).take(num).to_a
end
</syntaxhighlight>
</lang>
{{out}}
<pre>first 30 gapful numbers >= 100:
Line 3,207:
=={{header|Scheme}}==
{{trans|Clojure}}
<langsyntaxhighlight 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)))
Line 3,226:
 
(map report-range '((100 30) (1000000 15) (1000000000 10)))
</syntaxhighlight>
</lang>
{{Out}}
<pre>The first 30 gapful numbers >= 100:
Line 3,239:
=={{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 3,254:
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 3,277:
This is not a particularly efficient solution, but it gets the job done.
 
<syntaxhighlight lang="sql">
<lang SQL>
/*
This code is an implementation of gapful numbers in SQL ORACLE 19c
Line 3,312:
select gapful_numbers(1000000000,10) as res from dual;
/
</syntaxhighlight>
</lang>
 
{{out}}
Line 3,323:
=={{header|Swift}}==
 
<langsyntaxhighlight lang="swift">func isGapful(n: Int) -> Bool {
guard n > 100 else {
return true
Line 3,340:
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}}
Line 3,349:
 
=={{header|Tcl}}==
<langsyntaxhighlight Tcllang="tcl">proc ungap n {
if {[string length $n] < 3} {
return $n
Line 3,379:
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 3,388:
{{works with|Bourne Again Shell}}
{{trans|Clojure}}
<langsyntaxhighlight lang="bash">first-digit() {
printf '%s\n' "${1:0:1}"
}
Line 3,430:
}
 
report-ranges 1,30 1000000,15 1000000000,10</langsyntaxhighlight>
 
{{Out}}
Line 3,446:
=={{header|Visual Basic .NET}}==
{{trans|C#}}
<langsyntaxhighlight lang="vbnet">Module Module1
 
Function FirstNum(n As Integer) As Integer
Line 3,489:
End Sub
 
End Module</langsyntaxhighlight>
{{out}}
<pre>The first 30 gapful numbers are:
Line 3,502:
=={{header|Vlang}}==
{{trans|go}}
<langsyntaxhighlight lang="vlang">fn commatize(n u64) string {
mut s := n.str()
le := s.len
Line 3,538:
println("\n")
}
}</langsyntaxhighlight>
 
{{out}}
Line 3,561:
{{trans|Go}}
{{libheader|Wren-fmt}}
<langsyntaxhighlight lang="ecmascript">import "/fmt" for Fmt
 
var starts = [1e2, 1e6, 1e7, 1e9, 7123]
Line 3,584:
}
System.print("\n")
}</langsyntaxhighlight>
 
{{out}}
Line 3,605:
 
=={{header|XBS}}==
<langsyntaxhighlight lang="xbs">func isgapful(n:number):boolean{
set s:string = tostring(n);
set d = toint(`{s::at(0)}{s::at(?s-1)}`);
Line 3,628:
findGapfulNumbers(100,30);
findGapfulNumbers(1000000,15);
findGapfulNumbers(1000000000,15);</langsyntaxhighlight>
{{out}}
<pre>
Line 3,637:
 
=={{header|XPL0}}==
<langsyntaxhighlight XPL0lang="xpl0">func Gapful(N0); \Return 'true' if gapful number
int N0, N, First, Last;
[N:= N0;
Line 3,667:
ShowGap(1_000_000, 15);
ShowGap(1_000_000_000, 10);
]</langsyntaxhighlight>
 
{{out}}
Line 3,680:
 
=={{header|Yabasic}}==
<langsyntaxhighlight Yabasiclang="yabasic">sub is_gapful(n)
m = n
l = mod(n, 10)
Line 3,706:
muestra_gapful(1000000000, 10)
muestra_gapful(7123,25)
end</langsyntaxhighlight>
{{out}}
<pre>
Line 3,725:
 
=={{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>
10,333

edits