Skip to content

Commit

Permalink
Add random letters to Morse arguments (code-golf#363)
Browse files Browse the repository at this point in the history
  • Loading branch information
btnlq authored Jan 7, 2021
1 parent 36e3552 commit 508d895
Showing 1 changed file with 10 additions and 5 deletions.
15 changes: 10 additions & 5 deletions hole/morse.go
Original file line number Diff line number Diff line change
Expand Up @@ -45,13 +45,17 @@ var morseMap = map[rune]string{
' ': " ",
}

func morse(reverse bool) (args []string, out string) {
digits := []string{"0", "1", "2", "3", "4", "5", "6", "7", "8", "9"}
func shuffle(str string) string {
chars := []byte(str)

rand.Shuffle(len(digits), func(i, j int) {
digits[i], digits[j] = digits[j], digits[i]
rand.Shuffle(len(chars), func(i, j int) {
chars[i], chars[j] = chars[j], chars[i]
})

return string(chars)
}

func morse(reverse bool) (args []string, out string) {
words := []string{
"BUD",
"FOR",
Expand All @@ -60,7 +64,8 @@ func morse(reverse bool) (args []string, out string) {
"QUICK",
"VEX",
"WALTZ",
strings.Join(digits, ""),
shuffle("0123456789"),
shuffle("ABCDEFGHIJKLMNOPQRSTUVWXYZ"),
}

rand.Shuffle(len(words), func(i, j int) {
Expand Down

0 comments on commit 508d895

Please sign in to comment.