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

Add CLU
(Add BQN)
(Add CLU)
Line 490:
{{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|CLU}}==
<lang clu>digit_sum = proc (n: int) returns (int)
sum: int := 0
while n > 0 do
sum := sum + n // 10
n := n / 10
end
return (sum)
end digit_sum
 
digit_sum_is_substring = proc (n: int) returns (bool)
n_str: string := int$unparse(n)
ds_str: string := int$unparse(digit_sum(n))
return (string$indexs(ds_str, n_str) ~= 0)
end digit_sum_is_substring
 
match_range = iter (from, to: int, p: proctype (int) returns (bool))
yields (int)
for i: int in int$from_to(from,to) do
if p(i) then yield(i) end
end
end match_range
 
start_up = proc ()
po: stream := stream$primary_output()
col: int := 0
for i: int in match_range(0, 999, digit_sum_is_substring) do
stream$putright(po, int$unparse(i), 4)
col := col + 1
if col // 10 = 0 then stream$putc(po, '\n') end
end
end start_up</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|COBOL}}==
<lang cobol> IDENTIFICATION DIVISION.
2,114

edits