Created
May 11, 2014 07:06
-
-
Save sideb0ard/8cf033e70989991e2a3e to your computer and use it in GitHub Desktop.
This file contains 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 ( | |
"bytes" | |
"fmt" | |
"log" | |
"os" | |
"strconv" | |
) | |
func main() { | |
if len(os.Args) == 1 { | |
log.Fatal("GIMME NUMZZZZ") | |
} | |
fmt.Println("STRINGY:" + stringify(os.Args[1:])) | |
var numzarray []int | |
for i := range os.Args[1:] { | |
inny, _ := strconv.ParseInt(os.Args[i+1], 10, 32) | |
numzarray = append(numzarray, int(inny)) | |
} | |
for i := range numzarray[1:] { | |
current := numzarray[i+1] | |
fmt.Println("CURRENT IS : ", current) | |
j := i | |
fmt.Println("J VAL IS: ", numzarray[j]) | |
for j >= 0 && numzarray[j] > current { | |
fmt.Println("J greater than or eq to zero and numzarray[j] > current, hence: numzarray[j=1] = numzaraay[j]. Decrementing J") | |
numzarray[j+1] = numzarray[j] | |
j = j - 1 | |
fmt.Println("SORTEDNUMZ: ", numzarray) | |
} | |
numzarray[j+1] = current | |
fmt.Println("SORTEDNUMZ: ", numzarray) | |
} | |
fmt.Println("SORTEDNUMZ: ", numzarray) | |
} | |
func stringify(stingz []string) string { | |
var unifiedString bytes.Buffer | |
for i := range stingz { | |
if i != 0 { | |
unifiedString.WriteString(" ") | |
} | |
unifiedString.WriteString(stingz[i]) | |
} | |
return unifiedString.String() | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment