Last active
November 14, 2021 15:06
-
-
Save ewrvp7lv7/74b2240c614e39968171436fc37a5081 to your computer and use it in GitHub Desktop.
All combinations of uniq symbols
This file contains hidden or 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 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