Skip to content

Instantly share code, notes, and snippets.

@vivan-snapretail
Created May 10, 2019 15:11
Show Gist options
  • Save vivan-snapretail/d2fbca18e7f48b5fb636906297ef372b to your computer and use it in GitHub Desktop.
Save vivan-snapretail/d2fbca18e7f48b5fb636906297ef372b to your computer and use it in GitHub Desktop.
coderbyte alphabet soup
package main
import "fmt"
import "sort"
type runeSorter []rune
func AlphabetSoup(str string) string {
// code goes here
sorted := SortString(str)
// Note: feel free to modify the return type of this function
return sorted
}
func SortString( s string) string {
r := []rune(s)
sort.Sort(runeSorter(r))
return string(r)
}
func (s runeSorter) Swap(i, j int) {
s[i],s[j] = s[j],s[i]
}
func (s runeSorter) Less(i, j int) bool {
return s[i] < s[j]
}
func (s runeSorter) Len() int {
return len(s)
}
func main() {
// do not modify below here, readline is our function
// that properly reads in the input for you
fmt.Println(AlphabetSoup(readline()))
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment