Skip to content

Instantly share code, notes, and snippets.

@vzool
Last active March 16, 2019 09:13
Show Gist options
  • Select an option

  • Save vzool/d399dd9f85df01743ff416c3852f1271 to your computer and use it in GitHub Desktop.

Select an option

Save vzool/d399dd9f85df01743ff416c3852f1271 to your computer and use it in GitHub Desktop.
Nexus Births
package main
import (
"fmt"
"sort"
"strconv"
"strings"
)
func main() {
for _, year := range []int{1988, 1996, 1994, 2000, 2001, 2003}{
fmt.Println(nexus(year))
}
}
func nexus(birthDate int) []int {
result := make([]int, 3)
birth := fmt.Sprint(birthDate)
var nums sort.StringSlice = strings.Split(birth, "")
nums.Sort()
startLine, err := strconv.Atoi(strings.Join(nums, ""))
if err != nil {
panic("error to convert")
}
result[0] = startLine
result[1] = birthDate
sort.Sort(sort.Reverse(nums[:]))
finishLine, err := strconv.Atoi(strings.Join(nums, ""))
if err != nil {
panic("error to convert")
}
result[2] = finishLine
return result
}
// OUTPUT
/*
[1889 1988 9881]
[1699 1996 9961]
[1499 1994 9941]
[2 2000 2000]
[12 2001 2100]
[23 2003 3200]
*/
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment