Skip to content

Instantly share code, notes, and snippets.

@lepoetemaudit
Created July 8, 2018 12:40
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save lepoetemaudit/003723424f25f71de59189f2eb2477af to your computer and use it in GitHub Desktop.
Save lepoetemaudit/003723424f25f71de59189f2eb2477af to your computer and use it in GitHub Desktop.
sum in golang
package main
import "fmt"
func sum(numbers []int) int {
if len(numbers) == 0 {
return 0
} else {
return numbers[0] + sum(numbers[1:])
}
}
func main() {
fmt.Printf("result: %d", sum([]int { 1, 2, 3, 4 }))
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment