Cody

Problem 8057. (Linear) Recurrence Equations - Generalised Fibonacci-like sequences

Solution 1933923

Submitted on 13 Sep 2019 by 3-2
This solution is locked. To view this solution, you need to provide a solution of the same size or smaller.

Test Suite

Test Status Code Input and Output
1   Pass
Init = [1,1]; Rules = [1,1]; N = 1:10; values_correct = [1 1 2 3 5 8 13 21 34 55]; assert(isequal(recurrence_seq(N, Init, Rules),values_correct))

values = 1 values = 1 1 values = 1 1 2 values = 1 1 2 3 values = 1 1 2 3 5 values = 1 1 2 3 5 8 values = 1 1 2 3 5 8 13 values = 1 1 2 3 5 8 13 21 values = 1 1 2 3 5 8 13 21 34 values = 1 1 2 3 5 8 13 21 34 55

2   Pass
Init = [2,3]; Rules = [1,1]; N = 1:10; values_correct = [2, 3, 5, 8, 13, 21, 34, 55, 89, 144]; assert(isequal(recurrence_seq(N, Init, Rules),values_correct))

values = 2 values = 2 3 values = 2 3 5 values = 2 3 5 8 values = 2 3 5 8 13 values = 2 3 5 8 13 21 values = 2 3 5 8 13 21 34 values = 2 3 5 8 13 21 34 55 values = 2 3 5 8 13 21 34 55 89 values = 2 3 5 8 13 21 34 55 89 144

3   Pass
Init = [1,1]; Rules = [1,1]; N = -5:5; values_correct = [5, -3, 2, -1, 1, 0, 1, 1, 2, 3, 5]; values_accepted = [nan, nan, nan, nan, nan, nan, 1, 1, 2, 3, 5]; values = recurrence_seq(N, Init, Rules); assert(isequal(values,values_correct)||isequaln(values,values_accepted))

values = NaN values = NaN NaN values = NaN NaN NaN values = NaN NaN NaN NaN values = NaN NaN NaN NaN NaN values = NaN NaN NaN NaN NaN NaN values = NaN NaN NaN NaN NaN NaN 1 values = NaN NaN NaN NaN NaN NaN 1 1 values = NaN NaN NaN NaN NaN NaN 1 1 2 values = NaN NaN NaN NaN NaN NaN 1 1 2 3 values = NaN NaN NaN NaN NaN NaN 1 1 2 3 5

4   Pass
Init = [1,3]; Rules = [1,1]; N = 1:10; values_correct = [1, 3, 4, 7, 11, 18, 29, 47, 76, 123]; assert(isequal(recurrence_seq(N, Init, Rules),values_correct))

values = 1 values = 1 3 values = 1 3 4 values = 1 3 4 7 values = 1 3 4 7 11 values = 1 3 4 7 11 18 values = 1 3 4 7 11 18 29 values = 1 3 4 7 11 18 29 47 values = 1 3 4 7 11 18 29 47 76 values = 1 3 4 7 11 18 29 47 76 123

5   Pass
Init = [1, 1, 1]; Rules = [1, 1, 0]; N = 4:21; values_correct = [2, 2, 3, 4, 5, 7, 9, 12, 16, 21, 28, 37, 49, 65, 86, 114, 151, 200]; assert(isequal(recurrence_seq(N, Init, Rules),values_correct))

values = 2 values = 2 2 values = 2 2 3 values = 2 2 3 4 values = 2 2 3 4 5 values = 2 2 3 4 5 7 values = 2 2 3 4 5 7 9 values = 2 2 3 4 5 7 9 12 values = 2 2 3 4 5 7 9 12 16 values = 2 2 3 4 5 7 9 12 16 21 values = 2 2 3 4 5 7 9 12 16 21 28 values = 2 2 3 4 5 7 9 12 16 21 28 37 values = 2 2 3 4 5 7 9 12 16 21 28 37 49 values = 2 2 3 4 5 7 9 12 16 21 28 37 49 65 values = 2 2 3 4 5 7 9 12 16 21 28 37 49 65 86 values = 2 2 3 4 5 7 9 12 16 21 28 37 49 65 86 114 values = 2 2 3 4 5 7 9 12 16 21 28 37 49 65 86 114 151 values = 2 2 3 4 5 7 9 12 16 21 28 37 49 65 86 114 151 200

6   Pass
Init = [0, 1]; Rules = [1, 2]; N = 4:3:19; values_correct = [5, 70, 985, 13860, 195025, 2744210]; assert(isequal(recurrence_seq(N, Init, Rules),values_correct))

values = 5 values = 5 70 values = 5 70 985 values = 5 70 985 13860 values = 5 70 985 13860 195025 values = 5 70 985 13860 195025 2744210

7   Pass
Init = [3-2, 9-4]; Rules = [-6 5]; N = 1:10; values_correct = [1, 5, 19, 65, 211, 665, 2059, 6305, 19171, 58025]; assert(isequal(recurrence_seq(N, Init, Rules),values_correct))

values = 1 values = 1 5 values = 1 5 19 values = 1 5 19 65 values = 1 5 19 65 211 values = 1 5 19 65 211 665 values = 1 5 19 65 211 665 2059 values = 1 5 19 65 211 665 2059 6305 values = 1 5 19 65 211 665 2059 6305 19171 values = 1 5 19 65 211 665 2059 6305 19171 58025

8   Pass
Init = [3, 0, 2]; Rules = [1, 1, 0]; N = [28:38, 10:-1:1]; values_correct = [1983, 2627, 3480, 4610, 6107, 8090, 10717, 14197, 18807, 24914, 33004, 12, 10, 7, 5, 5, 2, 3, 2, 0, 3]; assert(isequal(recurrence_seq(N, Init, Rules),values_correct))

values = 1983 values = 1983 2627 values = 1983 2627 3480 values = 1983 2627 3480 4610 values = 1983 2627 3480 4610 6107 values = 1983 2627 3480 4610 6107 8090 values = 1983 2627 3480 4610 6107 8090 10717 values = 1983 2627 3480 4610 6107 8090 10717 14197 values = 1983 2627 3480 4610 6107 8090 10717 14197 18807 values = 1983 2627 3480 4610 6107 8090 10717 14197 18807 24914 values = 1983 2627 3480 4610 6107 8090 10717 14197 18807 24914 33004 values = 1983 2627 3480 4610 6107 8090 10717 14197 18807 24914 33004 12 values = 1983 2627 3480 4610 6107 8090 10717 14197 18807 24914 33004 12 10 values = 1983 2627 3480 4610 6107 8090 10717 14197 18807 24914 33004 12 10 7 values = 1983 2627 3480 4610 6107 8090 10717 14197 18807 24914 33004 12 10 7 5 values = Columns 1 through 15 1983 2627 3480 4610 6107 8090 10717 14197 18807 24914 33004 12 10 7 5 Column 16 5 values = Columns 1 through 15 1983 2627 3480 4610 6107 8090 10717 14197 18807 24914 33004 12 10 7 5 Columns 16 through 17 5 2 values = Columns 1 through 15 1983 2627 3480 4610 6107 8090 10717 14197 18807 24914 33004 12 10 7 5 Columns 16 through 18 5 2 3 values = Columns 1 through 15 1983 2627 3480 4610 6107 8090 10717 14197 18807 24914 33004 12 10 7 5 Columns 16 through 19 5 2 3 2 values = Columns 1 through 15 1983 2627 3480 4610 6107 8090 10717 14197 18807 24914 33004 12 10 7 5 Columns 16 through 20 5 2 3 2 0 values = Columns 1 through 15 1983 2627 3480 4610 6107 8090 10717 14197 18807 24914 33004 12 10 7 5 Columns 16 through 21 5 2 3 2 0 3

9   Pass
Init = [3, 0, 2]; % Perrin init Rules = [1, 1, 1]; % Tribonacci rules N = [1:15]; values_correct = [3, 0, 2, 5, 7, 14, 26, 47, 87, 160, 294, 541, 995, 1830, 3366]; assert(isequal(recurrence_seq(N, Init, Rules),values_correct))

values = 3 values = 3 0 values = 3 0 2 values = 3 0 2 5 values = 3 0 2 5 7 values = 3 0 2 5 7 14 values = 3 0 2 5 7 14 26 values = 3 0 2 5 7 14 26 47 values = 3 0 2 5 7 14 26 47 87 values = 3 0 2 5 7 14 26 47 87 160 values = 3 0 2 5 7 14 26 47 87 160 294 values = 3 0 2 5 7 14 26 47 87 160 294 541 values = 3 0 2 5 7 14 26 47 87 160 294 541 995 values = 3 0 2 5 7 14 26 47 87 160 294 541 995 1830 values = 3 0 2 5 7 14 26 47 87 160 294 541 995 1830 3366

10   Pass
Init = [0, 0, 1]; Rules = [1, 1, 1]; N = [1:23]; values_correct = [0, 0, 1, 1, 2, 4, 7, 13, 24, 44, 81, 149, 274, 504, 927, 1705, 3136, 5768, 10609, 19513, 35890, 66012, 121415]; assert(isequal(recurrence_seq(N, Init, Rules),values_correct))

values = 0 values = 0 0 values = 0 0 1 values = 0 0 1 1 values = 0 0 1 1 2 values = 0 0 1 1 2 4 values = 0 0 1 1 2 4 7 values = 0 0 1 1 2 4 7 13 values = 0 0 1 1 2 4 7 13 24 values = 0 0 1 1 2 4 7 13 24 44 values = 0 0 1 1 2 4 7 13 24 44 81 values = 0 0 1 1 2 4 7 13 24 44 81 149 values = 0 0 1 1 2 4 7 13 24 44 81 149 274 values = 0 0 1 1 2 4 7 13 24 44 81 149 274 504 values = 0 0 1 1 2 4 7 13 24 44 81 149 274 504 927 values = Columns 1 through 15 0 0 1 1 2 4 7 13 24 44 81 149 274 504 927 Column 16 1705 values = Columns 1 through 15 0 0 1 1 2 4 7 13 24 44 81 149 274 504 927 Columns 16 through 17 1705 3136 values = Columns 1 through 15 0 0 1 1 2 4 7 13 24 44 81 149 274 504 927 Columns 16 through 18 1705 3136 5768 values = Columns 1 through 15 0 0 1 1 2 4 7 13 24 44 81 149 274 504 927 Columns 16 through 19 1705 3136 5768 10609 values = Columns 1 through 15 0 0 1 1 2 4 7 13 24 44 81 149 274 504 927 Columns 16 through 20 1705 3136 5768 10609 19513 values = Columns 1 through 15 0 0 1 1 2 4 7 13 24 44 81 149 274 504 927 Columns 16 through 21 1705 3136 5768 10609 19513 35890 values = Columns 1 through 15 0 0 1 1 2 4 7 13 24 44 81 149 274 504 927 Columns 16 through 22 1705 3136 5768 10609 19513 35890 66012 values = Columns 1 through 15 0 0 1 1 2 4 7 13 24 44 81 149 274 504 927 Columns 16 through 23 1705 3136 5768 10609 19513 35890 66012 121415

11   Pass
Init = [0, 0, 0, 1]; Rules = [1, 1, 1, 1]; N = [20:23]; values_correct = [20569, 39648, 76424, 147312]; assert(isequal(recurrence_seq(N, Init, Rules),values_correct))

values = 20569 values = 20569 39648 values = 20569 39648 76424 values = 20569 39648 76424 147312

12   Pass
Init = [0, 0, 0, 0, 0, 0, 1]; Rules = [1, 1, 1, 1, 1, 1, 1]; N = [7:15, 19]; values_correct = [1, 1, 2, 4, 8, 16, 32, 64, 127, 2000]; assert(isequal(recurrence_seq(N, Init, Rules),values_correct))

values = 1 values = 1 1 values = 1 1 2 values = 1 1 2 4 values = 1 1 2 4 8 values = 1 1 2 4 8 16 values = 1 1 2 4 8 16 32 values = 1 1 2 4 8 16 32 64 values = 1 1 2 4 8 16 32 64 127 values = 1 1 2 4 8 16 32 64 127 2000

13   Pass
Init = [1, -1]; Rules = [1, -1]; N = 1:10; values_correct = [1, -1, 2, -3, 5, -8, 13, -21, 34, -55]; assert(isequal(recurrence_seq(N, Init, Rules),values_correct))

values = 1 values = 1 -1 values = 1 -1 2 values = 1 -1 2 -3 values = 1 -1 2 -3 5 values = 1 -1 2 -3 5 -8 values = 1 -1 2 -3 5 -8 13 values = 1 -1 2 -3 5 -8 13 -21 values = 1 -1 2 -3 5 -8 13 -21 34 values = 1 -1 2 -3 5 -8 13 -21 34 -55

14   Pass
Init = [1, -1]; Rules = [-1, 1]; N = 1:10; values_correct = [1, -1, -2, -1, 1, 2, 1, -1, -2, -1]; assert(isequal(recurrence_seq(N, Init, Rules),values_correct))

values = 1 values = 1 -1 values = 1 -1 -2 values = 1 -1 -2 -1 values = 1 -1 -2 -1 1 values = 1 -1 -2 -1 1 2 values = 1 -1 -2 -1 1 2 1 values = 1 -1 -2 -1 1 2 1 -1 values = 1 -1 -2 -1 1 2 1 -1 -2 values = 1 -1 -2 -1 1 2 1 -1 -2 -1

15   Pass
Init = [1, -1]; Rules = [1, 1]; N = 1:10; values_correct = [1, -1, 0, -1, -1, -2, -3, -5, -8, -13]; assert(isequal(recurrence_seq(N, Init, Rules),values_correct))

values = 1 values = 1 -1 values = 1 -1 0 values = 1 -1 0 -1 values = 1 -1 0 -1 -1 values = 1 -1 0 -1 -1 -2 values = 1 -1 0 -1 -1 -2 -3 values = 1 -1 0 -1 -1 -2 -3 -5 values = 1 -1 0 -1 -1 -2 -3 -5 -8 values = 1 -1 0 -1 -1 -2 -3 -5 -8 -13

16   Pass
Init = [1, 1]; Rules = [2, -1]; N = 1:10; values_correct = ones(1,10); assert(isequal(recurrence_seq(N, Init, Rules),values_correct))

values = 1 values = 1 1 values = 1 1 1 values = 1 1 1 1 values = 1 1 1 1 1 values = 1 1 1 1 1 1 values = 1 1 1 1 1 1 1 values = 1 1 1 1 1 1 1 1 values = 1 1 1 1 1 1 1 1 1 values = 1 1 1 1 1 1 1 1 1 1

17   Pass
Init = [1, 2]; Rules = [2, -1]; N = 1:10; values_correct = [1, 2, 0, 4, -4, 12, -20, 44, -84, 172]; assert(isequal(recurrence_seq(N, Init, Rules),values_correct))

values = 1 values = 1 2 values = 1 2 0 values = 1 2 0 4 values = 1 2 0 4 -4 values = 1 2 0 4 -4 12 values = 1 2 0 4 -4 12 -20 values = 1 2 0 4 -4 12 -20 44 values = 1 2 0 4 -4 12 -20 44 -84 values = 1 2 0 4 -4 12 -20 44 -84 172

18   Pass
Init = [0, 1]; Rules = [2, 1]; N = 1:10; values_correct = [0, 1, 1, 3, 5, 11, 21, 43, 85, 171]; assert(isequal(recurrence_seq(N, Init, Rules),values_correct))

values = 0 values = 0 1 values = 0 1 1 values = 0 1 1 3 values = 0 1 1 3 5 values = 0 1 1 3 5 11 values = 0 1 1 3 5 11 21 values = 0 1 1 3 5 11 21 43 values = 0 1 1 3 5 11 21 43 85 values = 0 1 1 3 5 11 21 43 85 171

19   Pass
Init = [1, 0, 2]; Rules = [-1 1 1]; N = 1:20; values_correct = [1, 0, 2, 1, 3, 2, 4, 3, 5, 4, 6, 5, 7, 6, 8, 7, 9, 8, 10, 9]; assert(isequal(recurrence_seq(N, Init, Rules),values_correct))

values = 1 values = 1 0 values = 1 0 2 values = 1 0 2 1 values = 1 0 2 1 3 values = 1 0 2 1 3 2 values = 1 0 2 1 3 2 4 values = 1 0 2 1 3 2 4 3 values = 1 0 2 1 3 2 4 3 5 values = 1 0 2 1 3 2 4 3 5 4 values = 1 0 2 1 3 2 4 3 5 4 6 values = 1 0 2 1 3 2 4 3 5 4 6 5 values = 1 0 2 1 3 2 4 3 5 4 6 5 7 values = 1 0 2 1 3 2 4 3 5 4 6 5 7 6 values = 1 0 2 1 3 2 4 3 5 4 6 5 7 6 8 values = 1 0 2 1 3 2 4 3 5 4 6 5 7 6 8 7 values = 1 0 2 1 3 2 4 3 5 4 6 5 7 6 8 7 9 values = 1 0 2 1 3 2 4 3 5 4 6 5 7 6 8 7 9 8 values = 1 0 2 1 3 2 4 3 5 4 6 5 7 6 8 7 9 8 10 values = 1 0 2 1 3 2 4 3 5 4 6 5 7 6 8 7 9 8 10 9