Gapful numbers: Difference between revisions

Added Algol 68
(→‎{{header|Scheme}}: remove 1+ so it works in R5RS.)
(Added Algol 68)
Line 38:
:*   numbersaplenty [http://www.numbersaplenty.com/set/gapful_number/ gapful numbers]
<br><br>
 
=={{header|ALGOL 68}}==
<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</lang>
{{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}}==
3,025

edits