Skip to content

Instantly share code, notes, and snippets.

@SebDeclercq
Created July 25, 2019 13:51
Show Gist options
  • Save SebDeclercq/aaaf0eac87459e26ddd47e94e078c9e9 to your computer and use it in GitHub Desktop.
Save SebDeclercq/aaaf0eac87459e26ddd47e94e078c9e9 to your computer and use it in GitHub Desktop.
package kata
import (
"sort"
"strings"
"strconv"
)
func MaxRot(n int64) int64 {
ints := strings.Split(strconv.FormatInt(n, 10), "")
sort.Sort(sort.Reverse(sort.StringSlice(ints)))
int_str := strings.Join(ints, "")
max, _ := strconv.ParseInt(int_str, 10, 64)
return max
}
package kata_test
import (
. "github.com/onsi/ginkgo"
. "github.com/onsi/gomega"
. "codewarrior/kata"
)
func dotest(n int64, exp int64) {
var ans = MaxRot(n)
Expect(ans).To(Equal(exp))
}
var _ = Describe("Tests MaxRot", func() {
It("should handle basic cases", func() {
dotest(38458215, 85821534)
dotest(195881031, 988103115)
dotest(896219342, 962193428)
})
})
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment