Intersecting number wheels: Difference between revisions
→{{header|Go}}: Tidied up a bit.
(Promote to full task status.) |
(→{{header|Go}}: Tidied up a bit.) |
||
Line 254:
import (
"fmt"
"sort"
"strconv"
)
Line 262 ⟶ 263:
}
func generate(wheels wheelMap, start string, maxCount int) {
count := 0
w := wheels[start]
Line 269 ⟶ 271:
s := w.values[w.next]
v, err := strconv.Atoi(s)
w.next = (w.next +
}▼
if err == nil {
fmt.Printf("%d ", v)
Line 285:
ss := s
s = w2.values[w2.next]
w2.next = (w2.next +
}▼
wheels[ss] = w2
v, err = strconv.Atoi(s)
Line 305 ⟶ 302:
}
func printWheels(wheels
var names []string
for name := range wheels {
names = append(names, name)
}
sort.Strings(names)
fmt.Println("Intersecting Number Wheel group:")
for _, name := range names {
fmt.Printf(" %s: %v\n", name, wheels[name].values)
}
fmt.
}
func main() {▼
wheels["A"] = wheel{0, []string{"1", "2", "3"}}▼
printWheels(wheels, "A")▼
generate(wheels, "A", 20)▼
▲func main() {
wheels["A"] = wheel{0, []string{"1", "B", "2"}}▼
{
▲ },
{
wheels["A"] = wheel{0, []string{"1", "D", "D"}}▼
},
wheels["B"] = wheel{0, []string{"3", "4"}}▼
{
},
}
for _, wheels := range wheelMaps {
▲ generate(wheels, "A", 20)
}
}</lang>
|