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

Added Algol W
(Add BCPL)
(Added Algol W)
Line 249:
200 300 400 500 600 700 800 900 910 911
912 913 914 915 916 917 918 919</pre>
 
=={{header|ALGOL W}}==
<lang algolw>begin % find numbers n, where the sum of the digits is a substring of n %
% returns true if the digits of s contains the digits of t, false otherwise %
% s and t are assumed to be blank-padded, left-justified numeric strings %
logical procedure containsDigits( integer value s, t ) ;
if s = t then true
else begin
integer tPower, v, u;
logical isContaned;
% find the lowest power of 10 that is greater then t %
tPower := 10;
v := abs t;
while v > 9 do begin
tPower := tPower * 10;
v := v div 10
end while_v_gt_9 ;
isContaned := false;
v := abs t;
u := abs s;
while not isContaned and u > 0 do begin
isContaned := ( u rem tPower ) = v;
u := u div 10
end while_not_isContaned_and_u_gt_0 ;
isContaned
end containsDigits ;
% find and show the matching numbers up to 1000 %
integer nCount;
nCount := 0;
for n := 0 until 999 do begin
integer dSum, v;
dSum := 0;
v := n;
while v > 0 do begin
dSum := dSum + ( v rem 10 );
v := v div 10
end while_v_gt_0 ;
if containsDigits( n, dSum ) then begin
writeon( i_w := 5, s_w := 0, n );
nCount := nCount + 1;
if nCount rem 8 = 0 then write()
end if_n_contains_dSum
end for_n
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|APL}}==
{{works with|Dyalog APL}}
3,028

edits