Skip to content

Instantly share code, notes, and snippets.

@stek29
Created May 12, 2019 21:06
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save stek29/a06e630473b1fd6af091f47577efe37d to your computer and use it in GitHub Desktop.
Save stek29/a06e630473b1fd6af091f47577efe37d to your computer and use it in GitHub Desktop.
package main
import (
"bufio"
"fmt"
"os"
"strings"
"github.com/rivo/uniseg"
)
func reverseStringSlice(ss []string) {
last := len(ss) - 1
for i := 0; i < len(ss)/2; i++ {
ss[i], ss[last-i] = ss[last-i], ss[i]
}
}
func unicodeReverse(in string) string {
var chunks []string
gr := uniseg.NewGraphemes(in)
for gr.Next() {
chunks = append(chunks, gr.Str())
}
reverseStringSlice(chunks)
return strings.Join(chunks, "")
}
func main() {
scanner := bufio.NewScanner(os.Stdin)
for scanner.Scan() {
fmt.Println(unicodeReverse(scanner.Text()))
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment