Sum of the digits of n is substring of n: Difference between revisions
Sum of the digits of n is substring of n (view source)
Revision as of 13:09, 14 April 2021
, 3 years agoAdded Wren
Thundergnat (talk | contribs) (→{{header|Raku}}: Add a Raku example) |
(Added Wren) |
||
Line 240:
300 400 500 600 700 800 900 910 911 912
913 914 915 916 917 918 919</pre>
=={{header|Wren}}==
{{libheader|Wren-math}}
{{libheader|Wren-seq}}
{{libheader|Wren-fmt}}
<lang ecmascript>import "/math" for Int
import "/seq" for Lst
import "/fmt" for Fmt
var numbers = []
for (n in 0..999) {
var ns = n.toString
var ds = Int.digitSum(n).toString
if (ns.contains(ds)) numbers.add(n)
}
System.print("Numbers under 1,000 whose sum of digits is a substring of themselves:")
for (chunk in Lst.chunks(numbers, 8)) Fmt.print("$3d", chunk)
System.print("\n%(numbers.count) such numbers found.")</lang>
{{out}}
<pre>
Numbers under 1,000 whose sum of digits is a substring of themselves:
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
48 such numbers found.
</pre>
|