Skip to content

Instantly share code, notes, and snippets.

@caelifer
Created December 10, 2015 02:12
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save caelifer/aaedc5ed68c09ad6a93d to your computer and use it in GitHub Desktop.
Save caelifer/aaedc5ed68c09ad6a93d to your computer and use it in GitHub Desktop.
package main
import "fmt"
func nextPermutation(x byte) byte {
a := x & -x
b := x + a
c := b ^ x
a <<= 2
c /= a
return b | c
}
func main() {
count := 0
for cur, lst := byte(7), byte(127); cur < lst; cur = nextPermutation(cur) {
fmt.Printf("%08b\n", cur)
count++
}
fmt.Printf("Total %d permutations\n", count)
}
@caelifer
Copy link
Author

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment