Skip to content

Instantly share code, notes, and snippets.

@NicolaM94
Created July 29, 2023 17:15
Show Gist options
  • Save NicolaM94/25fd6adb19ddacb6233ae9ffab73e57b to your computer and use it in GitHub Desktop.
Save NicolaM94/25fd6adb19ddacb6233ae9ffab73e57b to your computer and use it in GitHub Desktop.
Pascal's triangle algorithm based on a recursive approach
func pascalTriangleRecursive(cnt, row int, elements []int) []int {
if cnt < row {
temp := []int{1}
for i, j := range elements[:len(elements)-1] {
temp = append(temp, j+elements[i+1])
}
temp = append(temp, 1)
return pascalTriangleRecursive(cnt+1, row, temp)
}
return elements
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment