added Transpose(), randomly transpose a string
This commit is contained in:
parent
f278fdda14
commit
705d4441af
15
main.go
15
main.go
@ -1,7 +1,18 @@
|
|||||||
package main
|
package main
|
||||||
|
|
||||||
import "fmt"
|
import (
|
||||||
|
"fmt"
|
||||||
|
"math/rand"
|
||||||
|
"time"
|
||||||
|
|
||||||
|
"s.mcquay.me/dm/psyfer/psyfer"
|
||||||
|
)
|
||||||
|
|
||||||
|
func init() {
|
||||||
|
rand.Seed(time.Now().UnixNano())
|
||||||
|
}
|
||||||
|
|
||||||
func main() {
|
func main() {
|
||||||
fmt.Println("hello psyfer")
|
fmt.Println(psyfer.Transpose("hello world"))
|
||||||
|
fmt.Println(psyfer.Transpose("hello"))
|
||||||
}
|
}
|
||||||
|
16
psyfer/transposition.go
Normal file
16
psyfer/transposition.go
Normal file
@ -0,0 +1,16 @@
|
|||||||
|
package psyfer
|
||||||
|
|
||||||
|
import (
|
||||||
|
"fmt"
|
||||||
|
"math/rand"
|
||||||
|
)
|
||||||
|
|
||||||
|
func Transpose(input string) string {
|
||||||
|
shuffle := ""
|
||||||
|
list := rand.Perm(len(input))
|
||||||
|
fmt.Println(list)
|
||||||
|
for _, i := range list {
|
||||||
|
shuffle += string(input[i])
|
||||||
|
}
|
||||||
|
return shuffle
|
||||||
|
}
|
Loading…
Reference in New Issue
Block a user