本文整理汇总了Golang中sort.Ints函数的典型用法代码示例。如果您正苦于以下问题:Golang Ints函数的具体用法?Golang Ints怎么用?Golang Ints使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了Ints函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Golang代码示例。
示例1: getAllInt
func getAllInt(t *testing.T, title string, path string, obj interface{}, exp []int) {
result := getAllInterface(t, title, path, obj)
if result == nil {
return
}
if len(result) != len(exp) {
t.Errorf("FAIL(%s): %s -> invalid length %d < %d", title, path, len(result), len(exp))
return
}
var intResult []int
for _, val := range result {
intResult = append(intResult, val.(int))
}
sort.Ints(exp)
sort.Ints(intResult)
for i := 0; i < len(intResult); i++ {
if intResult[i] != exp[i] {
t.Errorf("FAIL(%s): %s -> exp %d got %d", title, path, exp[i], intResult)
}
}
}
示例2: IsValid
func IsValid(sudoku Sudoku) bool {
for i := 0; i < SUDOKU_LENGTH; i++ {
rowNums := ScanRow(&sudoku, i)
sort.Ints(rowNums)
for i := 0; i < len(rowNums)-1; i++ {
if rowNums[i+1] == rowNums[i] {
return false
}
}
colNums := ScanCol(&sudoku, i)
sort.Ints(colNums)
for i := 0; i < len(colNums)-1; i++ {
if colNums[i+1] == colNums[i] {
return false
}
}
recNums := ScanRec(&sudoku, i)
sort.Ints(recNums)
for i := 0; i < len(recNums)-1; i++ {
if recNums[i+1] == recNums[i] {
return false
}
}
}
return true
}
示例3: Same
// Same determines whether the trees
// t1 and t2 contain the same values.
func Same(t1, t2 *tree.Tree) bool {
t1ch := make(chan int)
t2ch := make(chan int)
t1val := []int{}
t2val := []int{}
go Walk(t1, t1ch)
go Walk(t2, t2ch)
for i := range t1ch {
t1val = append(t1val, i)
}
for i := range t2ch {
t2val = append(t2val, i)
}
sort.Ints(t1val)
sort.Ints(t2val)
for i, _ := range t1val {
if t1val[i] != t2val[i] {
return false
}
}
return true
}
示例4: InitAssets
func InitAssets() {
if len(male) > 0 && len(female) > 0 {
return
}
filepath.Walk("img", func(path string, info os.FileInfo, err error) error {
re := regexp.MustCompile("/(male|female)/(\\D+)(\\d+)\\.png")
found := re.FindStringSubmatch(path)
if len(found) > 0 {
gender := found[1]
datatype := found[2]
index, err := strconv.Atoi(found[3])
if err == nil {
if gender == "male" {
male[datatype] = append(male[datatype], index)
} else if gender == "female" {
female[datatype] = append(female[datatype], index)
}
}
}
return nil
})
for _, value := range male {
sort.Ints(value)
}
for _, value := range female {
sort.Ints(value)
}
}
示例5: main
func main() {
f, err := os.Open("input.txt")
if err != nil {
panic(err)
}
total_wrapping := 0
total_length := 0
content, err := ioutil.ReadAll(f)
lines := strings.Split(string(content), "\n")
for _, line := range lines {
lwh := strings.Split(string(line), "x")
l, _ := strconv.Atoi(lwh[0])
w, _ := strconv.Atoi(lwh[1])
h, _ := strconv.Atoi(lwh[2])
side := []int{l * w, w * h, l * h}
sort.Ints(side)
min_side := side[0]
wrapping := 2*(l*w+w*h+l*h) + min_side
total_wrapping += wrapping
perimeter := []int{2 * (l + w), 2 * (w + h), 2 * (l + h)}
sort.Ints(perimeter)
min_perimeter := perimeter[0]
bow := l * w * h
total_length += min_perimeter + bow
}
fmt.Println(total_wrapping)
fmt.Println(total_length)
}
示例6: testProcUtil
func testProcUtil(t *testing.T, pid int) {
lwps, err := LWPs(pid)
if err != nil {
t.Fatal(err)
}
sort.Ints(lwps)
t.Logf("LWPs(%d) = %#v", pid, lwps)
children, err := Children(pid)
if err != nil {
t.Fatal(err)
}
sort.Ints(children)
t.Logf("Children(%d) = %#v", pid, children)
descendants, err := Descendants(pid)
if err != nil {
t.Fatal(err)
}
sort.Ints(descendants)
t.Logf("Descendants(%d) = %#v", pid, descendants)
descendantLWPs, err := DescendantLWPs(pid)
if err != nil {
t.Fatal(err)
}
sort.Ints(descendantLWPs)
t.Logf("DescendantLWPs(%d) = %#v", pid, descendantLWPs)
}
示例7: validate
// validate checks that a board with all cells set to {1-9}
// fulfills the constraints of a solved board
func (b *Board) validate() bool {
for i := 0; i < 9; i++ {
row := b.row(i)
col := b.col(i)
zone := b.zone(i)
sort.Ints(row)
sort.Ints(col)
sort.Ints(zone)
// Check duplicates
for i := 0; i < 8; i++ {
if row[i] == row[i+1] {
return false
}
if col[i] == col[i+1] {
return false
}
if zone[i] == zone[i+1] {
return false
}
}
}
return true
}
示例8: compareIntArray
func compareIntArray(i, j interface{}) int {
ia := interface{}(i).([]int)
ja := interface{}(j).([]int)
sort.Ints(ia)
sort.Ints(ja)
il := len(ia)
jl := len(ja)
result := 0
if il < jl {
result = -1
} else if il > jl {
result = 1
} else {
for i, iv := range ia {
jv := ja[i]
if iv != jv {
if iv < jv {
result = -1
} else if iv > jv {
result = 1
}
break
}
}
}
return result
}
示例9: calculateEstimatesBetweenNodes
func calculateEstimatesBetweenNodes(priceestimatestruct UberAPI, index int) (lowEstimate []int, duration []int, distance []float64) {
fmt.Println("length of low estimate array is:", len(priceestimatestruct.Prices))
lowEstimate = make([]int, len(priceestimatestruct.Prices))
for i := 0; i < len(priceestimatestruct.Prices); i++ {
lowEstimate[i] = priceestimatestruct.Prices[i].LowEstimate
}
duration = make([]int, len(priceestimatestruct.Prices))
for i := 0; i < len(priceestimatestruct.Prices); i++ {
duration[i] = priceestimatestruct.Prices[i].Duration
}
distance = make([]float64, len(priceestimatestruct.Prices))
for i := 0; i < len(priceestimatestruct.Prices); i++ {
distance[i] = priceestimatestruct.Prices[i].Distance
}
sort.Ints(lowEstimate)
sort.Ints(duration)
sort.Float64s(distance)
fmt.Println("Unsorted LowEstimate array : ", lowEstimate)
fmt.Println("Unsorted duration array : ", duration)
fmt.Println("Unsorted distance array : ", distance)
if lowEstimate[0] == 0 {
cheapestCostArray = append(cheapestCostArray, lowEstimate[1])
} else {
cheapestCostArray = append(cheapestCostArray, lowEstimate[0])
}
durationArray = append(durationArray, duration[0])
distanceArray = append(distanceArray, distance[0])
return cheapestCostArray, durationArray, distanceArray
}
开发者ID:sagardafle,项目名称:Uber-Trip-Planner-in-GO-programming-language,代码行数:33,代码来源:UberTrip_Planner_in_GOLang.go
示例10: cliDumpRevNat
func cliDumpRevNat(ctx *cli.Context) {
dump, err := client.RevNATDump()
if err != nil {
fmt.Fprintf(os.Stderr, "Warning: Unable to dump map: %s\n", err)
}
revNatFormat := map[int]string{}
revNatFormatKeysV4 := []int{}
revNatFormatKeysV6 := []int{}
for _, revNat := range dump {
revNatFormat[int(revNat.ID)] = revNat.String()
if revNat.IsIPv6() {
revNatFormatKeysV6 = append(revNatFormatKeysV6, int(revNat.ID))
} else {
revNatFormatKeysV4 = append(revNatFormatKeysV4, int(revNat.ID))
}
}
sort.Ints(revNatFormatKeysV6)
sort.Ints(revNatFormatKeysV4)
if len(revNatFormatKeysV6) != 0 {
fmt.Printf("IPv6:\n")
for _, revNATID := range revNatFormatKeysV6 {
fmt.Printf("%d => %s\n", revNATID, revNatFormat[revNATID])
}
}
if len(revNatFormatKeysV4) != 0 {
fmt.Printf("IPv4:\n")
for _, revNATID := range revNatFormatKeysV4 {
fmt.Printf("%d => %s\n", revNATID, revNatFormat[revNATID])
}
}
}
示例11: solve
func solve(mr *MyReader) {
x, y, z, n := I4(mr.Gis())
xs := []int{0, x}
ys := []int{0, y}
for _, da := range mr.NGis(n) {
d, a := I2(da)
if d == 0 {
xs = append(xs, a)
} else {
ys = append(ys, a)
}
}
sort.Ints(xs)
sort.Ints(ys)
minval := func(vs []int, r int) int {
for i := 1; i < len(vs); i++ {
r = Min(r, vs[i]-vs[i-1])
}
return r
}
xmin := minval(xs, x)
ymin := minval(ys, y)
ans := xmin * ymin * z
fmt.Println(ans)
}
示例12: Same
// Same determines whether the trees
// t1 and t2 contain the same values.
func Same(t1, t2 *tree.Tree) bool {
ch1 := make(chan int)
ch2 := make(chan int)
go Walk(t1, ch1)
go Walk(t2, ch2)
s1 := make([]int, 10)
s2 := make([]int, 10)
for i := 0; i < 10; i++ {
a := <-ch1
b := <-ch2
s1[i] = a
s2[i] = b
}
sort.Ints(s1)
sort.Ints(s2)
for i := 0; i < 10; i++ {
if s1[i] != s2[i] {
return false
}
}
return true
}
示例13: main
func main() {
fmt.Scan(&n, &m)
var temp string
for i := 0; i < n; i++ {
fmt.Scan(&temp, &j)
if temp == "ATK" {
atk = append(atk, j)
} else {
def = append(def, j)
}
}
for i := 0; i < m; i++ {
fmt.Scan(&j)
fox = append(fox, j)
}
sort.Ints(def)
sort.Ints(atk)
sort.Ints(fox)
a := killAll()
b := onlyatk()
if a > b {
fmt.Println(a)
} else {
fmt.Println(b)
}
}
示例14: TestDepthFirstSearch
func TestDepthFirstSearch(t *testing.T) {
G := NewAdjGraphForFile("./algs4-data/tinyG.txt")
var search Search
var slice []int
// test 1
search = NewDepthFirstSearch(G, 0)
assert.NotEqual(t, search.Count(), G.V())
slice = make([]int, 0)
for v := 0; v < G.V(); v++ {
if search.Marked(v) {
slice = append(slice, v)
}
}
sort.Ints(slice)
assert.Equal(t, slice, []int{0, 1, 2, 3, 4, 5, 6})
// test 2
search = NewDepthFirstSearch(G, 9)
assert.NotEqual(t, search.Count(), G.V())
slice = make([]int, 0)
for v := 0; v < G.V(); v++ {
if search.Marked(v) {
slice = append(slice, v)
}
}
sort.Ints(slice)
assert.Equal(t, slice, []int{9, 10, 11, 12})
}
示例15: main
func main() {
bi := bufio.NewReader(os.Stdin)
bo := bufio.NewWriter(os.Stdout)
defer bo.Flush()
var n, m int
fmt.Fscanln(bi, &n, &m)
g := make([]int, n)
for i := range g {
fmt.Fscan(bi, &g[i])
}
b := make([]int, m)
for i := range b {
fmt.Fscan(bi, &b[i])
}
sort.Ints(g)
sort.Ints(b)
res := sum(g) // no one takes
for k := 1; k <= min(len(b), len(g)); k++ {
new_res := sum(g[:len(g)-k]) + sum(b[:len(b)-k])*k
if new_res < res {
res = new_res
}
}
fmt.Fprintln(bo, res)
}