Created
July 8, 2020 06:57
-
-
Save bamchoh/7e576cbd2303a9aeef1c930050bb4348 to your computer and use it in GitHub Desktop.
ビット全探索
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
package main | |
import ( | |
"strings" | |
"fmt" | |
) | |
func comb(a []string) [][]string { | |
ret := make([][]string, 0) | |
for s:=0;s<(1<<len(a));s++ { | |
b := []string{} | |
for i:=0;i<len(a);i++ { | |
if((s >> i) & 0x1 == 1) { | |
b = append(b, a[i]) | |
} | |
} | |
ret = append(ret, b) | |
} | |
return ret | |
} | |
func main() { | |
a := []string { "a","b","c","d","e" } | |
b := comb(a) | |
for i,v := range b { | |
fmt.Printf("%0*b:", len(a), i) | |
fmt.Println(strings.Join(v, ",")) | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment