From 705d4441afff35687351024db9660bf8541b44ee Mon Sep 17 00:00:00 2001 From: derek mcquay Date: Thu, 11 Feb 2016 22:54:51 -0800 Subject: [PATCH] added Transpose(), randomly transpose a string --- main.go | 15 +++++++++++++-- psyfer/transposition.go | 16 ++++++++++++++++ 2 files changed, 29 insertions(+), 2 deletions(-) create mode 100644 psyfer/transposition.go diff --git a/main.go b/main.go index 276591a..ba04a5f 100644 --- a/main.go +++ b/main.go @@ -1,7 +1,18 @@ package main -import "fmt" +import ( + "fmt" + "math/rand" + "time" + + "s.mcquay.me/dm/psyfer/psyfer" +) + +func init() { + rand.Seed(time.Now().UnixNano()) +} func main() { - fmt.Println("hello psyfer") + fmt.Println(psyfer.Transpose("hello world")) + fmt.Println(psyfer.Transpose("hello")) } diff --git a/psyfer/transposition.go b/psyfer/transposition.go new file mode 100644 index 0000000..54c8a0c --- /dev/null +++ b/psyfer/transposition.go @@ -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 +}