Last active
          April 24, 2021 14:51 
        
      - 
      
 - 
        
Save royling/ebcef895542bf78eabb0ff16b43c09ad to your computer and use it in GitHub Desktop.  
Revisions
- 
        
royling revised this gist
Apr 24, 2021 . 1 changed file with 49 additions and 0 deletions.There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -0,0 +1,49 @@ package main import ( "io" "os" "strings" ) type rot13Reader struct { r io.Reader } func subst(b byte) byte { var ( alpha bool start byte ) switch { case b >= 'a' && b <= 'z': alpha = true start = 'a' case b >= 'A' && b <= 'Z': alpha = true start = 'A' } if alpha { return (b+13-start)%26 + start } return b } func (rot13 *rot13Reader) Read(b []byte) (int, error) { n, err := rot13.r.Read(b) if err == io.EOF { return 0, err } for i, c := range b { b[i] = subst(c) } return n, nil } func main() { s := strings.NewReader("Lbh penpxrq gur pbqr!") r := rot13Reader{s} io.Copy(os.Stdout, &r) // You cracked the code! }  - 
        
royling revised this gist
Apr 24, 2021 . 1 changed file with 15 additions and 0 deletions.There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -0,0 +1,15 @@ package main import "golang.org/x/tour/reader" type MyReader struct{} // TODO: Add a Read([]byte) (int, error) method to MyReader. func (r MyReader) Read(b []byte) (int, error) { b[0] = 'A' return 1, nil } func main() { reader.Validate(MyReader{}) }  - 
        
royling revised this gist
Apr 24, 2021 . 1 changed file with 21 additions and 0 deletions.There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -0,0 +1,21 @@ package main import "fmt" // fibonacci is a function that returns // a function that returns an int. func fibonacci() func() int { a, b := 0, 1 return func() int { i := a a, b = b, a+b return i } } func main() { f := fibonacci() for i := 0; i < 10; i++ { fmt.Println(f()) } }  - 
        
royling revised this gist
Apr 24, 2021 . 1 changed file with 22 additions and 0 deletions.There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -21,3 +21,25 @@ func WordCount(s string) map[string]int { func main() { wc.Test(WordCount) } /* var m2 = map[int]string{ 1: "a", 2: "b", } // Pointer as key type var m3 = map[*Vertex]string { &Vertex{40.68433, -74.39967,}: "Bell", &Vertex{37.42202, -122.08408,}: "Google", nil: "nil", } // Pointer as value type var m4 = map[string]*Vertex { "Bell Labs": &Vertex{40.68433, -74.39967}, "Google": &Vertex{37.42202, -122.08408}, } // Cannot omit type name `Vertex` if pointer is used as key/value type! */  - 
        
royling revised this gist
Apr 24, 2021 . 1 changed file with 3 additions and 3 deletions.There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -9,9 +9,9 @@ import ( func WordCount(s string) map[string]int { m := make(map[string]int) for _, w := range strings.Fields(s) { //if _, present := m[w]; !present { // m[w] = 0 //} m[w] += 1 }  - 
        
royling revised this gist
Apr 24, 2021 . 1 changed file with 2 additions and 2 deletions.There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -9,10 +9,10 @@ import ( func WordCount(s string) map[string]int { m := make(map[string]int) for _, w := range strings.Fields(s) { if _, present := m[w]; !present { m[w] = 0 } m[w] += 1 } return m  - 
        
royling revised this gist
Apr 24, 2021 . 1 changed file with 23 additions and 0 deletions.There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -0,0 +1,23 @@ package main import ( "strings" "golang.org/x/tour/wc" ) func WordCount(s string) map[string]int { m := make(map[string]int) for _, w := range strings.Fields(s) { _, present := m[w] if !present { m[w] = 0 } m[w] += 1 } return m } func main() { wc.Test(WordCount) }  - 
        
royling renamed this gist
Apr 24, 2021 . 1 changed file with 0 additions and 0 deletions.There are no files selected for viewing
File renamed without changes. - 
        
royling created this gist
Apr 23, 2021 .There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -0,0 +1,31 @@ package main import "golang.org/x/tour/pic" type Selector func(int, int) int type Renderer func(int, int) [][]uint8 func PicSelector(f Selector) Renderer { return func(dx, dy int) [][]uint8 { var res [][]uint8 for y := 0; y < dy; y++ { var e []uint8 for x := 0; x < dx; x++ { v := uint8(f(x, y)) e = append(e, v) } res = append(res, e) } return res } } func main() { pic.Show(PicSelector(func(x, y int) int { return (x + y) * (x - y) })) }