Skip to content

Instantly share code, notes, and snippets.

@NicolaM94
Last active July 30, 2023 10:21
Show Gist options
  • Save NicolaM94/7b7c30cf402f7f88429160fb729f8f8b to your computer and use it in GitHub Desktop.
Save NicolaM94/7b7c30cf402f7f88429160fb729f8f8b to your computer and use it in GitHub Desktop.
Pascal's triangle algorithms without copying the array
func pascalTriangle (pascalLine []int) []int {
if compareSlices(pascalLine, []int{1}) {
return []int{1, 1}
}
for i, j := range pascalLine[:len(pascalLine)-1] {
pascalLine[i] = j + pascalLine[i+1]
}
return append([]int{1}, pascalLine...)
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment