Positive decimal integers with the digit 1 occurring exactly twice: Difference between revisions
Positive decimal integers with the digit 1 occurring exactly twice (view source)
Revision as of 13:47, 8 July 2021
, 2 years agoAdded Go
(Added Wren) |
(Added Go) |
||
Line 31:
119 121 131 141 151 161 171 181 191 211
311 411 511 611 711 811 911
</pre>
=={{header|Go}}==
{{trans|Wren}}
{{libheader|Go-rcu}}
<lang go>package main
import (
"fmt"
"rcu"
)
func main() {
fmt.Println("Decimal numbers under 1,000 whose digits include two 1's:")
var results []int
for i := 11; i <= 911; i++ {
digits := rcu.Digits(i, 10)
count := 0
for _, d := range digits {
if d == 1 {
count++
}
}
if count == 2 {
results = append(results, i)
}
}
for i, n := range results {
fmt.Printf("%5d", n)
if (i+1)%7 == 0 {
fmt.Println()
}
}
fmt.Println("\n\nFound", len(results), "such numbers.")
}</lang>
{{out}}
<pre>
Decimal numbers under 1,000 whose digits include two 1's:
11 101 110 112 113 114 115
116 117 118 119 121 131 141
151 161 171 181 191 211 311
411 511 611 711 811 911
Found 27 such numbers.
</pre>
|