切片的使用

package main

import "fmt"

func main() {
	all := getNumComs()

	for _, v := range all {
		fmt.Println(v)
	}
	fmt.Println(len(all))

}

func getNumComs() [][][5]int {
	all := make([][][5]int, 0)
	array1 := [][5]int{{5, 6, 7, 8, 9}, {0, 1, 2, 3, 4}, {1, 3, 5, 7, 9}, {0, 2, 4, 6, 8}}
	array2 := [][5]int{{5, 6, 7, 8, 9}, {0, 1, 2, 3, 4}, {1, 3, 5, 7, 9}, {0, 2, 4, 6, 8}}
	array3 := [][5]int{{5, 6, 7, 8, 9}, {0, 1, 2, 3, 4}, {1, 3, 5, 7, 9}, {0, 2, 4, 6, 8}}
	array4 := [][5]int{{5, 6, 7, 8, 9}, {0, 1, 2, 3, 4}, {1, 3, 5, 7, 9}, {0, 2, 4, 6, 8}}

	for _, a := range array1 {
		for _, b := range array2 {
			for _, c := range array3 {
				for _, d := range array4 {
					oneArray := [][5]int{a, b, c, d}
					all = append(all, oneArray)
				}
			}
		}
	}

	return all
}
package main

import "fmt"

func main() {
	all := getNumComs()

	for _, v := range all {
		fmt.Println(v)
	}
	fmt.Println(len(all))

}

func getNumComs() [][][]int {
	all := make([][][]int, 0)
	array1 := [][]int{{5, 6, 7, 8, 9}, {0, 1, 2, 3, 4}, {1, 3, 5, 7, 9}, {0, 2, 4, 6, 8}}
	array2 := [][]int{{5, 6, 7, 8, 9}, {0, 1, 2, 3, 4}, {1, 3, 5, 7, 9}, {0, 2, 4, 6, 8}}
	array3 := [][]int{{5, 6, 7, 8, 9}, {0, 1, 2, 3, 4}, {1, 3, 5, 7, 9}, {0, 2, 4, 6, 8}}
	array4 := [][]int{{5, 6, 7, 8, 9}, {0, 1, 2, 3, 4}, {1, 3, 5, 7, 9}, {0, 2, 4, 6, 8}}

	for _, a := range array1 {
		for _, b := range array2 {
			for _, c := range array3 {
				for _, d := range array4 {
					oneArray := [][]int{a, b, c, d}
					all = append(all, oneArray)
				}
			}
		}
	}

	return all
}

Posted in Go