Leonardo numbers: Difference between revisions

Content added Content deleted
Line 1,761: Line 1,761:
/* main */
/* main */
main :: proc() {
main :: proc() {
fmt.println("\nThe first 25 Leonardo numbers with L[0] = 1, L[1] = 1 and add number = 1 are:")
fmt.println("\nThe first 25 Leonardo numbers with L[0] = 1, L[1] = 1 and add number = 1 are:")
fmt.println(leonardo(25, 1, 1, 1))
result := leonardo(25, 1, 1, 1)
fmt.println(result)
fmt.println("\nThe first 25 Leonardo numbers with L[0] = 0, L[1] = 1 and add number = 0 are:")
delete (result)
fmt.println(leonardo(25, 0, 1, 0))
fmt.println("\nThe first 25 Leonardo numbers with L[0] = 0, L[1] = 1 and add number = 0 are:")
result = leonardo(25, 0, 1, 0)
fmt.println(result)
delete (result)
}
}
/* definitions */
/* definitions */
leonardo :: proc(n, l0, l1, add: int) -> []int {
leonardo :: proc(n, l0, l1, add: int) -> []int {
leo := make([]int, n)
leo := make([]int, n)
leo[0] = l0
leo[0] = l0
leo[1] = l1
leo[1] = l1
for i in 2 ..< n {
for i in 2 ..< n {
leo[i] = leo[i - 1] + leo[i - 2] + add
leo[i] = leo[i - 1] + leo[i - 2] + add
}
}
return leo
return leo
}
}

</syntaxhighlight>
</syntaxhighlight>
{{out}}
{{out}}