Jump to content

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

Add Draco
(Add Draco)
Line 777:
{{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|Draco}}==
<lang draco>\util.g
 
proc nonrec digit_sum(word n) word:
word sum;
sum := 0;
while n ~= 0 do
sum := sum + n % 10;
n := n / 10;
od;
sum
corp
 
proc nonrec itoa(word n; *char buf) void:
channel output text ch;
open(ch, buf);
write(ch; n);
close(ch)
corp
 
proc nonrec digit_sum_is_substring(word n) bool:
[10] char dstr, dsub;
itoa(n, &dstr[0]);
itoa(digit_sum(n), &dsub[0]);
CharsIndex(&dstr[0], &dsub[0]) ~= -1
corp
 
proc nonrec main() void:
word i, seen;
seen := 0;
for i from 0 upto 999 do
if digit_sum_is_substring(i) then
write(i:4);
seen := seen + 1;
if seen % 20 = 0 then writeln() fi
fi
od
corp</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|F_Sharp|F#}}==
2,115

edits

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