Posts

Showing posts from July, 2017

Working through the golang tour

Exercise: rot13Reader https://tour.golang.org/methods/23 This was was tougher than I thought,  Mainly because you really have to understand the implied pieces that are needed.  I ended up solving this with a map rather than the github answer key I found. package main import ( "io" "os" "strings" ) type rot13Reader struct { r io.Reader } func main() { s := strings.NewReader("Lbh penpxrq gur pbqr!") r := rot13Reader{s} io.Copy(os.Stdout, &r) } func (rot13 rot13Reader) Read(b []byte) (n int, err error) { n,err = rot13.r.Read(b) for i:=0;i<n;i++ { b[i] = m[b[i]] } return n,err } var m = map[byte]byte{ 'A': 'N', 'B': 'O', 'C': 'P', 'D': 'Q', 'E': 'R', 'F': 'S', 'G': 'T', 'H': 'U', 'I': 'V', 'J': 'W', 'K': 'X', 'L': &#