Gapful numbers: Difference between revisions

→‎{{header|UNIX Shell}}: Add implementation.
(→‎{{header|UNIX Shell}}: Add implementation.)
Line 2,754:
The first 15 gapful >= 1000000: 1000000 1000005 1000008 1000010 1000016 1000020 1000021 1000030 1000032 1000034 1000035 1000040 1000050 1000060 1000065
The first 10 gapful >= 1000000000: 1000000000 1000000001 1000000005 1000000008 1000000010 1000000016 1000000020 1000000027 1000000030 1000000032
 
=={{header|UNIX Shell}}==
{{works with|Bourne Again Shell}}
{{trans|Clojure}}
<lang bash>first-digit() {
printf '%s\n' "${1:0:1}"
}
 
last-digit() {
printf '%s\n' $(( $1 % 10 ))
}
 
bookend-number() {
printf '%s%s\n' "$(first-digit "$@")" "$(last-digit "$@")"
}
 
is-gapful() {
(( $1 >= 100 && $1 % $(bookend-number "$1") == 0 ))
}
 
gapfuls-in-range() {
local gapfuls=()
local -i i found
for (( i=$1, found=0; found < $2; ++i )); do
if is-gapful "$i"; then
if (( found )); then
printf ' ';
fi
printf '%s' "$i"
(( found++ ))
fi
done
printf '\n'
}
 
report-ranges() {
local range
local -i start size
for range; do
IFS=, read start size <<<"$range"
printf 'The first %d gapful numbers >= %d:\n' "$size" "$start"
gapfuls-in-range "$start" "$size"
printf '\n'
done
}
 
report-ranges 100,30 1000000,15 1000000000,10</lang>
 
{{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|Visual Basic .NET}}==
1,479

edits