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

add fermat
(add fermat)
Line 807:
400 500 600 700 800 900 910 911
912 913 914 915 916 917 918 919
</pre>
 
=={{header|Fermat}}==
No string conversion.
<lang fermat>Func Digsum(n, b) =
ds:=0; {digital sum of n in base b}
while n>0 do
ds:+(n|b);
n:=n\b;
od;
ds.;
 
Func Numdig(n, b) =
nd:=0; {number of digits of n in base b}
while n > 0 do
nd:+;
n:=n\b;
od;
nd.;
 
for n = 1 to 999 do
ds:=Digsum(n, 10); {digital sum of n}
nd:=Numdig(ds, 10); {how many digits does the digital sum itself have?}
nt:=n; {temporary copy of n}
while nt>0 do
if ds=(nt|(10^(nd))) then
!!n; {if the last nt digits of n are the digital sum, print and exit the loop}
&>;
fi;
nt:=nt\10; {peel off the last digit and go again}
od;
od;</lang>
{{out}}<pre>
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>
 
Line 884 ⟶ 964:
= 918
= 919</pre>
 
=={{header|FreeBASIC}}==
<lang freebasic>function is_substring( s as string, j as string ) as boolean
781

edits