I have a file:
package main
import "fmt"
func
combinations(result chan []byte, len int, min byte, max byte) {
res := make([]byte,len)
for i := 0; i < len; i++ {
res[i] = min
}
result <- res
for true {
i := 0
for i = 0; i < len; i++ {
if res[i] < max {
res[i] = res[i] + 1;
break
} else {
res[i] = 32
}
}
result <- res
if(i == len) {
close(result)
return;
}
}
}
func
main() {
combination_chan := make(chan []byte)
go combinations(combination_chan, 2, 0, 5)
for next_combination := range combination_chan {
fmt.Printf("%x
",next_combination)
}
}
I expect this to print all possible combinations of 2 bytes between 0 and 5, IE:
0000
0100
...
0001
...
0505
However, it seems to skip every other value, and print the same value twice, IE:
0100
0100
0300
0300
...
Why would it be doing this? I've inserted prints before the 'result <- res' line, and those are all correct.