Skip to content

Commit 45ff9e1

Browse files
Create StringCombinations.go
1 parent e3447b6 commit 45ff9e1

File tree

1 file changed

+32
-0
lines changed

1 file changed

+32
-0
lines changed

StringCombinations.go

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
/*
2+
String combinations in Go
3+
*/
4+
package main
5+
6+
import "fmt"
7+
8+
type Combinations struct {
9+
out []rune
10+
in []rune
11+
}
12+
13+
func startCombinations(input string) {
14+
c := &Combinations{
15+
in: []rune(input),
16+
}
17+
18+
c.Combine(0)
19+
}
20+
21+
func (c *Combinations) Combine(seed int) {
22+
inLen := len(c.in)
23+
for i := seed; i < inLen-1; i++ {
24+
c.out = append(c.out, c.in[i])
25+
fmt.Println(string(c.out))
26+
c.Combine(i + 1)
27+
c.out = c.out[:len(c.out)-1]
28+
}
29+
c.out = append(c.out, c.in[inLen-1])
30+
fmt.Println(string(c.out))
31+
c.out = c.out[:len(c.out)-1]
32+
}

0 commit comments

Comments
 (0)