Last active
August 29, 2015 14:26
-
-
Save apg/d548346a7009477ca88e 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
$ go run score.go | |
Test: [1 2 3] | |
score=0 | |
Test: [2 1 3] | |
score=1 | |
Test: [3 2 1] | |
score=2 | |
Test: [1 2 4 3 5] | |
score=1 | |
Test: [1 2 4 3 5 6 8 9 7] | |
score=2 |
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" | |
func sortScore(a []int) int { | |
var score int | |
for i := 0; i < len(a)-1; i++ { | |
if a[i] > a[i+1] { | |
score++ | |
} | |
} | |
return score | |
} | |
func main() { | |
tests := [][]int{ | |
[]int{1, 2, 3}, | |
[]int{2, 1, 3}, | |
[]int{3, 2, 1}, | |
[]int{1, 2, 4, 3, 5}, | |
[]int{1, 2, 4, 3, 5, 6, 8, 9, 7}, | |
} | |
for _, t := range tests { | |
fmt.Println("Test:", t) | |
fmt.Printf("\tscore=%d\n", sortScore(t)) | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment