Jump to content

Sum of the digits of n is substring of n: Difference between revisions

Added Algol 68
m (→‎{{header|Python}}: (abstracted out the formatting of the full script version))
(Added Algol 68)
Line 4:
Find and show numbers n with property that the sum of the digits of n is substring of n, where '''n < 1000'''
<br><br>
 
=={{header|ALGOL 68}}==
ALGOL 68G has the procedure "string in string" in the prelude, for other compilers, a version is available here: [[ALGOL_68/prelude]].
<lang algol68>BEGIN # find n where the sum of the digits is a substring of the representaton of n #
INT max number = 1 000;
INT n count := 0;
FOR n FROM 0 TO max number - 1 DO
INT d sum := 0;
INT v := n;
WHILE v > 0 DO
d sum +:= v MOD 10;
v OVERAB 10
OD;
IF string in string( whole( d sum, 0 ), NIL, whole( n, 0 ) ) THEN
# the string representaton of the digit sum is contained in the representation of n #
print( ( " ", whole( n, -4 ) ) );
n count +:= 1;
IF n count MOD 8 = 0 THEN print( ( newline ) ) FI
FI
OD
END</lang>
{{out}}
<pre>
0 1 2 3 4 5 6 7
8 9 10 20 30 40 50 60
70 80 90 100 109 119 129 139
149 159 169 179 189 199 200 300
400 500 600 700 800 900 910 911
912 913 914 915 916 917 918 919
</pre>
 
=={{header|Factor}}==
3,060

edits

Cookies help us deliver our services. By using our services, you agree to our use of cookies.