Skip to content

Instantly share code, notes, and snippets.

View GlenDC's full-sized avatar
🚀

Glen De Cauwsemaecker GlenDC

🚀
View GitHub Profile
@GlenDC
GlenDC / combinations.go
Last active August 29, 2015 14:01
Combinations of an array in Go
func AllUniqueCombinations_Recursive(combination, array []int, result [][]int) [][]int {
if len(array) > 0 {
for i := range array {
c := make([]int, 0, len(combination))
c = append(c, combination...)
c = append(c, array[i])
a := make([]int, 0, len(array)-1)
a = append(a, array[0:i]...)
a = append(a, array[i+1:]...)
result = AllUniqueCombinations_Recursive(c, a, result)
@GlenDC
GlenDC / permutations.go
Last active August 29, 2015 14:01
Permations of an array in Go
func Pow(x, n int) int {
return int(math.Pow(float64(x), float64(n)))
}
func Permutations(array []int) [][]int {
size := len(array)
total := Pow(2, size)
permutations := make([][]int, 0, total)
for i := 0; i < total; i++ {
package main
import "code.google.com/p/go-tour/pic"
func Pic(dx, dy int) [][]uint8 {
pic := make([][]uint8, dy)
for y := range pic {
pic[y] = make([]uint8, dx)
for x := range pic[y] {
pic[y][x] = uint8(x*y)