Cody

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

Solution 2135503

Submitted on 21 Feb 2020 by Jiahang Li
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))

Init = 1 1 2 Init = 1 1 2 3 Init = 1 1 2 3 5 Init = 1 1 2 3 5 8 Init = 1 1 2 3 5 8 13 Init = 1 1 2 3 5 8 13 21 Init = 1 1 2 3 5 8 13 21 34 Init = 1 1 2 3 5 8 13 21 34 55 Init = 1 1 2 3 5 8 13 21 34 55 89 Init = 1 1 2 3 5 8 13 21 34 55 89 144 ans = 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))

Init = 2 3 5 Init = 2 3 5 8 Init = 2 3 5 8 13 Init = 2 3 5 8 13 21 Init = 2 3 5 8 13 21 34 Init = 2 3 5 8 13 21 34 55 Init = 2 3 5 8 13 21 34 55 89 Init = 2 3 5 8 13 21 34 55 89 144 Init = 2 3 5 8 13 21 34 55 89 144 233 Init = 2 3 5 8 13 21 34 55 89 144 233 377 ans = 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))

Init = 1 1 2 Init = 1 1 2 3 Init = 1 1 2 3 5 Init = 1 1 2 3 5 8 Init = 1 1 2 3 5 8 13 q = NaN NaN NaN NaN NaN NaN ans = 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))

Init = 1 3 4 Init = 1 3 4 7 Init = 1 3 4 7 11 Init = 1 3 4 7 11 18 Init = 1 3 4 7 11 18 29 Init = 1 3 4 7 11 18 29 47 Init = 1 3 4 7 11 18 29 47 76 Init = 1 3 4 7 11 18 29 47 76 123 Init = 1 3 4 7 11 18 29 47 76 123 199 Init = 1 3 4 7 11 18 29 47 76 123 199 322 ans = 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))

Init = 1 1 1 2 Init = 1 1 1 2 2 Init = 1 1 1 2 2 3 Init = 1 1 1 2 2 3 4 Init = 1 1 1 2 2 3 4 5 Init = 1 1 1 2 2 3 4 5 7 Init = 1 1 1 2 2 3 4 5 7 9 Init = 1 1 1 2 2 3 4 5 7 9 12 Init = 1 1 1 2 2 3 4 5 7 9 12 16 Init = 1 1 1 2 2 3 4 5 7 9 12 16 21 Init = 1 1 1 2 2 3 4 5 7 9 12 16 21 28 Init = 1 1 1 2 2 3 4 5 7 9 12 16 21 28 37 Init = 1 1 1 2 2 3 4 5 7 9 12 16 21 28 37 49 Init = 1 1 1 2 2 3 4 5 7 9 12 16 21 28 37 49 65 Init = 1 1 1 2 2 3 4 5 7 9 12 16 21 28 37 49 65 86 Init = 1 1 1 2 2 3 4 5 7 9 12 16 21 28 37 49 65 86 114 Init = 1 1 1 2 2 3 4 5 7 9 12 16 21 28 37 49 65 86 114 151 Init = 1 1 1 2 2 3 4 5 7 9 12 16 21 28 37 49 65 86 114 151 200 Init = 1 1 1 2 2 3 4 5 7 9 12 16 21 28 37 49 65 86 114 151 200 265 Init = 1 1 1 2 2 3 4 5 7 9 12 16 21 28 37 49 65 86 114 151 200 265 351 Init = 1 1 1 2 2 3 4 5 7 9 12 16 21 28 37 49 65 86 114 151 200 265 351 465 ans = 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))

Init = 0 1 2 Init = 0 1 2 5 Init = 0 1 2 5 12 Init = 0 1 2 5 12 29 Init = 0 1 2 5 12 29 70 Init = 0 1 2 5 12 29 70 169 Init = 0 1 2 5 12 29 70 169 408 Init = 0 1 2 5 12 29 70 169 408 985 Init = 0 1 2 5 12 29 70 169 408 985 2378 Init = 0 1 2 5 12 29 70 169 408 985 2378 5741 Init = 0 1 2 5 12 29 70 169 408 985 2378 5741 13860 Init = 0 1 2 5 12 29 70 169 408 985 2378 5741 13860 33461 Init = Columns 1 through 14 0 1 2 5 12 29 70 169 408 985 2378 5741 13860 33461 Column 15 80782 Init = Columns 1 through 14 0 1 2 5 12 29 70 169 408 985 2378 5741 13860 33461 Columns 15 through 16 80782 195025 Init = Columns 1 through 14 0 1 2 5 12 29 70 169 408 985 2378 5741 13860 33461 Columns 15 through 17 80782 195025 470832 Init = Columns 1 through 14 0 1 2 5 12 29 70 169 408 985 2378 5741 13860 33461 Columns 15 through 18 80782 195025 470832 1136689 Init = Columns 1 through 14 0 1 2 5 12 29 70 169 408 985 2378 5741 13860 33461 Columns 15 through 19 80782 195025 470832 1136689 2744210 Init = Columns 1 through 14 0 1 2 5 12 29 70 169 408 985 2378 5741 13860 33461 Columns 15 through 20 80782 195025 470832 1136689 2744210 6625109 Init = Columns 1 through 14 0 1 2 5 12 29 70 169 408 985 2378 5741 13860 33461 Columns 15 through 21 80782 195025 470832 1136689 2744210 6625109 15994428 ans = 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))

Init = 1 5 19 Init = 1 5 19 65 Init = 1 5 19 65 211 Init = 1 5 19 65 211 665 Init = 1 5 19 65 211 665 2059 Init = 1 5 19 65 211 665 2059 6305 Init = 1 5 19 65 211 665 2059 6305 19171 Init = 1 5 19 65 211 665 2059 6305 19171 58025 Init = 1 5 19 65 211 665 2059 6305 19171 58025 175099 Init = 1 5 19 65 211 665 2059 6305 19171 58025 175099 527345 ans = 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))

Init = 3 0 2 3 Init = 3 0 2 3 2 Init = 3 0 2 3 2 5 Init = 3 0 2 3 2 5 5 Init = 3 0 2 3 2 5 5 7 Init = 3 0 2 3 2 5 5 7 10 Init = 3 0 2 3 2 5 5 7 10 12 Init = 3 0 2 3 2 5 5 7 10 12 17 Init = 3 0 2 3 2 5 5 7 10 12 17 22 Init = 3 0 2 3 2 5 5 7 10 12 17 22 29 Init = 3 0 2 3 2 5 5 7 10 12 17 22 29 39 Init = 3 0 2 3 2 5 5 7 10 12 17 22 29 39 51 Init = 3 0 2 3 2 5 5 7 10 12 17 22 29 39 51 68 Init = 3 0 2 3 2 5 5 7 10 12 17 22 29 39 51 68 90 Init = 3 0 2 3 2 5 5 7 10 12 17 22 29 39 51 68 90 119 Init = 3 0 2 3 2 5 5 7 10 12 17 22 29 39 51 68 90 119 158 Init = 3 0 2 3 2 5 5 7 10 12 17 22 29 39 51 68 90 119 158 209 Init = 3 0 2 3 2 5 5 7 10 12 17 22 29 39 51 68 90 119 158 209 277 Init = 3 0 2 3 2 5 5 7 10 12 17 22 29 39 51 68 90 119 158 209 277 367 Init = 3 0 2 3 2 5 5 7 10 12 17 22 29 39 51 68 90 119 158 209 277 367 486 Init = 3 0 2 3 2 5 5 7 10 12 17 22 29 39 51 68 90 119 158 209 277 367 486 644 Init = 3 0 2 3 2 5 5 7 10 12 17 22 29 39 51 68 90 119 158 209 277 367 486 644 853 Init = Columns 1 through 14 3 0 2 3 2 5 5 7 10 12 17 22 29 39 Columns 15 through 26 51 68 90 119 158 209 277 367 486 644 853 1130 Init = Columns 1 through 14 3 0 2 3 2 5 5 7 10 12 17 22 29 39 Columns 15 through 27 51 68 90 119 158 209 277 367 486 644 853 1130 1497 Init = Columns 1 through 14 3 0 2 3 2 5 5 7 10 12 17 22 29 39 Columns 15 through 28 51 68 90 119 158 209 277 367 486 644 853 1130 1497 1983 Init = Columns 1 through 14 3 0 2 3 2 5 5 7 10 12 17 22 29 39 Columns 15 through 28 51 68 90 119 158 209 277 367 486 644 853 1130 1497 1983 Column 29 2627 Init = Columns 1 through 14 3 0 2 3 2 5 5 7 10 12 17 22 29 39 Columns 15 through 28 51 68 90 119 158 209 277 367 486 644 853 1130 1497 1983 Columns 29 through 30 2627 3480 Init = Columns 1 through 14 3 0 2 3 2 5 5 7 10 12 17 22 29 39 Columns 15 through 28 51 68 90 119 158 209 277 367 486 644 853 1130 1497 1983 Columns 29 through 31 2627 3480 4610 Init = Columns 1 through 14 3 0 2 3 2 5 5 7 10 12 17 22 29 39 Columns 15 through 28 51 68 90 119 158 209 277 367 486 644 853 1130 1497 1983 Columns 29 through 32 2627 3480 4610 6107 Init = Columns 1 through 14 3 0 2 3 2 5 5 7 10 12 17 22 29 39 Columns 15 through 28 51 68 90 119 158 209 277 367 486 644 853 1130 1497 1983 Columns 29 through 33 2627 3480 4610 6107 8090 Init = Columns 1 through 14 3 0 2 3 2 5 5 7 10 12 17 22 29 39 Columns 15 through 28 51 68 90 119 158 209 277 367 486 644 853 1130 1497 1983 Columns 29 through 34 2627 3480 4610 6107 8090 10717 Init = Columns 1 through 14 3 0 2 3 2 5 5 7 10 12 17 22 29 39 Columns 15 through 28 51 68 90 119 158 209 277 367 486 644 853 1130 1497 1983 Columns 29 through 35 2627 3480 4610 6107 8090 10717 14197 Init = Columns 1 through 14 3 0 2 3 2 5 5 7 10 12 17 22 29 39 Columns 15 through 28 51 68 90 119 158 209 277 367 486 644 853 1130 1497 1983 Columns 29 through 36 2627 3480 4610 6107 8090 10717 14197 18807 Init = Columns 1 through 14 3 0 2 3 2 5 5 7 10 12 17 22 29 39 Columns 15 through 28 51 68 90 119 158 209 277 367 486 644 853 1130 1497 1983 Columns 29 through 37 2627 3480 4610 6107 8090 10717 14197 18807 24914 Init = Columns 1 through 14 3 0 2 3 2 5 5 7 10 12 17 22 29 39 Columns 15 through 28 51 68 90 119 158 209 277 367 486 644 853 1130 1497 1983 Columns 29 through 38 2627 3480 4610 6107 8090 10717 14197 18807 24914 33004 Init = Columns 1 through 14 3 0 2 3 2 5 5 7 10 12 17 22 29 39 Columns 15 through 28 51 68 90 119 158 209 277 367 486 644 853 1130 1497 1983 Columns 29 through 39 2627 3480 4610 6107 8090 10717 14197 18807 24914 33004 43721 Init = Columns 1 through 14 3 0 2 3 2 5 5 7 10 12 17 22 29 39 Columns 15 through 28 51 68 90 119 158 209 277 367 486 644 853 1130 1497 1983 Columns 29 through 40 2627 3480 4610 6107 8090 10717 14197 18807 24914 33004 43721 57918 Init = Columns 1 through 14 3 0 2 3 2 5 5 7 10 12 17 22 29 39 Columns 15 through 28 51 68 90 119 158 209 277 367 486 644 853 1130 1497 1983 Columns 29 through 41 2627 3480 4610 6107 8090 10717 14197 18807 24914 33004 43721 57918 76725 ans = Columns 1 through 14 1983 2627 3480 4610 ...

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))

Init = 3 0 2 5 Init = 3 0 2 5 7 Init = 3 0 2 5 7 14 Init = 3 0 2 5 7 14 26 Init = 3 0 2 5 7 14 26 47 Init = 3 0 2 5 7 14 26 47 87 Init = 3 0 2 5 7 14 26 47 87 160 Init = 3 0 2 5 7 14 26 47 87 160 294 Init = 3 0 2 5 7 14 26 47 87 160 294 541 Init = 3 0 2 5 7 14 26 47 87 160 294 541 995 Init = 3 0 2 5 7 14 26 47 87 160 294 541 995 1830 Init = Columns 1 through 14 3 0 2 5 7 14 26 47 87 160 294 541 995 1830 Column 15 3366 Init = Columns 1 through 14 3 0 2 5 7 14 26 47 87 160 294 541 995 1830 Columns 15 through 16 3366 6191 Init = Columns 1 through 14 3 0 2 5 7 14 26 47 87 160 294 541 995 1830 Columns 15 through 17 3366 6191 11387 Init = Columns 1 through 14 3 0 2 5 7 14 26 47 87 160 294 541 995 1830 Columns 15 through 18 3366 6191 11387 20944 ans = Columns 1 through 14 3 0 2 5 7 14 26 47 87 160 294 541 995 1830 Column 15 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))

Init = 0 0 1 1 Init = 0 0 1 1 2 Init = 0 0 1 1 2 4 Init = 0 0 1 1 2 4 7 Init = 0 0 1 1 2 4 7 13 Init = 0 0 1 1 2 4 7 13 24 Init = 0 0 1 1 2 4 7 13 24 44 Init = 0 0 1 1 2 4 7 13 24 44 81 Init = 0 0 1 1 2 4 7 13 24 44 81 149 Init = 0 0 1 1 2 4 7 13 24 44 81 149 274 Init = 0 0 1 1 2 4 7 13 24 44 81 149 274 504 Init = 0 0 1 1 2 4 7 13 24 44 81 149 274 504 927 Init = Columns 1 through 14 0 0 1 1 2 4 7 13 24 44 81 149 274 504 Columns 15 through 16 927 1705 Init = Columns 1 through 14 0 0 1 1 2 4 7 13 24 44 81 149 274 504 Columns 15 through 17 927 1705 3136 Init = Columns 1 through 14 0 0 1 1 2 4 7 13 24 44 81 149 274 504 Columns 15 through 18 927 1705 3136 5768 Init = Columns 1 through 14 0 0 1 1 2 4 7 13 24 44 81 149 274 504 Columns 15 through 19 927 1705 3136 5768 10609 Init = Columns 1 through 14 0 0 1 1 2 4 7 13 24 44 81 149 274 504 Columns 15 through 20 927 1705 3136 5768 10609 19513 Init = Columns 1 through 14 0 0 1 1 2 4 7 13 24 44 81 149 274 504 Columns 15 through 21 927 1705 3136 5768 10609 19513 35890 Init = Columns 1 through 14 0 0 1 1 2 4 7 13 24 44 81 149 274 504 Columns 15 through 22 927 1705 3136 5768 10609 19513 35890 66012 Init = Columns 1 through 14 0 0 1 1 2 4 7 13 24 44 81 149 274 504 Columns 15 through 23 927 1705 3136 5768 10609 19513 35890 66012 121415 Init = Columns 1 through 14 0 0 1 1 2 4 7 13 24 44 81 149 274 504 Columns 15 through 24 927 1705 3136 5768 10609 19513 35890 66012 121415 223317 Init = Columns 1 through 14 0 0 1 1 2 4 7 13 24 44 81 149 274 504 Columns 15 through 25 927 1705 3136 5768 10609 19513 35890 66012 121415 223317 410744 Init = Columns 1 through 14 0 0 1 1 2 4 7 13 24 44 81 149 274 504 Columns 15 through 26 927 1705 3136 5768 10609 19513 35890 66012 121415 223317 410744 755476 ans = Columns 1 through 14 0 0 1 1 2 4 7 13 24 44 81 149 274 504 Columns 15 through 23 927 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))

Init = 0 0 0 1 1 Init = 0 0 0 1 1 2 Init = 0 0 0 1 1 2 4 Init = 0 0 0 1 1 2 4 8 Init = 0 0 0 1 1 2 4 8 15 Init = 0 0 0 1 1 2 4 8 15 29 Init = 0 0 0 1 1 2 4 8 15 29 56 Init = 0 0 0 1 1 2 4 8 15 29 56 108 Init = 0 0 0 1 1 2 4 8 15 29 56 108 208 Init = 0 0 0 1 1 2 4 8 15 29 56 108 208 401 Init = 0 0 0 1 1 2 4 8 15 29 56 108 208 401 773 Init = Columns 1 through 14 0 0 0 1 1 2 4 8 15 29 56 108 208 401 Columns 15 through 16 773 1490 Init = Columns 1 through 14 0 0 0 1 1 2 4 8 15 29 56 108 208 401 Columns 15 through 17 773 1490 2872 Init = Columns 1 through 14 0 0 0 1 1 2 4 8 15 29 56 108 208 401 Columns 15 through 18 773 1490 2872 5536 Init = Columns 1 through 14 0 0 0 1 1 2 4 8 15 29 56 108 208 401 Columns 15 through 19 773 1490 2872 5536 10671 Init = Columns 1 through 14 0 0 0 1 1 2 4 8 15 29 56 108 208 401 Columns 15 through 20 773 1490 2872 5536 10671 20569 Init = Columns 1 through 14 0 0 0 1 1 2 4 8 15 29 56 108 208 401 Columns 15 through 21 773 1490 2872 5536 10671 20569 39648 Init = Columns 1 through 14 0 0 0 1 1 2 4 8 15 29 56 108 208 401 Columns 15 through 22 773 1490 2872 5536 10671 20569 39648 76424 Init = Columns 1 through 14 0 0 0 1 1 2 4 8 15 29 56 108 208 401 Columns 15 through 23 773 1490 2872 5536 10671 20569 39648 76424 147312 Init = Columns 1 through 14 0 0 0 1 1 2 4 8 15 29 56 108 208 401 Columns 15 through 24 773 1490 2872 5536 10671 20569 39648 76424 147312 283953 Init = Columns 1 through 14 0 0 0 1 1 2 4 8 15 29 56 108 208 401 Columns 15 through 25 773 1490 2872 5536 10671 20569 39648 76424 147312 283953 547337 Init = Columns 1 through 14 0 0 0 1 1 2 4 8 15 29 56 108 208 401 Columns 15 through 26 773 1490 2872 5536 10671 20569 39648 76424 147312 283953 547337 1055026 Init = Columns 1 through 14 0 0 0 1 1 2 4 8 15 29 56 108 208 401 Columns 15 through 27 773 1490 2872 5536 10671 20569 39648 76424 147312 283953 547337 1055026 2033628 ans = 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))

Init = 0 0 0 0 0 0 1 1 Init = 0 0 0 0 0 0 1 1 2 Init = 0 0 0 0 0 0 1 1 2 4 Init = 0 0 0 0 0 0 1 1 2 4 8 Init = 0 0 0 0 0 0 1 1 2 4 8 16 Init = 0 0 0 0 0 0 1 1 2 4 8 16 32 Init = 0 0 0 0 0 0 1 1 2 4 8 16 32 64 Init = 0 0 0 0 0 0 1 1 2 4 8 16 32 64 127 Init = 0 0 0 0 0 0 1 1 2 4 8 16 32 64 127 253 Init = 0 0 0 0 0 0 1 1 2 4 8 16 32 64 127 253 504 Init = Columns 1 through 14 0 0 0 0 0 0 1 1 2 4 8 16 32 64 Columns 15 through 18 127 253 504 1004 Init = Columns 1 through 14 0 0 0 0 0 0 1 1 2 4 8 16 32 64 Columns 15 through 19 127 253 504 1004 2000 Init = Columns 1 through 14 0 0 0 0 0 0 1 1 2 4 8 16 32 64 Columns 15 through 20 127 253 504 1004 2000 3984 Init = Columns 1 through 14 0 0 0 0 0 0 1 1 2 4 8 16 32 64 Columns 15 through 21 127 253 504 1004 2000 3984 7936 Init = Columns 1 through 14 0 0 0 0 0 0 1 1 2 4 8 16 32 64 Columns 15 through 22 127 253 504 1004 2000 3984 7936 15808 Init = Columns 1 through 14 0 0 0 0 0 0 1 1 2 4 8 16 32 64 Columns 15 through 23 127 253 504 1004 2000 3984 7936 15808 31489 Init = Columns 1 through 14 0 0 0 0 0 0 1 1 2 4 8 16 32 64 Columns 15 through 24 127 253 504 1004 2000 3984 7936 15808 31489 62725 Init = Columns 1 through 14 0 0 0 0 0 0 1 1 2 4 8 16 32 64 Columns 15 through 25 127 253 504 1004 2000 3984 7936 15808 31489 62725 124946 Init = Columns 1 through 14 0 0 0 0 0 0 1 1 2 4 8 16 32 64 Columns 15 through 26 127 253 504 1004 2000 3984 7936 15808 31489 62725 124946 248888 ans = 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))

Init = 1 -1 2 Init = 1 -1 2 -3 Init = 1 -1 2 -3 5 Init = 1 -1 2 -3 5 -8 Init = 1 -1 2 -3 5 -8 13 Init = 1 -1 2 -3 5 -8 13 -21 Init = 1 -1 2 -3 5 -8 13 -21 34 Init = 1 -1 2 -3 5 -8 13 -21 34 -55 Init = 1 -1 2 -3 5 -8 13 -21 34 -55 89 Init = 1 -1 2 -3 5 -8 13 -21 34 -55 89 -144 ans = 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))

Init = 1 -1 -2 Init = 1 -1 -2 -1 Init = 1 -1 -2 -1 1 Init = 1 -1 -2 -1 1 2 Init = 1 -1 -2 -1 1 2 1 Init = 1 -1 -2 -1 1 2 1 -1 Init = 1 -1 -2 -1 1 2 1 -1 -2 Init = 1 -1 -2 -1 1 2 1 -1 -2 -1 Init = 1 -1 -2 -1 1 2 1 -1 -2 -1 1 Init = 1 -1 -2 -1 1 2 1 -1 -2 -1 1 2 ans = 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))

Init = 1 -1 0 Init = 1 -1 0 -1 Init = 1 -1 0 -1 -1 Init = 1 -1 0 -1 -1 -2 Init = 1 -1 0 -1 -1 -2 -3 Init = 1 -1 0 -1 -1 -2 -3 -5 Init = 1 -1 0 -1 -1 -2 -3 -5 -8 Init = 1 -1 0 -1 -1 -2 -3 -5 -8 -13 Init = 1 -1 0 -1 -1 -2 -3 -5 -8 -13 -21 Init = 1 -1 0 -1 -1 -2 -3 -5 -8 -13 -21 -34 ans = 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))

Init = 1 1 1 Init = 1 1 1 1 Init = 1 1 1 1 1 Init = 1 1 1 1 1 1 Init = 1 1 1 1 1 1 1 Init = 1 1 1 1 1 1 1 1 Init = 1 1 1 1 1 1 1 1 1 Init = 1 1 1 1 1 1 1 1 1 1 Init = 1 1 1 1 1 1 1 1 1 1 1 Init = 1 1 1 1 1 1 1 1 1 1 1 1 ans = 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))

Init = 1 2 0 Init = 1 2 0 4 Init = 1 2 0 4 -4 Init = 1 2 0 4 -4 12 Init = 1 2 0 4 -4 12 -20 Init = 1 2 0 4 -4 12 -20 44 Init = 1 2 0 4 -4 12 -20 44 -84 Init = 1 2 0 4 -4 12 -20 44 -84 172 Init = 1 2 0 4 -4 12 -20 44 -84 172 -340 Init = 1 2 0 4 -4 12 -20 44 -84 172 -340 684 ans = 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))

Init = 0 1 1 Init = 0 1 1 3 Init = 0 1 1 3 5 Init = 0 1 1 3 5 11 Init = 0 1 1 3 5 11 21 Init = 0 1 1 3 5 11 21 43 Init = 0 1 1 3 5 11 21 43 85 Init = 0 1 1 3 5 11 21 43 85 171 Init = 0 1 1 3 5 11 21 43 85 171 341 Init = 0 1 1 3 5 11 21 43 85 171 341 683 ans = 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))

Init = 1 0 2 1 Init = 1 0 2 1 3 Init = 1 0 2 1 3 2 Init = 1 0 2 1 3 2 4 Init = 1 0 2 1 3 2 4 3 Init = 1 0 2 1 3 2 4 3 5 Init = 1 0 2 1 3 2 4 3 5 4 Init = 1 0 2 1 3 2 4 3 5 4 6 Init = 1 0 2 1 3 2 4 3 5 4 6 5 Init = 1 0 2 1 3 2 4 3 5 4 6 5 7 Init = 1 0 2 1 3 2 4 3 5 4 6 5 7 6 Init = 1 0 2 1 3 2 4 3 5 4 6 5 7 6 8 Init = 1 0 2 1 3 2 4 3 5 4 6 5 7 6 8 7 Init = 1 0 2 1 3 2 4 3 5 4 6 5 7 6 8 7 9 Init = 1 0 2 1 3 2 4 3 5 4 6 5 7 6 8 7 9 8 Init = 1 0 2 1 3 2 4 3 5 4 6 5 7 6 8 7 9 8 10 Init = 1 0 2 1 3 2 4 3 5 4 6 5 7 6 8 7 9 8 10 9 Init = 1 0 2 1 3 2 4 3 5 4 6 5 7 6 8 7 9 8 10 9 11 Init = 1 0 2 1 3 2 4 3 5 4 6 5 7 6 8 7 9 8 10 9 11 10 Init = 1 0 2 1 3 2 4 3 5 4 6 5 7 6 8 7 9 8 10 9 11 10 12 ans = 1 0 2 1 3 2 4 3 5 4 6 5 7 6 8 7 9 8 10 9

### Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!