Skip to content

Instantly share code, notes, and snippets.

@sideb0ard
Created May 11, 2014 07:06
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save sideb0ard/8cf033e70989991e2a3e to your computer and use it in GitHub Desktop.
Save sideb0ard/8cf033e70989991e2a3e to your computer and use it in GitHub Desktop.
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