Skip to content

Instantly share code, notes, and snippets.

@ewrvp7lv7
Last active November 14, 2021 15:06
Show Gist options
  • Save ewrvp7lv7/74b2240c614e39968171436fc37a5081 to your computer and use it in GitHub Desktop.
Save ewrvp7lv7/74b2240c614e39968171436fc37a5081 to your computer and use it in GitHub Desktop.
All combinations of uniq symbols
package module
import (
"fmt"
"strings"
)
func main() {
str := "fgfwfhh"
//replace repeated runes to blanks
rs := []rune(str)
for i := 0; i < len(rs); i++ {
for j := i + 1; j < len(rs); j++ {
if rs[j] == rs[i] {
rs[j] = ' '
}
}
}
// remove blanks
str = strings.ReplaceAll(string(rs), " ", "")
recursiveStr("", str)
}
func recursiveStr(variants string, s string) {
for _, r := range s {
recursiveStr(variants+string(r), strings.ReplaceAll(s, string(r), ""))
}
if len(s) == 0 {
fmt.Println(variants)
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment