Padovan n-step number sequences: Difference between revisions
Content added Content deleted
Line 934: | Line 934: | ||
|- |
|- |
||
|} |
|} |
||
=={{header|Mathematica}}/{{header|Wolfram Language}}== |
|||
<lang Mathematica>ClearAll[Padovan] |
|||
Padovan[2,tmax_]:=Module[{start,a,m}, |
|||
start={1,1,1}; |
|||
start=MapIndexed[a[#2[[1]]]==#1&,start]; |
|||
RecurrenceTable[{a[m]==a[m-2]+a[m-3]}~Join~start,a, {m,tmax}] |
|||
] |
|||
Padovan[n_,tmax_]:=Module[{start,eq,a,m}, |
|||
start=Padovan[n-1,n+1]; |
|||
start=MapIndexed[a[#2[[1]]]==#1&,start]; |
|||
eq=Range[2,n+1]; |
|||
eq=Append[start,a[m]==Total[a[m-#]&/@eq]]; |
|||
RecurrenceTable[eq,a, {m,tmax}] |
|||
] |
|||
Padovan[2,15] |
|||
Padovan[3,15] |
|||
Padovan[4,15] |
|||
Padovan[5,15] |
|||
Padovan[6,15] |
|||
Padovan[7,15] |
|||
Padovan[8,15]</lang> |
|||
{{out}} |
|||
<pre>{1,1,1,2,2,3,4,5,7,9,12,16,21,28,37} |
|||
{1,1,1,2,3,4,6,9,13,19,28,41,60,88,129} |
|||
{1,1,1,2,3,5,7,11,17,26,40,61,94,144,221} |
|||
{1,1,1,2,3,5,8,12,19,30,47,74,116,182,286} |
|||
{1,1,1,2,3,5,8,13,20,32,51,81,129,205,326} |
|||
{1,1,1,2,3,5,8,13,21,33,53,85,136,218,349} |
|||
{1,1,1,2,3,5,8,13,21,34,54,87,140,225,362}</pre> |
|||
=={{header|Nim}}== |
=={{header|Nim}}== |