You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

57 lines
829 B

package main
import (
"bufio"
"fmt"
"math/rand"
"os"
"strings"
"time"
"unicode"
)
func main() {
rand.Seed(time.Now().UnixNano())
s := bufio.NewScanner(os.Stdin)
for s.Scan() {
l := s.Text()
for _, word := range strings.Fields(l) {
fmt.Printf("%s ", jumble(word))
}
fmt.Println()
}
if err := s.Err(); err != nil {
}
}
func jumble(word string) string {
switch len(word) {
case 1, 2, 3:
return word
}
w := []rune(strings.ToLower(word))
start, end := 0, len(w)
for i := 0; i < len(w); i++ {
if unicode.IsLetter(w[i]) {
start = i
break
}
}
for i := len(w) - 1; i > 0; i-- {
if unicode.IsLetter(w[i]) {
end = i
break
}
}
var r string
r += string(w[start])
ps := rand.Perm(end - start - 1)
for _, p := range ps {
r += string(w[p+1])
}
r += string(w[end])
return r
}