Leonardo numbers: Difference between revisions

m
→‎{{header|Wren}}: Changed to Wren S/H
m (→‎{{header|Wren}}: Changed to Wren S/H)
 
(8 intermediate revisions by 4 users not shown)
Line 962:
</pre>
 
=={{header|EasyLang}}==
<syntaxhighlight lang="easylang">
proc leonardo L0 L1 add . .
print "L0:" & L0 & " L1:" & L1 & " add:" & add
write L0 & " "
write L1 & " "
for i = 2 to 24
tmp = L0
L0 = L1
L1 = tmp + L1 + add
write L1 & " "
.
print ""
.
leonardo 1 1 1
leonardo 0 1 0
</syntaxhighlight>
 
=={{header|EMal}}==
<syntaxhighlight lang="emal">
fun leonardo = List by int n, int leo0, int leo1, int add
List leo = int[].with(n)
leo[0] = leo0
leo[1] = leo1
for int i = 2; i < n; ++i
leo[i] = leo[i - 1] + leo[i - 2] + add
end
return leo
end
writeLine("The first 25 Leonardo numbers with L[0] = 1, L[1] = 1 and add number = 1 are:")
writeLine(leonardo(25, 1, 1, 1))
writeLine()
writeLine("The first 25 Leonardo numbers with L[0] = 0, L[1] = 1 and add number = 0 are:")
writeLine(leonardo(25, 0, 1, 0))
</syntaxhighlight>
{{out}}
<pre>
The first 25 Leonardo numbers with L[0] = 1, L[1] = 1 and add number = 1 are:
[1,1,3,5,9,15,25,41,67,109,177,287,465,753,1219,1973,3193,5167,8361,13529,21891,35421,57313,92735,150049]
 
The first 25 Leonardo numbers with L[0] = 0, L[1] = 1 and add number = 0 are:
[0,1,1,2,3,5,8,13,21,34,55,89,144,233,377,610,987,1597,2584,4181,6765,10946,17711,28657,46368]
</pre>
 
=={{header|F#|F sharp}}==
Line 1,578 ⟶ 1,621:
<pre>{1, 1, 3, 5, 9, 15, 25, 41, 67, 109, 177, 287, 465, 753, 1219, 1973, 3193, 5167, 8361, 13529, 21891, 35421, 57313, 92735, 150049}
{0, 1, 1, 2, 3, 5, 8, 13, 21, 34, 55, 89, 144, 233, 377, 610, 987, 1597, 2584, 4181, 6765, 10946, 17711, 28657, 46368}</pre>
 
=={{header|Maxima}}==
<syntaxhighlight lang="maxima">
/* Function that return the terms of an specified Leonardo sequence */
leo_specified(n,L0,L1,add):=block(
if n=0 then L[n]:L0 else if n=1 then L[n]:L1 else L[n]:L[n-1]+L[n-2]+add,
L[n])$
 
/* Test cases */
/* First 25 terms of Leonardo numbers (specification (1,1,1)) */
makelist(leo_specified(i,1,1,1),i,0,25);
 
/* First 25 terms of Fibonacci numbers (specification (0,1,0)) */
makelist(leo_specified(i,0,1,0),i,0,25);
</syntaxhighlight>
{{out}}
<pre>
[1,1,3,5,9,15,25,41,67,109,177,287,465,753,1219,1973,3193,5167,8361,13529,21891,35421,57313,92735,150049,242785]
 
[0,1,1,2,3,5,8,13,21,34,55,89,144,233,377,610,987,1597,2584,4181,6765,10946,17711,28657,46368,75025]
</pre>
 
 
=={{header|min}}==
Line 1,705 ⟶ 1,770:
<pre>Leonardo[1,1,1]: 1 1 3 5 9 15 25 41 67 109 177 287 465 753 1219 1973 3193 5167 8361 13529 21891 35421 57313 92735 150049
Leonardo[0,1,0]: 0 1 1 2 3 5 8 13 21 34 55 89 144 233 377 610 987 1597 2584 4181 6765 10946 17711 28657 46368
</pre>
 
=={{header|Odin}}==
<syntaxhighlight lang="Go">
package main
/* imports */
import "core:fmt"
/* main */
main :: proc() {
fmt.println("\nThe first 25 Leonardo numbers with L[0] = 1, L[1] = 1 and add number = 1 are:")
result := leonardo(25, 1, 1, 1)
fmt.println(result)
delete(result)
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 */
leonardo :: proc(n, l0, l1, add: int) -> []int {
leo := make([]int, n)
leo[0] = l0
leo[1] = l1
for i in 2 ..< n {
leo[i] = leo[i - 1] + leo[i - 2] + add
}
return leo
}
</syntaxhighlight>
{{out}}
<pre>
The first 25 Leonardo numbers with L[0] = 1, L[1] = 1 and add number = 1 are:
[1, 1, 3, 5, 9, 15, 25, 41, 67, 109, 177, 287, 465, 753, 1219, 1973, 3193, 5167, 8361, 13529, 21891, 35421, 57313, 92735, 150049]
 
The first 25 Leonardo numbers with L[0] = 0, L[1] = 1 and add number = 0 are:
[0, 1, 1, 2, 3, 5, 8, 13, 21, 34, 55, 89, 144, 233, 377, 610, 987, 1597, 2584, 4181, 6765, 10946, 17711, 28657, 46368]
</pre>
 
Line 2,456 ⟶ 2,557:
 
=={{header|Wren}}==
<syntaxhighlight lang="ecmascriptwren">var leonardo = Fn.new { |first, add, limit|
var leo = List.filled(limit, 0)
leo[0] = first[0]
Line 2,479 ⟶ 2,580:
0 1 1 2 3 5 8 13 21 34 55 89 144 233 377 610 987 1597 2584 4181 6765 10946 17711 28657 46368
</pre>
 
 
=={{header|Yabasic}}==
9,476

edits