Last active
March 16, 2019 09:13
-
-
Save vzool/d399dd9f85df01743ff416c3852f1271 to your computer and use it in GitHub Desktop.
Nexus Births
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 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