Created
July 25, 2019 13:51
-
-
Save SebDeclercq/aaaf0eac87459e26ddd47e94e078c9e9 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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