回答編集履歴

2

edit

2018/01/22 17:28

投稿

mkgrei
mkgrei

スコア8562

answer CHANGED
@@ -8,4 +8,35 @@
8
8
  pythonでの実装。
9
9
 
10
10
  https://stackoverflow.com/questions/23412146/create-cartesian-product-in-go
11
- それと同等なgolangの実装。
11
+ それと同等なgolangの実装。
12
+
13
+ ---
14
+
15
+ 私もそのロジックは理解できませんでしたが、正しそうな結果は得られました。
16
+
17
+ ```go
18
+ package main
19
+ import "fmt"
20
+
21
+ func get_strings(ss []string, count int) []string {
22
+ searched := len(ss[len(ss)-1])
23
+ char := "abcde"
24
+ if searched < count-1 {
25
+ ss = get_strings(ss, count-1)
26
+ }
27
+ for _, s := range ss {
28
+ for _, c := range char {
29
+ ss = append(ss, s + string(c))
30
+ }
31
+ }
32
+ if count == 1 {
33
+ ss = ss[1:]
34
+ }
35
+ return ss
36
+ }
37
+
38
+ func main() {
39
+ ans := []string{""}
40
+ fmt.Println(get_strings(ans, 3))
41
+ }
42
+ ```

1

edit

2018/01/22 17:28

投稿

mkgrei
mkgrei

スコア8562

answer CHANGED
@@ -1,3 +1,11 @@
1
1
  https://github.com/dieyushi/golang-brutedict
2
2
 
3
- 公開されているライブラリでは参考になりませんでしたか?
3
+ 公開されているライブラリでは参考になりませんでしたか?
4
+
5
+ ---
6
+
7
+ https://docs.python.jp/3/library/itertools.html#itertools.product
8
+ pythonでの実装。
9
+
10
+ https://stackoverflow.com/questions/23412146/create-cartesian-product-in-go
11
+ それと同等なgolangの実装。