Skip to content

Instantly share code, notes, and snippets.

@stek29
Created May 12, 2019
Embed
What would you like to do?
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