Skip to content

Instantly share code, notes, and snippets.

@nomkhonwaan
Last active August 29, 2015 14:22
Show Gist options
  • Select an option

  • Save nomkhonwaan/9544da1b92e8bdcd2fa6 to your computer and use it in GitHub Desktop.

Select an option

Save nomkhonwaan/9544da1b92e8bdcd2fa6 to your computer and use it in GitHub Desktop.
package main
import (
"fmt"
"github.com/fighterlyt/permutation"
"reflect"
)
type Phone struct {
ID int
Vendor string
}
func main() {
phone := []Phone{
Phone{1, "Samsung"},
Phone{2, "HTC"},
Phone{3, "LG"},
Phone{4, "Sony"},
}
perm, _ := permutation.NewPerm(phone, func(i, j interface{}) bool {
return reflect.ValueOf(i).FieldByName("ID").Int() < reflect.ValueOf(j).FieldByName("ID").Int()
})
for elem, err := perm.Next(); err == nil; elem, err = perm.Next() {
fmt.Println(elem, perm.Left())
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment