Skip to content

Commit

Permalink
[go] Challenge 1 (Unreviewed) (YearOfProgramming#439)
Browse files Browse the repository at this point in the history
* [go] Challenge 1 (Unreviewed)

* Clean up README.md - I didn't keep as good of notes as I had intended
  • Loading branch information
tml authored and erocs committed Jan 23, 2017
1 parent cdf2b9a commit e032a3f
Show file tree
Hide file tree
Showing 2 changed files with 29 additions and 0 deletions.
6 changes: 6 additions & 0 deletions challenge_1/go/tml/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
# golang: Reverse a string

## My thought process
I don't want to do it in bytes - I want to use the runes support in golang
Tried the unicode normalization package, didn't really seem to make anything easier
http://devs.cloudimmunity.com/gotchas-and-common-mistakes-in-go-golang/ looks useful
23 changes: 23 additions & 0 deletions challenge_1/go/tml/src/strrev.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
package main

import (
"fmt"
"os"
"bufio"
)

func strrev(s string) string {
r := []rune(s)
rs := []rune{}
for i := len(r)-1; i>=0; i-- {
rs = append(rs, r[i])
}
return string(rs)
}

func main() {
scanner := bufio.NewScanner(os.Stdin)
for scanner.Scan() {
fmt.Println(strrev(scanner.Text()))
}
}

0 comments on commit e032a3f

Please sign in to comment.