Patience, young “Padovan”












4












$begingroup$


Everyone knows the Fibonacci sequence:

You take a square, attach an equal square to it, then repeatedly attach a square whose side length is equal to the largest side length of the resulting rectangle.

The result is a beautiful spiral of squares whose sequence of numbers is the Fibonacci sequence:





But, what if we didn't want to use squares?



If we use equilateral triangles—instead of squares—in a similar fashion, we get an equally beautiful spiral of triangles and a new sequence: the Padovan sequence, aka A000931:





Task:



Given a positive integer, $N$, output $a_N$, the $N$th term in the Padovan sequence OR the first $N$ terms.



Assume that the first three terms of the sequence are all $1$. Thus, the sequence will start as follows:
$$
1,1,1,2,2,3,...
$$



Input:




  • Any positive integer $Nge0$


  • Invalid input does not have to be taken into account



Output:




  • The $N$th term in the Padovan sequence OR the first $N$ terms of the Padovan sequence.


  • If the first $N$ terms are printed out, the output can be whatever is convenient (list/array, multi-line string, etc.)


  • Can be either $0$-indexed or $1$-indexed



Test Cases:

(0-indexed, $N$th term)



Input | Output
--------------
0 | 1
1 | 1
2 | 1
4 | 2
6 | 4
14 | 37
20 | 200
33 | 7739


(0-indexed, first $N$ terms)



Input | Output
--------------
1 | 1
3 | 1,1,1
4 | 1,1,1,2
7 | 1,1,1,2,2,3,4
10 | 1,1,1,2,2,3,4,5,7,9
12 | 1,1,1,2,2,3,4,5,7,9,12,16


Rules:




  • This is code-golf: the fewer bytes, the better!


  • Standard loopholes are forbidden.











share|improve this question











$endgroup$












  • $begingroup$
    Sandbox post can be found here.
    $endgroup$
    – Tau
    5 hours ago






  • 1




    $begingroup$
    14 (0-indexed) is shown as outputting 28 while I believe it should yield 37
    $endgroup$
    – Jonathan Allan
    5 hours ago










  • $begingroup$
    @JonathanAllan yes, you are correct. I fixed the last two test cases for $N$th term but not that one. The post has been edited.
    $endgroup$
    – Tau
    5 hours ago
















4












$begingroup$


Everyone knows the Fibonacci sequence:

You take a square, attach an equal square to it, then repeatedly attach a square whose side length is equal to the largest side length of the resulting rectangle.

The result is a beautiful spiral of squares whose sequence of numbers is the Fibonacci sequence:





But, what if we didn't want to use squares?



If we use equilateral triangles—instead of squares—in a similar fashion, we get an equally beautiful spiral of triangles and a new sequence: the Padovan sequence, aka A000931:





Task:



Given a positive integer, $N$, output $a_N$, the $N$th term in the Padovan sequence OR the first $N$ terms.



Assume that the first three terms of the sequence are all $1$. Thus, the sequence will start as follows:
$$
1,1,1,2,2,3,...
$$



Input:




  • Any positive integer $Nge0$


  • Invalid input does not have to be taken into account



Output:




  • The $N$th term in the Padovan sequence OR the first $N$ terms of the Padovan sequence.


  • If the first $N$ terms are printed out, the output can be whatever is convenient (list/array, multi-line string, etc.)


  • Can be either $0$-indexed or $1$-indexed



Test Cases:

(0-indexed, $N$th term)



Input | Output
--------------
0 | 1
1 | 1
2 | 1
4 | 2
6 | 4
14 | 37
20 | 200
33 | 7739


(0-indexed, first $N$ terms)



Input | Output
--------------
1 | 1
3 | 1,1,1
4 | 1,1,1,2
7 | 1,1,1,2,2,3,4
10 | 1,1,1,2,2,3,4,5,7,9
12 | 1,1,1,2,2,3,4,5,7,9,12,16


Rules:




  • This is code-golf: the fewer bytes, the better!


  • Standard loopholes are forbidden.











share|improve this question











$endgroup$












  • $begingroup$
    Sandbox post can be found here.
    $endgroup$
    – Tau
    5 hours ago






  • 1




    $begingroup$
    14 (0-indexed) is shown as outputting 28 while I believe it should yield 37
    $endgroup$
    – Jonathan Allan
    5 hours ago










  • $begingroup$
    @JonathanAllan yes, you are correct. I fixed the last two test cases for $N$th term but not that one. The post has been edited.
    $endgroup$
    – Tau
    5 hours ago














4












4








4


1



$begingroup$


Everyone knows the Fibonacci sequence:

You take a square, attach an equal square to it, then repeatedly attach a square whose side length is equal to the largest side length of the resulting rectangle.

The result is a beautiful spiral of squares whose sequence of numbers is the Fibonacci sequence:





But, what if we didn't want to use squares?



If we use equilateral triangles—instead of squares—in a similar fashion, we get an equally beautiful spiral of triangles and a new sequence: the Padovan sequence, aka A000931:





Task:



Given a positive integer, $N$, output $a_N$, the $N$th term in the Padovan sequence OR the first $N$ terms.



Assume that the first three terms of the sequence are all $1$. Thus, the sequence will start as follows:
$$
1,1,1,2,2,3,...
$$



Input:




  • Any positive integer $Nge0$


  • Invalid input does not have to be taken into account



Output:




  • The $N$th term in the Padovan sequence OR the first $N$ terms of the Padovan sequence.


  • If the first $N$ terms are printed out, the output can be whatever is convenient (list/array, multi-line string, etc.)


  • Can be either $0$-indexed or $1$-indexed



Test Cases:

(0-indexed, $N$th term)



Input | Output
--------------
0 | 1
1 | 1
2 | 1
4 | 2
6 | 4
14 | 37
20 | 200
33 | 7739


(0-indexed, first $N$ terms)



Input | Output
--------------
1 | 1
3 | 1,1,1
4 | 1,1,1,2
7 | 1,1,1,2,2,3,4
10 | 1,1,1,2,2,3,4,5,7,9
12 | 1,1,1,2,2,3,4,5,7,9,12,16


Rules:




  • This is code-golf: the fewer bytes, the better!


  • Standard loopholes are forbidden.











share|improve this question











$endgroup$




Everyone knows the Fibonacci sequence:

You take a square, attach an equal square to it, then repeatedly attach a square whose side length is equal to the largest side length of the resulting rectangle.

The result is a beautiful spiral of squares whose sequence of numbers is the Fibonacci sequence:





But, what if we didn't want to use squares?



If we use equilateral triangles—instead of squares—in a similar fashion, we get an equally beautiful spiral of triangles and a new sequence: the Padovan sequence, aka A000931:





Task:



Given a positive integer, $N$, output $a_N$, the $N$th term in the Padovan sequence OR the first $N$ terms.



Assume that the first three terms of the sequence are all $1$. Thus, the sequence will start as follows:
$$
1,1,1,2,2,3,...
$$



Input:




  • Any positive integer $Nge0$


  • Invalid input does not have to be taken into account



Output:




  • The $N$th term in the Padovan sequence OR the first $N$ terms of the Padovan sequence.


  • If the first $N$ terms are printed out, the output can be whatever is convenient (list/array, multi-line string, etc.)


  • Can be either $0$-indexed or $1$-indexed



Test Cases:

(0-indexed, $N$th term)



Input | Output
--------------
0 | 1
1 | 1
2 | 1
4 | 2
6 | 4
14 | 37
20 | 200
33 | 7739


(0-indexed, first $N$ terms)



Input | Output
--------------
1 | 1
3 | 1,1,1
4 | 1,1,1,2
7 | 1,1,1,2,2,3,4
10 | 1,1,1,2,2,3,4,5,7,9
12 | 1,1,1,2,2,3,4,5,7,9,12,16


Rules:




  • This is code-golf: the fewer bytes, the better!


  • Standard loopholes are forbidden.








code-golf number sequence






share|improve this question















share|improve this question













share|improve this question




share|improve this question








edited 5 hours ago







Tau

















asked 5 hours ago









TauTau

801313




801313












  • $begingroup$
    Sandbox post can be found here.
    $endgroup$
    – Tau
    5 hours ago






  • 1




    $begingroup$
    14 (0-indexed) is shown as outputting 28 while I believe it should yield 37
    $endgroup$
    – Jonathan Allan
    5 hours ago










  • $begingroup$
    @JonathanAllan yes, you are correct. I fixed the last two test cases for $N$th term but not that one. The post has been edited.
    $endgroup$
    – Tau
    5 hours ago


















  • $begingroup$
    Sandbox post can be found here.
    $endgroup$
    – Tau
    5 hours ago






  • 1




    $begingroup$
    14 (0-indexed) is shown as outputting 28 while I believe it should yield 37
    $endgroup$
    – Jonathan Allan
    5 hours ago










  • $begingroup$
    @JonathanAllan yes, you are correct. I fixed the last two test cases for $N$th term but not that one. The post has been edited.
    $endgroup$
    – Tau
    5 hours ago
















$begingroup$
Sandbox post can be found here.
$endgroup$
– Tau
5 hours ago




$begingroup$
Sandbox post can be found here.
$endgroup$
– Tau
5 hours ago




1




1




$begingroup$
14 (0-indexed) is shown as outputting 28 while I believe it should yield 37
$endgroup$
– Jonathan Allan
5 hours ago




$begingroup$
14 (0-indexed) is shown as outputting 28 while I believe it should yield 37
$endgroup$
– Jonathan Allan
5 hours ago












$begingroup$
@JonathanAllan yes, you are correct. I fixed the last two test cases for $N$th term but not that one. The post has been edited.
$endgroup$
– Tau
5 hours ago




$begingroup$
@JonathanAllan yes, you are correct. I fixed the last two test cases for $N$th term but not that one. The post has been edited.
$endgroup$
– Tau
5 hours ago










19 Answers
19






active

oldest

votes


















6












$begingroup$


Haskell, 26 bytes





(l!!)
l=1:1:1:2:scanl(+)2l


Try it online! Outputs the n'th term zero-indexed.



I thought that the "obvious" recursive solution below would be unbeatable, but then I found this. It's similar to the classic golfy expression l=1:scanl(+)1l for the infinite Fibonacci list, but here the difference between adjacent elements is the term 4 positions back. We can more directly write l=1:1:zipWith(+)l(0:l), but that's longer.



If this challenge allowed infinite list output, we could cut the first line and have 20 bytes.



27 bytes





f n|n<3=1|1>0=f(n-2)+f(n-3)


Try it online!






share|improve this answer









$endgroup$





















    5












    $begingroup$


    Oasis, 5 bytes



    nth term 0-indexed



    cd+1V


    Try it online!



    Explanation



       1V   # a(0) = 1
    # a(1) = 1
    # a(2) = 1
    # a(n) =
    c # a(n-2)
    + # +
    d # a(n-3)





    share|improve this answer









    $endgroup$





















      5












      $begingroup$


      Python 2, 30 bytes





      f=lambda n:n<3or f(n-2)+f(n-3)


      Try it online!



      Returns the n'th term zero indexed. Outputs True for 1.






      share|improve this answer











      $endgroup$





















        3












        $begingroup$


        Wolfram Language (Mathematica), 33 bytes



        a@0=a@1=a@2=1;a@n_:=a[n-2]+a[n-3]   


        1-indexed, returns the nth term



        Try it online!






        share|improve this answer









        $endgroup$





















          3












          $begingroup$


          Jelly, 11 bytes



          5B+Ɲ2ị;Ʋ⁸¡Ḣ


          Try it online!



          0-indexed.






          share|improve this answer











          $endgroup$













          • $begingroup$
            Can you specify whether this answer is 0-indexed or 1-indexed?
            $endgroup$
            – Tau
            5 hours ago










          • $begingroup$
            @Tau It's 0-indexed. I've edited it in.
            $endgroup$
            – Erik the Outgolfer
            5 hours ago





















          3












          $begingroup$


          Jelly, 10 bytes



          ‘HRcḤạ¥¥‘S


          A monadic Link accepting n (1-indexed) which yields P(n).



          Try it online!



          How?



          Implements $P(n) = sum_{i=1}^{lfloorfrac{n+1}2rfloor}binom{2i}{n+1-2i}$



          ‘HRcḤạ¥¥‘S - Link: integer, n       e.g. 21
          ‘ - increment n 22
          H - halve 11
          R - range [1, 2, 3, 4, 5, 6, 7, 8, 9,10,11]
          - (note: floors input, e.g. n=6 -> ‘=7 -> H=3.5 -> R=[1,2,3] )
          ‘ - increment n 21
          ¥ - last two links as a dyad:
          ¥ - last two links as a dyad:
          Ḥ - double [ 2, 4, 6, 8,10,12,14,16,18,20,22]
          ạ - absolute difference [20,18,16,14,12,10, 8, 6, 4, 2, 0]
          c - left-choose-right [ 0, 0, 0, 0, 0, 0, 0,28,126,45,1]
          S - sum 200





          share|improve this answer











          $endgroup$





















            3












            $begingroup$


            Jelly, 10 bytes



            9s3’Ẓæ*³FṀ


            Try it online!



            1-indexed. Computes the largest element of: $$begin{bmatrix}0&0&1 \ 1&0&1 \ 0&1&0end{bmatrix}^n$$
            where the binary matrix is conveniently computed as: $$begin{bmatrix}mathsf{isprime}(0)&mathsf{isprime}(1)&mathsf{isprime}(2) \ mathsf{isprime}(3)&mathsf{isprime}(4)&mathsf{isprime}(5) \ mathsf{isprime}(6)&mathsf{isprime}(7)&mathsf{isprime}(8)end{bmatrix}$$



            (this is a total coincidence.)



            9s3         [[1,2,3],[4,5,6],[7,8,9]]    9 split 3
            ’ [[0,1,2],[3,4,5],[6,7,8]] decrease
            Ẓ [[0,0,1],[1,0,1],[0,1,0]] isprime
            æ*³ [[0,0,1],[1,0,1],[0,1,0]]^n matrix power by input
            FṀ flatten, maximum





            share|improve this answer









            $endgroup$





















              2












              $begingroup$


              Python 2, 56 48 bytes





              f=lambda n,a=1,b=1,c=1:n>2and f(n-1,b,c,a+b)or c


              Try it online!



              Returns nth value, 0-indexed.






              share|improve this answer









              $endgroup$





















                2












                $begingroup$


                Japt -N, 12 bytes



                <3ªßUµ2 +ß´U


                Try it






                share|improve this answer









                $endgroup$













                • $begingroup$
                  Looks like 12 is the best we can do :
                  $endgroup$
                  – Shaggy
                  3 hours ago



















                2












                $begingroup$


                Retina, 47 42 bytes



                K`0¶1¶0
                "$+"+`.+¶(.+)¶.+$
                $&¶$.(*_$1*
                6,G`


                Try it online! Outputs the first n terms on separate lines. Explanation:



                K`0¶1¶0


                Replace the input with the terms for -2, -1 and 0.



                "$+"+`.+¶(.+)¶.+$
                $&¶$.(*_$1*


                Generate the next n terms using the recurrence relation. *_ here is short for $&*_ which converts the (first) number in the match to unary, while $1* is short for $1*_ which converts the middle number to unary. The $.( returns the decimal sum of its unary arguments, i.e. the sum of the first and middle numbers.



                6,G`


                Discard the first six characters, i.e. the first three lines.






                share|improve this answer











                $endgroup$





















                  2












                  $begingroup$


                  Perl 6, 24 bytes



                  {(1,1,1,*+*+!*...*)[$_]}


                  Try it online!



                  A pretty standard generated sequence, with each new element generated by the expression * + * + !*. That adds the third-previous element, the second-previous element, and the logical negation of the previous element, which is always False, which is numerically zero.






                  share|improve this answer











                  $endgroup$













                  • $begingroup$
                    Why is this community wiki?
                    $endgroup$
                    – Jo King
                    2 hours ago



















                  2












                  $begingroup$


                  J, 24 bytes



                  closed form, 26 bytes



                  0.5<.@+1.04535%~1.32472^<:


                  Try it online!



                  iterative, 24 bytes



                  (],1#._2 _3{ ::1:])^:[1:


                  Try it online!






                  share|improve this answer











                  $endgroup$





















                    1












                    $begingroup$


                    C# (Visual C# Interactive Compiler), 34 bytes





                    int f(int g)=>g<3?1:f(g-2)+f(g-3);


                    Try it online!






                    share|improve this answer









                    $endgroup$





















                      1












                      $begingroup$

                      JavaScript (ES6), 23 bytes



                      Implements the recursive definition of A000931. Returns the $N$th term, 0-indexed.





                      f=n=>n<3||f(n-2)+f(n-3)


                      Try it online!






                      share|improve this answer











                      $endgroup$





















                        1












                        $begingroup$


                        Japt, 12 bytes



                        Returns the first n terms, 0-indexed. Replace h with g to return the nth term, 1-indexed.



                        ÈnZs3n)x}hBì


                        Try it



                        (Explanation to follow when my exhaustion wears off!)






                        share|improve this answer











                        $endgroup$





















                          1












                          $begingroup$


                          Lua 5.3, 49 bytes





                          function f(n)return n<=3 and 1or f(n-2)+f(n-3)end


                          Try it online!



                          Vanilla Lua doesn't have coercion of booleans to strings (even tonumber(true) returns nil), so you have to use a pseudo-ternary operator. This version is 1-indexed, like all of Lua. The 1or part has to be changed to 1 or in Lua 5.1, which has a different way of lexing numbers.






                          share|improve this answer











                          $endgroup$













                          • $begingroup$
                            <=3 can be <4
                            $endgroup$
                            – Jo King
                            2 hours ago



















                          1












                          $begingroup$


                          Cubix, 20 bytes



                          This is 0 indexed and outputs the Nth term



                          ;@UOI010+p?/sqq;W.(


                          Try it online!



                          Wraps onto a cube with side length 2



                              ; @
                          U O
                          I 0 1 0 + p ? /
                          s q q ; W . (
                          . .
                          . .


                          Watch it run





                          • I010 - Initiates the stack


                          • +p? - Adds the top of stack, pulls the counter from the bottom of stack and tests


                          • /;UO@ - If counter is 0, reflect onto top face, remove TOS, u-turn, output and halt


                          • (sqq;W - If counter is positive, reflect, decrement counter, swap TOS, push top to bottom twice, remove TOS and shift lane back into the main loop.






                          share|improve this answer









                          $endgroup$





















                            1












                            $begingroup$

                            TI-BASIC (TI-84), 34 bytes



                            [[0,1,0][0,0,1][1,1,0]]^(Ans+5:Ans(1,1


                            0-indexed $N$th term of the sequence.



                            Input is in Ans.

                            Output is in Ans and is automatically printed out.



                            I figured that enough time had passed, plus multiple answers had been posted, of which there were many which out-golfed this answer.



                            Example:



                            0
                            0
                            prgmCDGFD
                            1
                            9
                            9
                            prgmCDGFD
                            9
                            16
                            16
                            prgmCDGFD
                            65


                            Explanation:



                            [[0,1,0][0,0,1][1,1,0]]^(Ans+5:Ans(1,1      ;full program (example input: 6)

                            [[0,1,0][0,0,1][1,1,0]] ;generate the following matrix:
                            ; [0 1 0]
                            ; [0 0 1]
                            ; [1 1 0]
                            ^(Ans+5 ;then raise it to the power of: input + 5
                            ; [4 7 5]
                            ; [5 9 7]
                            ; [7 12 9]
                            Ans(1,1 ;get the top-left index and leave it in "Ans"
                            ;implicitly print Ans





                            share|improve this answer









                            $endgroup$





















                              1












                              $begingroup$

                              Pyth, 16 bytes



                              L?<b3!b+y-b2y-b3


                              This defines the function y. Try it here!



                              Here's a more fun solution, though it's 9 bytes longer; bytes could be shaved though.



                              +l{sa.pMf.Am&>d2%d2T./QY!


                              This uses the definition given by David Callan on the OEIS page: "a(n) = number of compositions of n into parts that are odd and >= 3." Try it here! It takes input directly instead of defining a function.






                              share|improve this answer









                              $endgroup$














                                Your Answer





                                StackExchange.ifUsing("editor", function () {
                                return StackExchange.using("mathjaxEditing", function () {
                                StackExchange.MarkdownEditor.creationCallbacks.add(function (editor, postfix) {
                                StackExchange.mathjaxEditing.prepareWmdForMathJax(editor, postfix, [["\$", "\$"]]);
                                });
                                });
                                }, "mathjax-editing");

                                StackExchange.ifUsing("editor", function () {
                                StackExchange.using("externalEditor", function () {
                                StackExchange.using("snippets", function () {
                                StackExchange.snippets.init();
                                });
                                });
                                }, "code-snippets");

                                StackExchange.ready(function() {
                                var channelOptions = {
                                tags: "".split(" "),
                                id: "200"
                                };
                                initTagRenderer("".split(" "), "".split(" "), channelOptions);

                                StackExchange.using("externalEditor", function() {
                                // Have to fire editor after snippets, if snippets enabled
                                if (StackExchange.settings.snippets.snippetsEnabled) {
                                StackExchange.using("snippets", function() {
                                createEditor();
                                });
                                }
                                else {
                                createEditor();
                                }
                                });

                                function createEditor() {
                                StackExchange.prepareEditor({
                                heartbeatType: 'answer',
                                autoActivateHeartbeat: false,
                                convertImagesToLinks: false,
                                noModals: true,
                                showLowRepImageUploadWarning: true,
                                reputationToPostImages: null,
                                bindNavPrevention: true,
                                postfix: "",
                                imageUploader: {
                                brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
                                contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
                                allowUrls: true
                                },
                                onDemand: true,
                                discardSelector: ".discard-answer"
                                ,immediatelyShowMarkdownHelp:true
                                });


                                }
                                });














                                draft saved

                                draft discarded


















                                StackExchange.ready(
                                function () {
                                StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fcodegolf.stackexchange.com%2fquestions%2f182797%2fpatience-young-padovan%23new-answer', 'question_page');
                                }
                                );

                                Post as a guest















                                Required, but never shown

























                                19 Answers
                                19






                                active

                                oldest

                                votes








                                19 Answers
                                19






                                active

                                oldest

                                votes









                                active

                                oldest

                                votes






                                active

                                oldest

                                votes









                                6












                                $begingroup$


                                Haskell, 26 bytes





                                (l!!)
                                l=1:1:1:2:scanl(+)2l


                                Try it online! Outputs the n'th term zero-indexed.



                                I thought that the "obvious" recursive solution below would be unbeatable, but then I found this. It's similar to the classic golfy expression l=1:scanl(+)1l for the infinite Fibonacci list, but here the difference between adjacent elements is the term 4 positions back. We can more directly write l=1:1:zipWith(+)l(0:l), but that's longer.



                                If this challenge allowed infinite list output, we could cut the first line and have 20 bytes.



                                27 bytes





                                f n|n<3=1|1>0=f(n-2)+f(n-3)


                                Try it online!






                                share|improve this answer









                                $endgroup$


















                                  6












                                  $begingroup$


                                  Haskell, 26 bytes





                                  (l!!)
                                  l=1:1:1:2:scanl(+)2l


                                  Try it online! Outputs the n'th term zero-indexed.



                                  I thought that the "obvious" recursive solution below would be unbeatable, but then I found this. It's similar to the classic golfy expression l=1:scanl(+)1l for the infinite Fibonacci list, but here the difference between adjacent elements is the term 4 positions back. We can more directly write l=1:1:zipWith(+)l(0:l), but that's longer.



                                  If this challenge allowed infinite list output, we could cut the first line and have 20 bytes.



                                  27 bytes





                                  f n|n<3=1|1>0=f(n-2)+f(n-3)


                                  Try it online!






                                  share|improve this answer









                                  $endgroup$
















                                    6












                                    6








                                    6





                                    $begingroup$


                                    Haskell, 26 bytes





                                    (l!!)
                                    l=1:1:1:2:scanl(+)2l


                                    Try it online! Outputs the n'th term zero-indexed.



                                    I thought that the "obvious" recursive solution below would be unbeatable, but then I found this. It's similar to the classic golfy expression l=1:scanl(+)1l for the infinite Fibonacci list, but here the difference between adjacent elements is the term 4 positions back. We can more directly write l=1:1:zipWith(+)l(0:l), but that's longer.



                                    If this challenge allowed infinite list output, we could cut the first line and have 20 bytes.



                                    27 bytes





                                    f n|n<3=1|1>0=f(n-2)+f(n-3)


                                    Try it online!






                                    share|improve this answer









                                    $endgroup$




                                    Haskell, 26 bytes





                                    (l!!)
                                    l=1:1:1:2:scanl(+)2l


                                    Try it online! Outputs the n'th term zero-indexed.



                                    I thought that the "obvious" recursive solution below would be unbeatable, but then I found this. It's similar to the classic golfy expression l=1:scanl(+)1l for the infinite Fibonacci list, but here the difference between adjacent elements is the term 4 positions back. We can more directly write l=1:1:zipWith(+)l(0:l), but that's longer.



                                    If this challenge allowed infinite list output, we could cut the first line and have 20 bytes.



                                    27 bytes





                                    f n|n<3=1|1>0=f(n-2)+f(n-3)


                                    Try it online!







                                    share|improve this answer












                                    share|improve this answer



                                    share|improve this answer










                                    answered 4 hours ago









                                    xnorxnor

                                    93.4k18190448




                                    93.4k18190448























                                        5












                                        $begingroup$


                                        Oasis, 5 bytes



                                        nth term 0-indexed



                                        cd+1V


                                        Try it online!



                                        Explanation



                                           1V   # a(0) = 1
                                        # a(1) = 1
                                        # a(2) = 1
                                        # a(n) =
                                        c # a(n-2)
                                        + # +
                                        d # a(n-3)





                                        share|improve this answer









                                        $endgroup$


















                                          5












                                          $begingroup$


                                          Oasis, 5 bytes



                                          nth term 0-indexed



                                          cd+1V


                                          Try it online!



                                          Explanation



                                             1V   # a(0) = 1
                                          # a(1) = 1
                                          # a(2) = 1
                                          # a(n) =
                                          c # a(n-2)
                                          + # +
                                          d # a(n-3)





                                          share|improve this answer









                                          $endgroup$
















                                            5












                                            5








                                            5





                                            $begingroup$


                                            Oasis, 5 bytes



                                            nth term 0-indexed



                                            cd+1V


                                            Try it online!



                                            Explanation



                                               1V   # a(0) = 1
                                            # a(1) = 1
                                            # a(2) = 1
                                            # a(n) =
                                            c # a(n-2)
                                            + # +
                                            d # a(n-3)





                                            share|improve this answer









                                            $endgroup$




                                            Oasis, 5 bytes



                                            nth term 0-indexed



                                            cd+1V


                                            Try it online!



                                            Explanation



                                               1V   # a(0) = 1
                                            # a(1) = 1
                                            # a(2) = 1
                                            # a(n) =
                                            c # a(n-2)
                                            + # +
                                            d # a(n-3)






                                            share|improve this answer












                                            share|improve this answer



                                            share|improve this answer










                                            answered 5 hours ago









                                            EmignaEmigna

                                            47.4k433144




                                            47.4k433144























                                                5












                                                $begingroup$


                                                Python 2, 30 bytes





                                                f=lambda n:n<3or f(n-2)+f(n-3)


                                                Try it online!



                                                Returns the n'th term zero indexed. Outputs True for 1.






                                                share|improve this answer











                                                $endgroup$


















                                                  5












                                                  $begingroup$


                                                  Python 2, 30 bytes





                                                  f=lambda n:n<3or f(n-2)+f(n-3)


                                                  Try it online!



                                                  Returns the n'th term zero indexed. Outputs True for 1.






                                                  share|improve this answer











                                                  $endgroup$
















                                                    5












                                                    5








                                                    5





                                                    $begingroup$


                                                    Python 2, 30 bytes





                                                    f=lambda n:n<3or f(n-2)+f(n-3)


                                                    Try it online!



                                                    Returns the n'th term zero indexed. Outputs True for 1.






                                                    share|improve this answer











                                                    $endgroup$




                                                    Python 2, 30 bytes





                                                    f=lambda n:n<3or f(n-2)+f(n-3)


                                                    Try it online!



                                                    Returns the n'th term zero indexed. Outputs True for 1.







                                                    share|improve this answer














                                                    share|improve this answer



                                                    share|improve this answer








                                                    edited 5 hours ago

























                                                    answered 5 hours ago









                                                    xnorxnor

                                                    93.4k18190448




                                                    93.4k18190448























                                                        3












                                                        $begingroup$


                                                        Wolfram Language (Mathematica), 33 bytes



                                                        a@0=a@1=a@2=1;a@n_:=a[n-2]+a[n-3]   


                                                        1-indexed, returns the nth term



                                                        Try it online!






                                                        share|improve this answer









                                                        $endgroup$


















                                                          3












                                                          $begingroup$


                                                          Wolfram Language (Mathematica), 33 bytes



                                                          a@0=a@1=a@2=1;a@n_:=a[n-2]+a[n-3]   


                                                          1-indexed, returns the nth term



                                                          Try it online!






                                                          share|improve this answer









                                                          $endgroup$
















                                                            3












                                                            3








                                                            3





                                                            $begingroup$


                                                            Wolfram Language (Mathematica), 33 bytes



                                                            a@0=a@1=a@2=1;a@n_:=a[n-2]+a[n-3]   


                                                            1-indexed, returns the nth term



                                                            Try it online!






                                                            share|improve this answer









                                                            $endgroup$




                                                            Wolfram Language (Mathematica), 33 bytes



                                                            a@0=a@1=a@2=1;a@n_:=a[n-2]+a[n-3]   


                                                            1-indexed, returns the nth term



                                                            Try it online!







                                                            share|improve this answer












                                                            share|improve this answer



                                                            share|improve this answer










                                                            answered 5 hours ago









                                                            J42161217J42161217

                                                            13.8k21253




                                                            13.8k21253























                                                                3












                                                                $begingroup$


                                                                Jelly, 11 bytes



                                                                5B+Ɲ2ị;Ʋ⁸¡Ḣ


                                                                Try it online!



                                                                0-indexed.






                                                                share|improve this answer











                                                                $endgroup$













                                                                • $begingroup$
                                                                  Can you specify whether this answer is 0-indexed or 1-indexed?
                                                                  $endgroup$
                                                                  – Tau
                                                                  5 hours ago










                                                                • $begingroup$
                                                                  @Tau It's 0-indexed. I've edited it in.
                                                                  $endgroup$
                                                                  – Erik the Outgolfer
                                                                  5 hours ago


















                                                                3












                                                                $begingroup$


                                                                Jelly, 11 bytes



                                                                5B+Ɲ2ị;Ʋ⁸¡Ḣ


                                                                Try it online!



                                                                0-indexed.






                                                                share|improve this answer











                                                                $endgroup$













                                                                • $begingroup$
                                                                  Can you specify whether this answer is 0-indexed or 1-indexed?
                                                                  $endgroup$
                                                                  – Tau
                                                                  5 hours ago










                                                                • $begingroup$
                                                                  @Tau It's 0-indexed. I've edited it in.
                                                                  $endgroup$
                                                                  – Erik the Outgolfer
                                                                  5 hours ago
















                                                                3












                                                                3








                                                                3





                                                                $begingroup$


                                                                Jelly, 11 bytes



                                                                5B+Ɲ2ị;Ʋ⁸¡Ḣ


                                                                Try it online!



                                                                0-indexed.






                                                                share|improve this answer











                                                                $endgroup$




                                                                Jelly, 11 bytes



                                                                5B+Ɲ2ị;Ʋ⁸¡Ḣ


                                                                Try it online!



                                                                0-indexed.







                                                                share|improve this answer














                                                                share|improve this answer



                                                                share|improve this answer








                                                                edited 5 hours ago

























                                                                answered 5 hours ago









                                                                Erik the OutgolferErik the Outgolfer

                                                                33k429106




                                                                33k429106












                                                                • $begingroup$
                                                                  Can you specify whether this answer is 0-indexed or 1-indexed?
                                                                  $endgroup$
                                                                  – Tau
                                                                  5 hours ago










                                                                • $begingroup$
                                                                  @Tau It's 0-indexed. I've edited it in.
                                                                  $endgroup$
                                                                  – Erik the Outgolfer
                                                                  5 hours ago




















                                                                • $begingroup$
                                                                  Can you specify whether this answer is 0-indexed or 1-indexed?
                                                                  $endgroup$
                                                                  – Tau
                                                                  5 hours ago










                                                                • $begingroup$
                                                                  @Tau It's 0-indexed. I've edited it in.
                                                                  $endgroup$
                                                                  – Erik the Outgolfer
                                                                  5 hours ago


















                                                                $begingroup$
                                                                Can you specify whether this answer is 0-indexed or 1-indexed?
                                                                $endgroup$
                                                                – Tau
                                                                5 hours ago




                                                                $begingroup$
                                                                Can you specify whether this answer is 0-indexed or 1-indexed?
                                                                $endgroup$
                                                                – Tau
                                                                5 hours ago












                                                                $begingroup$
                                                                @Tau It's 0-indexed. I've edited it in.
                                                                $endgroup$
                                                                – Erik the Outgolfer
                                                                5 hours ago






                                                                $begingroup$
                                                                @Tau It's 0-indexed. I've edited it in.
                                                                $endgroup$
                                                                – Erik the Outgolfer
                                                                5 hours ago













                                                                3












                                                                $begingroup$


                                                                Jelly, 10 bytes



                                                                ‘HRcḤạ¥¥‘S


                                                                A monadic Link accepting n (1-indexed) which yields P(n).



                                                                Try it online!



                                                                How?



                                                                Implements $P(n) = sum_{i=1}^{lfloorfrac{n+1}2rfloor}binom{2i}{n+1-2i}$



                                                                ‘HRcḤạ¥¥‘S - Link: integer, n       e.g. 21
                                                                ‘ - increment n 22
                                                                H - halve 11
                                                                R - range [1, 2, 3, 4, 5, 6, 7, 8, 9,10,11]
                                                                - (note: floors input, e.g. n=6 -> ‘=7 -> H=3.5 -> R=[1,2,3] )
                                                                ‘ - increment n 21
                                                                ¥ - last two links as a dyad:
                                                                ¥ - last two links as a dyad:
                                                                Ḥ - double [ 2, 4, 6, 8,10,12,14,16,18,20,22]
                                                                ạ - absolute difference [20,18,16,14,12,10, 8, 6, 4, 2, 0]
                                                                c - left-choose-right [ 0, 0, 0, 0, 0, 0, 0,28,126,45,1]
                                                                S - sum 200





                                                                share|improve this answer











                                                                $endgroup$


















                                                                  3












                                                                  $begingroup$


                                                                  Jelly, 10 bytes



                                                                  ‘HRcḤạ¥¥‘S


                                                                  A monadic Link accepting n (1-indexed) which yields P(n).



                                                                  Try it online!



                                                                  How?



                                                                  Implements $P(n) = sum_{i=1}^{lfloorfrac{n+1}2rfloor}binom{2i}{n+1-2i}$



                                                                  ‘HRcḤạ¥¥‘S - Link: integer, n       e.g. 21
                                                                  ‘ - increment n 22
                                                                  H - halve 11
                                                                  R - range [1, 2, 3, 4, 5, 6, 7, 8, 9,10,11]
                                                                  - (note: floors input, e.g. n=6 -> ‘=7 -> H=3.5 -> R=[1,2,3] )
                                                                  ‘ - increment n 21
                                                                  ¥ - last two links as a dyad:
                                                                  ¥ - last two links as a dyad:
                                                                  Ḥ - double [ 2, 4, 6, 8,10,12,14,16,18,20,22]
                                                                  ạ - absolute difference [20,18,16,14,12,10, 8, 6, 4, 2, 0]
                                                                  c - left-choose-right [ 0, 0, 0, 0, 0, 0, 0,28,126,45,1]
                                                                  S - sum 200





                                                                  share|improve this answer











                                                                  $endgroup$
















                                                                    3












                                                                    3








                                                                    3





                                                                    $begingroup$


                                                                    Jelly, 10 bytes



                                                                    ‘HRcḤạ¥¥‘S


                                                                    A monadic Link accepting n (1-indexed) which yields P(n).



                                                                    Try it online!



                                                                    How?



                                                                    Implements $P(n) = sum_{i=1}^{lfloorfrac{n+1}2rfloor}binom{2i}{n+1-2i}$



                                                                    ‘HRcḤạ¥¥‘S - Link: integer, n       e.g. 21
                                                                    ‘ - increment n 22
                                                                    H - halve 11
                                                                    R - range [1, 2, 3, 4, 5, 6, 7, 8, 9,10,11]
                                                                    - (note: floors input, e.g. n=6 -> ‘=7 -> H=3.5 -> R=[1,2,3] )
                                                                    ‘ - increment n 21
                                                                    ¥ - last two links as a dyad:
                                                                    ¥ - last two links as a dyad:
                                                                    Ḥ - double [ 2, 4, 6, 8,10,12,14,16,18,20,22]
                                                                    ạ - absolute difference [20,18,16,14,12,10, 8, 6, 4, 2, 0]
                                                                    c - left-choose-right [ 0, 0, 0, 0, 0, 0, 0,28,126,45,1]
                                                                    S - sum 200





                                                                    share|improve this answer











                                                                    $endgroup$




                                                                    Jelly, 10 bytes



                                                                    ‘HRcḤạ¥¥‘S


                                                                    A monadic Link accepting n (1-indexed) which yields P(n).



                                                                    Try it online!



                                                                    How?



                                                                    Implements $P(n) = sum_{i=1}^{lfloorfrac{n+1}2rfloor}binom{2i}{n+1-2i}$



                                                                    ‘HRcḤạ¥¥‘S - Link: integer, n       e.g. 21
                                                                    ‘ - increment n 22
                                                                    H - halve 11
                                                                    R - range [1, 2, 3, 4, 5, 6, 7, 8, 9,10,11]
                                                                    - (note: floors input, e.g. n=6 -> ‘=7 -> H=3.5 -> R=[1,2,3] )
                                                                    ‘ - increment n 21
                                                                    ¥ - last two links as a dyad:
                                                                    ¥ - last two links as a dyad:
                                                                    Ḥ - double [ 2, 4, 6, 8,10,12,14,16,18,20,22]
                                                                    ạ - absolute difference [20,18,16,14,12,10, 8, 6, 4, 2, 0]
                                                                    c - left-choose-right [ 0, 0, 0, 0, 0, 0, 0,28,126,45,1]
                                                                    S - sum 200






                                                                    share|improve this answer














                                                                    share|improve this answer



                                                                    share|improve this answer








                                                                    edited 2 hours ago

























                                                                    answered 5 hours ago









                                                                    Jonathan AllanJonathan Allan

                                                                    53.8k535173




                                                                    53.8k535173























                                                                        3












                                                                        $begingroup$


                                                                        Jelly, 10 bytes



                                                                        9s3’Ẓæ*³FṀ


                                                                        Try it online!



                                                                        1-indexed. Computes the largest element of: $$begin{bmatrix}0&0&1 \ 1&0&1 \ 0&1&0end{bmatrix}^n$$
                                                                        where the binary matrix is conveniently computed as: $$begin{bmatrix}mathsf{isprime}(0)&mathsf{isprime}(1)&mathsf{isprime}(2) \ mathsf{isprime}(3)&mathsf{isprime}(4)&mathsf{isprime}(5) \ mathsf{isprime}(6)&mathsf{isprime}(7)&mathsf{isprime}(8)end{bmatrix}$$



                                                                        (this is a total coincidence.)



                                                                        9s3         [[1,2,3],[4,5,6],[7,8,9]]    9 split 3
                                                                        ’ [[0,1,2],[3,4,5],[6,7,8]] decrease
                                                                        Ẓ [[0,0,1],[1,0,1],[0,1,0]] isprime
                                                                        æ*³ [[0,0,1],[1,0,1],[0,1,0]]^n matrix power by input
                                                                        FṀ flatten, maximum





                                                                        share|improve this answer









                                                                        $endgroup$


















                                                                          3












                                                                          $begingroup$


                                                                          Jelly, 10 bytes



                                                                          9s3’Ẓæ*³FṀ


                                                                          Try it online!



                                                                          1-indexed. Computes the largest element of: $$begin{bmatrix}0&0&1 \ 1&0&1 \ 0&1&0end{bmatrix}^n$$
                                                                          where the binary matrix is conveniently computed as: $$begin{bmatrix}mathsf{isprime}(0)&mathsf{isprime}(1)&mathsf{isprime}(2) \ mathsf{isprime}(3)&mathsf{isprime}(4)&mathsf{isprime}(5) \ mathsf{isprime}(6)&mathsf{isprime}(7)&mathsf{isprime}(8)end{bmatrix}$$



                                                                          (this is a total coincidence.)



                                                                          9s3         [[1,2,3],[4,5,6],[7,8,9]]    9 split 3
                                                                          ’ [[0,1,2],[3,4,5],[6,7,8]] decrease
                                                                          Ẓ [[0,0,1],[1,0,1],[0,1,0]] isprime
                                                                          æ*³ [[0,0,1],[1,0,1],[0,1,0]]^n matrix power by input
                                                                          FṀ flatten, maximum





                                                                          share|improve this answer









                                                                          $endgroup$
















                                                                            3












                                                                            3








                                                                            3





                                                                            $begingroup$


                                                                            Jelly, 10 bytes



                                                                            9s3’Ẓæ*³FṀ


                                                                            Try it online!



                                                                            1-indexed. Computes the largest element of: $$begin{bmatrix}0&0&1 \ 1&0&1 \ 0&1&0end{bmatrix}^n$$
                                                                            where the binary matrix is conveniently computed as: $$begin{bmatrix}mathsf{isprime}(0)&mathsf{isprime}(1)&mathsf{isprime}(2) \ mathsf{isprime}(3)&mathsf{isprime}(4)&mathsf{isprime}(5) \ mathsf{isprime}(6)&mathsf{isprime}(7)&mathsf{isprime}(8)end{bmatrix}$$



                                                                            (this is a total coincidence.)



                                                                            9s3         [[1,2,3],[4,5,6],[7,8,9]]    9 split 3
                                                                            ’ [[0,1,2],[3,4,5],[6,7,8]] decrease
                                                                            Ẓ [[0,0,1],[1,0,1],[0,1,0]] isprime
                                                                            æ*³ [[0,0,1],[1,0,1],[0,1,0]]^n matrix power by input
                                                                            FṀ flatten, maximum





                                                                            share|improve this answer









                                                                            $endgroup$




                                                                            Jelly, 10 bytes



                                                                            9s3’Ẓæ*³FṀ


                                                                            Try it online!



                                                                            1-indexed. Computes the largest element of: $$begin{bmatrix}0&0&1 \ 1&0&1 \ 0&1&0end{bmatrix}^n$$
                                                                            where the binary matrix is conveniently computed as: $$begin{bmatrix}mathsf{isprime}(0)&mathsf{isprime}(1)&mathsf{isprime}(2) \ mathsf{isprime}(3)&mathsf{isprime}(4)&mathsf{isprime}(5) \ mathsf{isprime}(6)&mathsf{isprime}(7)&mathsf{isprime}(8)end{bmatrix}$$



                                                                            (this is a total coincidence.)



                                                                            9s3         [[1,2,3],[4,5,6],[7,8,9]]    9 split 3
                                                                            ’ [[0,1,2],[3,4,5],[6,7,8]] decrease
                                                                            Ẓ [[0,0,1],[1,0,1],[0,1,0]] isprime
                                                                            æ*³ [[0,0,1],[1,0,1],[0,1,0]]^n matrix power by input
                                                                            FṀ flatten, maximum






                                                                            share|improve this answer












                                                                            share|improve this answer



                                                                            share|improve this answer










                                                                            answered 2 hours ago









                                                                            LynnLynn

                                                                            50.4k897232




                                                                            50.4k897232























                                                                                2












                                                                                $begingroup$


                                                                                Python 2, 56 48 bytes





                                                                                f=lambda n,a=1,b=1,c=1:n>2and f(n-1,b,c,a+b)or c


                                                                                Try it online!



                                                                                Returns nth value, 0-indexed.






                                                                                share|improve this answer









                                                                                $endgroup$


















                                                                                  2












                                                                                  $begingroup$


                                                                                  Python 2, 56 48 bytes





                                                                                  f=lambda n,a=1,b=1,c=1:n>2and f(n-1,b,c,a+b)or c


                                                                                  Try it online!



                                                                                  Returns nth value, 0-indexed.






                                                                                  share|improve this answer









                                                                                  $endgroup$
















                                                                                    2












                                                                                    2








                                                                                    2





                                                                                    $begingroup$


                                                                                    Python 2, 56 48 bytes





                                                                                    f=lambda n,a=1,b=1,c=1:n>2and f(n-1,b,c,a+b)or c


                                                                                    Try it online!



                                                                                    Returns nth value, 0-indexed.






                                                                                    share|improve this answer









                                                                                    $endgroup$




                                                                                    Python 2, 56 48 bytes





                                                                                    f=lambda n,a=1,b=1,c=1:n>2and f(n-1,b,c,a+b)or c


                                                                                    Try it online!



                                                                                    Returns nth value, 0-indexed.







                                                                                    share|improve this answer












                                                                                    share|improve this answer



                                                                                    share|improve this answer










                                                                                    answered 5 hours ago









                                                                                    Chas BrownChas Brown

                                                                                    5,1991523




                                                                                    5,1991523























                                                                                        2












                                                                                        $begingroup$


                                                                                        Japt -N, 12 bytes



                                                                                        <3ªßUµ2 +ß´U


                                                                                        Try it






                                                                                        share|improve this answer









                                                                                        $endgroup$













                                                                                        • $begingroup$
                                                                                          Looks like 12 is the best we can do :
                                                                                          $endgroup$
                                                                                          – Shaggy
                                                                                          3 hours ago
















                                                                                        2












                                                                                        $begingroup$


                                                                                        Japt -N, 12 bytes



                                                                                        <3ªßUµ2 +ß´U


                                                                                        Try it






                                                                                        share|improve this answer









                                                                                        $endgroup$













                                                                                        • $begingroup$
                                                                                          Looks like 12 is the best we can do :
                                                                                          $endgroup$
                                                                                          – Shaggy
                                                                                          3 hours ago














                                                                                        2












                                                                                        2








                                                                                        2





                                                                                        $begingroup$


                                                                                        Japt -N, 12 bytes



                                                                                        <3ªßUµ2 +ß´U


                                                                                        Try it






                                                                                        share|improve this answer









                                                                                        $endgroup$




                                                                                        Japt -N, 12 bytes



                                                                                        <3ªßUµ2 +ß´U


                                                                                        Try it







                                                                                        share|improve this answer












                                                                                        share|improve this answer



                                                                                        share|improve this answer










                                                                                        answered 4 hours ago









                                                                                        Embodiment of IgnoranceEmbodiment of Ignorance

                                                                                        2,828127




                                                                                        2,828127












                                                                                        • $begingroup$
                                                                                          Looks like 12 is the best we can do :
                                                                                          $endgroup$
                                                                                          – Shaggy
                                                                                          3 hours ago


















                                                                                        • $begingroup$
                                                                                          Looks like 12 is the best we can do :
                                                                                          $endgroup$
                                                                                          – Shaggy
                                                                                          3 hours ago
















                                                                                        $begingroup$
                                                                                        Looks like 12 is the best we can do :
                                                                                        $endgroup$
                                                                                        – Shaggy
                                                                                        3 hours ago




                                                                                        $begingroup$
                                                                                        Looks like 12 is the best we can do :
                                                                                        $endgroup$
                                                                                        – Shaggy
                                                                                        3 hours ago











                                                                                        2












                                                                                        $begingroup$


                                                                                        Retina, 47 42 bytes



                                                                                        K`0¶1¶0
                                                                                        "$+"+`.+¶(.+)¶.+$
                                                                                        $&¶$.(*_$1*
                                                                                        6,G`


                                                                                        Try it online! Outputs the first n terms on separate lines. Explanation:



                                                                                        K`0¶1¶0


                                                                                        Replace the input with the terms for -2, -1 and 0.



                                                                                        "$+"+`.+¶(.+)¶.+$
                                                                                        $&¶$.(*_$1*


                                                                                        Generate the next n terms using the recurrence relation. *_ here is short for $&*_ which converts the (first) number in the match to unary, while $1* is short for $1*_ which converts the middle number to unary. The $.( returns the decimal sum of its unary arguments, i.e. the sum of the first and middle numbers.



                                                                                        6,G`


                                                                                        Discard the first six characters, i.e. the first three lines.






                                                                                        share|improve this answer











                                                                                        $endgroup$


















                                                                                          2












                                                                                          $begingroup$


                                                                                          Retina, 47 42 bytes



                                                                                          K`0¶1¶0
                                                                                          "$+"+`.+¶(.+)¶.+$
                                                                                          $&¶$.(*_$1*
                                                                                          6,G`


                                                                                          Try it online! Outputs the first n terms on separate lines. Explanation:



                                                                                          K`0¶1¶0


                                                                                          Replace the input with the terms for -2, -1 and 0.



                                                                                          "$+"+`.+¶(.+)¶.+$
                                                                                          $&¶$.(*_$1*


                                                                                          Generate the next n terms using the recurrence relation. *_ here is short for $&*_ which converts the (first) number in the match to unary, while $1* is short for $1*_ which converts the middle number to unary. The $.( returns the decimal sum of its unary arguments, i.e. the sum of the first and middle numbers.



                                                                                          6,G`


                                                                                          Discard the first six characters, i.e. the first three lines.






                                                                                          share|improve this answer











                                                                                          $endgroup$
















                                                                                            2












                                                                                            2








                                                                                            2





                                                                                            $begingroup$


                                                                                            Retina, 47 42 bytes



                                                                                            K`0¶1¶0
                                                                                            "$+"+`.+¶(.+)¶.+$
                                                                                            $&¶$.(*_$1*
                                                                                            6,G`


                                                                                            Try it online! Outputs the first n terms on separate lines. Explanation:



                                                                                            K`0¶1¶0


                                                                                            Replace the input with the terms for -2, -1 and 0.



                                                                                            "$+"+`.+¶(.+)¶.+$
                                                                                            $&¶$.(*_$1*


                                                                                            Generate the next n terms using the recurrence relation. *_ here is short for $&*_ which converts the (first) number in the match to unary, while $1* is short for $1*_ which converts the middle number to unary. The $.( returns the decimal sum of its unary arguments, i.e. the sum of the first and middle numbers.



                                                                                            6,G`


                                                                                            Discard the first six characters, i.e. the first three lines.






                                                                                            share|improve this answer











                                                                                            $endgroup$




                                                                                            Retina, 47 42 bytes



                                                                                            K`0¶1¶0
                                                                                            "$+"+`.+¶(.+)¶.+$
                                                                                            $&¶$.(*_$1*
                                                                                            6,G`


                                                                                            Try it online! Outputs the first n terms on separate lines. Explanation:



                                                                                            K`0¶1¶0


                                                                                            Replace the input with the terms for -2, -1 and 0.



                                                                                            "$+"+`.+¶(.+)¶.+$
                                                                                            $&¶$.(*_$1*


                                                                                            Generate the next n terms using the recurrence relation. *_ here is short for $&*_ which converts the (first) number in the match to unary, while $1* is short for $1*_ which converts the middle number to unary. The $.( returns the decimal sum of its unary arguments, i.e. the sum of the first and middle numbers.



                                                                                            6,G`


                                                                                            Discard the first six characters, i.e. the first three lines.







                                                                                            share|improve this answer














                                                                                            share|improve this answer



                                                                                            share|improve this answer








                                                                                            edited 4 hours ago

























                                                                                            answered 4 hours ago









                                                                                            NeilNeil

                                                                                            82.6k745179




                                                                                            82.6k745179























                                                                                                2












                                                                                                $begingroup$


                                                                                                Perl 6, 24 bytes



                                                                                                {(1,1,1,*+*+!*...*)[$_]}


                                                                                                Try it online!



                                                                                                A pretty standard generated sequence, with each new element generated by the expression * + * + !*. That adds the third-previous element, the second-previous element, and the logical negation of the previous element, which is always False, which is numerically zero.






                                                                                                share|improve this answer











                                                                                                $endgroup$













                                                                                                • $begingroup$
                                                                                                  Why is this community wiki?
                                                                                                  $endgroup$
                                                                                                  – Jo King
                                                                                                  2 hours ago
















                                                                                                2












                                                                                                $begingroup$


                                                                                                Perl 6, 24 bytes



                                                                                                {(1,1,1,*+*+!*...*)[$_]}


                                                                                                Try it online!



                                                                                                A pretty standard generated sequence, with each new element generated by the expression * + * + !*. That adds the third-previous element, the second-previous element, and the logical negation of the previous element, which is always False, which is numerically zero.






                                                                                                share|improve this answer











                                                                                                $endgroup$













                                                                                                • $begingroup$
                                                                                                  Why is this community wiki?
                                                                                                  $endgroup$
                                                                                                  – Jo King
                                                                                                  2 hours ago














                                                                                                2












                                                                                                2








                                                                                                2





                                                                                                $begingroup$


                                                                                                Perl 6, 24 bytes



                                                                                                {(1,1,1,*+*+!*...*)[$_]}


                                                                                                Try it online!



                                                                                                A pretty standard generated sequence, with each new element generated by the expression * + * + !*. That adds the third-previous element, the second-previous element, and the logical negation of the previous element, which is always False, which is numerically zero.






                                                                                                share|improve this answer











                                                                                                $endgroup$




                                                                                                Perl 6, 24 bytes



                                                                                                {(1,1,1,*+*+!*...*)[$_]}


                                                                                                Try it online!



                                                                                                A pretty standard generated sequence, with each new element generated by the expression * + * + !*. That adds the third-previous element, the second-previous element, and the logical negation of the previous element, which is always False, which is numerically zero.







                                                                                                share|improve this answer














                                                                                                share|improve this answer



                                                                                                share|improve this answer








                                                                                                answered 3 hours ago


























                                                                                                community wiki





                                                                                                Sean













                                                                                                • $begingroup$
                                                                                                  Why is this community wiki?
                                                                                                  $endgroup$
                                                                                                  – Jo King
                                                                                                  2 hours ago


















                                                                                                • $begingroup$
                                                                                                  Why is this community wiki?
                                                                                                  $endgroup$
                                                                                                  – Jo King
                                                                                                  2 hours ago
















                                                                                                $begingroup$
                                                                                                Why is this community wiki?
                                                                                                $endgroup$
                                                                                                – Jo King
                                                                                                2 hours ago




                                                                                                $begingroup$
                                                                                                Why is this community wiki?
                                                                                                $endgroup$
                                                                                                – Jo King
                                                                                                2 hours ago











                                                                                                2












                                                                                                $begingroup$


                                                                                                J, 24 bytes



                                                                                                closed form, 26 bytes



                                                                                                0.5<.@+1.04535%~1.32472^<:


                                                                                                Try it online!



                                                                                                iterative, 24 bytes



                                                                                                (],1#._2 _3{ ::1:])^:[1:


                                                                                                Try it online!






                                                                                                share|improve this answer











                                                                                                $endgroup$


















                                                                                                  2












                                                                                                  $begingroup$


                                                                                                  J, 24 bytes



                                                                                                  closed form, 26 bytes



                                                                                                  0.5<.@+1.04535%~1.32472^<:


                                                                                                  Try it online!



                                                                                                  iterative, 24 bytes



                                                                                                  (],1#._2 _3{ ::1:])^:[1:


                                                                                                  Try it online!






                                                                                                  share|improve this answer











                                                                                                  $endgroup$
















                                                                                                    2












                                                                                                    2








                                                                                                    2





                                                                                                    $begingroup$


                                                                                                    J, 24 bytes



                                                                                                    closed form, 26 bytes



                                                                                                    0.5<.@+1.04535%~1.32472^<:


                                                                                                    Try it online!



                                                                                                    iterative, 24 bytes



                                                                                                    (],1#._2 _3{ ::1:])^:[1:


                                                                                                    Try it online!






                                                                                                    share|improve this answer











                                                                                                    $endgroup$




                                                                                                    J, 24 bytes



                                                                                                    closed form, 26 bytes



                                                                                                    0.5<.@+1.04535%~1.32472^<:


                                                                                                    Try it online!



                                                                                                    iterative, 24 bytes



                                                                                                    (],1#._2 _3{ ::1:])^:[1:


                                                                                                    Try it online!







                                                                                                    share|improve this answer














                                                                                                    share|improve this answer



                                                                                                    share|improve this answer








                                                                                                    edited 2 hours ago

























                                                                                                    answered 5 hours ago









                                                                                                    JonahJonah

                                                                                                    2,5911017




                                                                                                    2,5911017























                                                                                                        1












                                                                                                        $begingroup$


                                                                                                        C# (Visual C# Interactive Compiler), 34 bytes





                                                                                                        int f(int g)=>g<3?1:f(g-2)+f(g-3);


                                                                                                        Try it online!






                                                                                                        share|improve this answer









                                                                                                        $endgroup$


















                                                                                                          1












                                                                                                          $begingroup$


                                                                                                          C# (Visual C# Interactive Compiler), 34 bytes





                                                                                                          int f(int g)=>g<3?1:f(g-2)+f(g-3);


                                                                                                          Try it online!






                                                                                                          share|improve this answer









                                                                                                          $endgroup$
















                                                                                                            1












                                                                                                            1








                                                                                                            1





                                                                                                            $begingroup$


                                                                                                            C# (Visual C# Interactive Compiler), 34 bytes





                                                                                                            int f(int g)=>g<3?1:f(g-2)+f(g-3);


                                                                                                            Try it online!






                                                                                                            share|improve this answer









                                                                                                            $endgroup$




                                                                                                            C# (Visual C# Interactive Compiler), 34 bytes





                                                                                                            int f(int g)=>g<3?1:f(g-2)+f(g-3);


                                                                                                            Try it online!







                                                                                                            share|improve this answer












                                                                                                            share|improve this answer



                                                                                                            share|improve this answer










                                                                                                            answered 4 hours ago









                                                                                                            Embodiment of IgnoranceEmbodiment of Ignorance

                                                                                                            2,828127




                                                                                                            2,828127























                                                                                                                1












                                                                                                                $begingroup$

                                                                                                                JavaScript (ES6), 23 bytes



                                                                                                                Implements the recursive definition of A000931. Returns the $N$th term, 0-indexed.





                                                                                                                f=n=>n<3||f(n-2)+f(n-3)


                                                                                                                Try it online!






                                                                                                                share|improve this answer











                                                                                                                $endgroup$


















                                                                                                                  1












                                                                                                                  $begingroup$

                                                                                                                  JavaScript (ES6), 23 bytes



                                                                                                                  Implements the recursive definition of A000931. Returns the $N$th term, 0-indexed.





                                                                                                                  f=n=>n<3||f(n-2)+f(n-3)


                                                                                                                  Try it online!






                                                                                                                  share|improve this answer











                                                                                                                  $endgroup$
















                                                                                                                    1












                                                                                                                    1








                                                                                                                    1





                                                                                                                    $begingroup$

                                                                                                                    JavaScript (ES6), 23 bytes



                                                                                                                    Implements the recursive definition of A000931. Returns the $N$th term, 0-indexed.





                                                                                                                    f=n=>n<3||f(n-2)+f(n-3)


                                                                                                                    Try it online!






                                                                                                                    share|improve this answer











                                                                                                                    $endgroup$



                                                                                                                    JavaScript (ES6), 23 bytes



                                                                                                                    Implements the recursive definition of A000931. Returns the $N$th term, 0-indexed.





                                                                                                                    f=n=>n<3||f(n-2)+f(n-3)


                                                                                                                    Try it online!







                                                                                                                    share|improve this answer














                                                                                                                    share|improve this answer



                                                                                                                    share|improve this answer








                                                                                                                    edited 4 hours ago

























                                                                                                                    answered 4 hours ago









                                                                                                                    ArnauldArnauld

                                                                                                                    80.5k797333




                                                                                                                    80.5k797333























                                                                                                                        1












                                                                                                                        $begingroup$


                                                                                                                        Japt, 12 bytes



                                                                                                                        Returns the first n terms, 0-indexed. Replace h with g to return the nth term, 1-indexed.



                                                                                                                        ÈnZs3n)x}hBì


                                                                                                                        Try it



                                                                                                                        (Explanation to follow when my exhaustion wears off!)






                                                                                                                        share|improve this answer











                                                                                                                        $endgroup$


















                                                                                                                          1












                                                                                                                          $begingroup$


                                                                                                                          Japt, 12 bytes



                                                                                                                          Returns the first n terms, 0-indexed. Replace h with g to return the nth term, 1-indexed.



                                                                                                                          ÈnZs3n)x}hBì


                                                                                                                          Try it



                                                                                                                          (Explanation to follow when my exhaustion wears off!)






                                                                                                                          share|improve this answer











                                                                                                                          $endgroup$
















                                                                                                                            1












                                                                                                                            1








                                                                                                                            1





                                                                                                                            $begingroup$


                                                                                                                            Japt, 12 bytes



                                                                                                                            Returns the first n terms, 0-indexed. Replace h with g to return the nth term, 1-indexed.



                                                                                                                            ÈnZs3n)x}hBì


                                                                                                                            Try it



                                                                                                                            (Explanation to follow when my exhaustion wears off!)






                                                                                                                            share|improve this answer











                                                                                                                            $endgroup$




                                                                                                                            Japt, 12 bytes



                                                                                                                            Returns the first n terms, 0-indexed. Replace h with g to return the nth term, 1-indexed.



                                                                                                                            ÈnZs3n)x}hBì


                                                                                                                            Try it



                                                                                                                            (Explanation to follow when my exhaustion wears off!)







                                                                                                                            share|improve this answer














                                                                                                                            share|improve this answer



                                                                                                                            share|improve this answer








                                                                                                                            edited 3 hours ago

























                                                                                                                            answered 3 hours ago









                                                                                                                            ShaggyShaggy

                                                                                                                            18.9k21768




                                                                                                                            18.9k21768























                                                                                                                                1












                                                                                                                                $begingroup$


                                                                                                                                Lua 5.3, 49 bytes





                                                                                                                                function f(n)return n<=3 and 1or f(n-2)+f(n-3)end


                                                                                                                                Try it online!



                                                                                                                                Vanilla Lua doesn't have coercion of booleans to strings (even tonumber(true) returns nil), so you have to use a pseudo-ternary operator. This version is 1-indexed, like all of Lua. The 1or part has to be changed to 1 or in Lua 5.1, which has a different way of lexing numbers.






                                                                                                                                share|improve this answer











                                                                                                                                $endgroup$













                                                                                                                                • $begingroup$
                                                                                                                                  <=3 can be <4
                                                                                                                                  $endgroup$
                                                                                                                                  – Jo King
                                                                                                                                  2 hours ago
















                                                                                                                                1












                                                                                                                                $begingroup$


                                                                                                                                Lua 5.3, 49 bytes





                                                                                                                                function f(n)return n<=3 and 1or f(n-2)+f(n-3)end


                                                                                                                                Try it online!



                                                                                                                                Vanilla Lua doesn't have coercion of booleans to strings (even tonumber(true) returns nil), so you have to use a pseudo-ternary operator. This version is 1-indexed, like all of Lua. The 1or part has to be changed to 1 or in Lua 5.1, which has a different way of lexing numbers.






                                                                                                                                share|improve this answer











                                                                                                                                $endgroup$













                                                                                                                                • $begingroup$
                                                                                                                                  <=3 can be <4
                                                                                                                                  $endgroup$
                                                                                                                                  – Jo King
                                                                                                                                  2 hours ago














                                                                                                                                1












                                                                                                                                1








                                                                                                                                1





                                                                                                                                $begingroup$


                                                                                                                                Lua 5.3, 49 bytes





                                                                                                                                function f(n)return n<=3 and 1or f(n-2)+f(n-3)end


                                                                                                                                Try it online!



                                                                                                                                Vanilla Lua doesn't have coercion of booleans to strings (even tonumber(true) returns nil), so you have to use a pseudo-ternary operator. This version is 1-indexed, like all of Lua. The 1or part has to be changed to 1 or in Lua 5.1, which has a different way of lexing numbers.






                                                                                                                                share|improve this answer











                                                                                                                                $endgroup$




                                                                                                                                Lua 5.3, 49 bytes





                                                                                                                                function f(n)return n<=3 and 1or f(n-2)+f(n-3)end


                                                                                                                                Try it online!



                                                                                                                                Vanilla Lua doesn't have coercion of booleans to strings (even tonumber(true) returns nil), so you have to use a pseudo-ternary operator. This version is 1-indexed, like all of Lua. The 1or part has to be changed to 1 or in Lua 5.1, which has a different way of lexing numbers.







                                                                                                                                share|improve this answer














                                                                                                                                share|improve this answer



                                                                                                                                share|improve this answer








                                                                                                                                edited 3 hours ago

























                                                                                                                                answered 3 hours ago









                                                                                                                                cyclaministcyclaminist

                                                                                                                                1613




                                                                                                                                1613












                                                                                                                                • $begingroup$
                                                                                                                                  <=3 can be <4
                                                                                                                                  $endgroup$
                                                                                                                                  – Jo King
                                                                                                                                  2 hours ago


















                                                                                                                                • $begingroup$
                                                                                                                                  <=3 can be <4
                                                                                                                                  $endgroup$
                                                                                                                                  – Jo King
                                                                                                                                  2 hours ago
















                                                                                                                                $begingroup$
                                                                                                                                <=3 can be <4
                                                                                                                                $endgroup$
                                                                                                                                – Jo King
                                                                                                                                2 hours ago




                                                                                                                                $begingroup$
                                                                                                                                <=3 can be <4
                                                                                                                                $endgroup$
                                                                                                                                – Jo King
                                                                                                                                2 hours ago











                                                                                                                                1












                                                                                                                                $begingroup$


                                                                                                                                Cubix, 20 bytes



                                                                                                                                This is 0 indexed and outputs the Nth term



                                                                                                                                ;@UOI010+p?/sqq;W.(


                                                                                                                                Try it online!



                                                                                                                                Wraps onto a cube with side length 2



                                                                                                                                    ; @
                                                                                                                                U O
                                                                                                                                I 0 1 0 + p ? /
                                                                                                                                s q q ; W . (
                                                                                                                                . .
                                                                                                                                . .


                                                                                                                                Watch it run





                                                                                                                                • I010 - Initiates the stack


                                                                                                                                • +p? - Adds the top of stack, pulls the counter from the bottom of stack and tests


                                                                                                                                • /;UO@ - If counter is 0, reflect onto top face, remove TOS, u-turn, output and halt


                                                                                                                                • (sqq;W - If counter is positive, reflect, decrement counter, swap TOS, push top to bottom twice, remove TOS and shift lane back into the main loop.






                                                                                                                                share|improve this answer









                                                                                                                                $endgroup$


















                                                                                                                                  1












                                                                                                                                  $begingroup$


                                                                                                                                  Cubix, 20 bytes



                                                                                                                                  This is 0 indexed and outputs the Nth term



                                                                                                                                  ;@UOI010+p?/sqq;W.(


                                                                                                                                  Try it online!



                                                                                                                                  Wraps onto a cube with side length 2



                                                                                                                                      ; @
                                                                                                                                  U O
                                                                                                                                  I 0 1 0 + p ? /
                                                                                                                                  s q q ; W . (
                                                                                                                                  . .
                                                                                                                                  . .


                                                                                                                                  Watch it run





                                                                                                                                  • I010 - Initiates the stack


                                                                                                                                  • +p? - Adds the top of stack, pulls the counter from the bottom of stack and tests


                                                                                                                                  • /;UO@ - If counter is 0, reflect onto top face, remove TOS, u-turn, output and halt


                                                                                                                                  • (sqq;W - If counter is positive, reflect, decrement counter, swap TOS, push top to bottom twice, remove TOS and shift lane back into the main loop.






                                                                                                                                  share|improve this answer









                                                                                                                                  $endgroup$
















                                                                                                                                    1












                                                                                                                                    1








                                                                                                                                    1





                                                                                                                                    $begingroup$


                                                                                                                                    Cubix, 20 bytes



                                                                                                                                    This is 0 indexed and outputs the Nth term



                                                                                                                                    ;@UOI010+p?/sqq;W.(


                                                                                                                                    Try it online!



                                                                                                                                    Wraps onto a cube with side length 2



                                                                                                                                        ; @
                                                                                                                                    U O
                                                                                                                                    I 0 1 0 + p ? /
                                                                                                                                    s q q ; W . (
                                                                                                                                    . .
                                                                                                                                    . .


                                                                                                                                    Watch it run





                                                                                                                                    • I010 - Initiates the stack


                                                                                                                                    • +p? - Adds the top of stack, pulls the counter from the bottom of stack and tests


                                                                                                                                    • /;UO@ - If counter is 0, reflect onto top face, remove TOS, u-turn, output and halt


                                                                                                                                    • (sqq;W - If counter is positive, reflect, decrement counter, swap TOS, push top to bottom twice, remove TOS and shift lane back into the main loop.






                                                                                                                                    share|improve this answer









                                                                                                                                    $endgroup$




                                                                                                                                    Cubix, 20 bytes



                                                                                                                                    This is 0 indexed and outputs the Nth term



                                                                                                                                    ;@UOI010+p?/sqq;W.(


                                                                                                                                    Try it online!



                                                                                                                                    Wraps onto a cube with side length 2



                                                                                                                                        ; @
                                                                                                                                    U O
                                                                                                                                    I 0 1 0 + p ? /
                                                                                                                                    s q q ; W . (
                                                                                                                                    . .
                                                                                                                                    . .


                                                                                                                                    Watch it run





                                                                                                                                    • I010 - Initiates the stack


                                                                                                                                    • +p? - Adds the top of stack, pulls the counter from the bottom of stack and tests


                                                                                                                                    • /;UO@ - If counter is 0, reflect onto top face, remove TOS, u-turn, output and halt


                                                                                                                                    • (sqq;W - If counter is positive, reflect, decrement counter, swap TOS, push top to bottom twice, remove TOS and shift lane back into the main loop.







                                                                                                                                    share|improve this answer












                                                                                                                                    share|improve this answer



                                                                                                                                    share|improve this answer










                                                                                                                                    answered 3 hours ago









                                                                                                                                    MickyTMickyT

                                                                                                                                    10.3k21637




                                                                                                                                    10.3k21637























                                                                                                                                        1












                                                                                                                                        $begingroup$

                                                                                                                                        TI-BASIC (TI-84), 34 bytes



                                                                                                                                        [[0,1,0][0,0,1][1,1,0]]^(Ans+5:Ans(1,1


                                                                                                                                        0-indexed $N$th term of the sequence.



                                                                                                                                        Input is in Ans.

                                                                                                                                        Output is in Ans and is automatically printed out.



                                                                                                                                        I figured that enough time had passed, plus multiple answers had been posted, of which there were many which out-golfed this answer.



                                                                                                                                        Example:



                                                                                                                                        0
                                                                                                                                        0
                                                                                                                                        prgmCDGFD
                                                                                                                                        1
                                                                                                                                        9
                                                                                                                                        9
                                                                                                                                        prgmCDGFD
                                                                                                                                        9
                                                                                                                                        16
                                                                                                                                        16
                                                                                                                                        prgmCDGFD
                                                                                                                                        65


                                                                                                                                        Explanation:



                                                                                                                                        [[0,1,0][0,0,1][1,1,0]]^(Ans+5:Ans(1,1      ;full program (example input: 6)

                                                                                                                                        [[0,1,0][0,0,1][1,1,0]] ;generate the following matrix:
                                                                                                                                        ; [0 1 0]
                                                                                                                                        ; [0 0 1]
                                                                                                                                        ; [1 1 0]
                                                                                                                                        ^(Ans+5 ;then raise it to the power of: input + 5
                                                                                                                                        ; [4 7 5]
                                                                                                                                        ; [5 9 7]
                                                                                                                                        ; [7 12 9]
                                                                                                                                        Ans(1,1 ;get the top-left index and leave it in "Ans"
                                                                                                                                        ;implicitly print Ans





                                                                                                                                        share|improve this answer









                                                                                                                                        $endgroup$


















                                                                                                                                          1












                                                                                                                                          $begingroup$

                                                                                                                                          TI-BASIC (TI-84), 34 bytes



                                                                                                                                          [[0,1,0][0,0,1][1,1,0]]^(Ans+5:Ans(1,1


                                                                                                                                          0-indexed $N$th term of the sequence.



                                                                                                                                          Input is in Ans.

                                                                                                                                          Output is in Ans and is automatically printed out.



                                                                                                                                          I figured that enough time had passed, plus multiple answers had been posted, of which there were many which out-golfed this answer.



                                                                                                                                          Example:



                                                                                                                                          0
                                                                                                                                          0
                                                                                                                                          prgmCDGFD
                                                                                                                                          1
                                                                                                                                          9
                                                                                                                                          9
                                                                                                                                          prgmCDGFD
                                                                                                                                          9
                                                                                                                                          16
                                                                                                                                          16
                                                                                                                                          prgmCDGFD
                                                                                                                                          65


                                                                                                                                          Explanation:



                                                                                                                                          [[0,1,0][0,0,1][1,1,0]]^(Ans+5:Ans(1,1      ;full program (example input: 6)

                                                                                                                                          [[0,1,0][0,0,1][1,1,0]] ;generate the following matrix:
                                                                                                                                          ; [0 1 0]
                                                                                                                                          ; [0 0 1]
                                                                                                                                          ; [1 1 0]
                                                                                                                                          ^(Ans+5 ;then raise it to the power of: input + 5
                                                                                                                                          ; [4 7 5]
                                                                                                                                          ; [5 9 7]
                                                                                                                                          ; [7 12 9]
                                                                                                                                          Ans(1,1 ;get the top-left index and leave it in "Ans"
                                                                                                                                          ;implicitly print Ans





                                                                                                                                          share|improve this answer









                                                                                                                                          $endgroup$
















                                                                                                                                            1












                                                                                                                                            1








                                                                                                                                            1





                                                                                                                                            $begingroup$

                                                                                                                                            TI-BASIC (TI-84), 34 bytes



                                                                                                                                            [[0,1,0][0,0,1][1,1,0]]^(Ans+5:Ans(1,1


                                                                                                                                            0-indexed $N$th term of the sequence.



                                                                                                                                            Input is in Ans.

                                                                                                                                            Output is in Ans and is automatically printed out.



                                                                                                                                            I figured that enough time had passed, plus multiple answers had been posted, of which there were many which out-golfed this answer.



                                                                                                                                            Example:



                                                                                                                                            0
                                                                                                                                            0
                                                                                                                                            prgmCDGFD
                                                                                                                                            1
                                                                                                                                            9
                                                                                                                                            9
                                                                                                                                            prgmCDGFD
                                                                                                                                            9
                                                                                                                                            16
                                                                                                                                            16
                                                                                                                                            prgmCDGFD
                                                                                                                                            65


                                                                                                                                            Explanation:



                                                                                                                                            [[0,1,0][0,0,1][1,1,0]]^(Ans+5:Ans(1,1      ;full program (example input: 6)

                                                                                                                                            [[0,1,0][0,0,1][1,1,0]] ;generate the following matrix:
                                                                                                                                            ; [0 1 0]
                                                                                                                                            ; [0 0 1]
                                                                                                                                            ; [1 1 0]
                                                                                                                                            ^(Ans+5 ;then raise it to the power of: input + 5
                                                                                                                                            ; [4 7 5]
                                                                                                                                            ; [5 9 7]
                                                                                                                                            ; [7 12 9]
                                                                                                                                            Ans(1,1 ;get the top-left index and leave it in "Ans"
                                                                                                                                            ;implicitly print Ans





                                                                                                                                            share|improve this answer









                                                                                                                                            $endgroup$



                                                                                                                                            TI-BASIC (TI-84), 34 bytes



                                                                                                                                            [[0,1,0][0,0,1][1,1,0]]^(Ans+5:Ans(1,1


                                                                                                                                            0-indexed $N$th term of the sequence.



                                                                                                                                            Input is in Ans.

                                                                                                                                            Output is in Ans and is automatically printed out.



                                                                                                                                            I figured that enough time had passed, plus multiple answers had been posted, of which there were many which out-golfed this answer.



                                                                                                                                            Example:



                                                                                                                                            0
                                                                                                                                            0
                                                                                                                                            prgmCDGFD
                                                                                                                                            1
                                                                                                                                            9
                                                                                                                                            9
                                                                                                                                            prgmCDGFD
                                                                                                                                            9
                                                                                                                                            16
                                                                                                                                            16
                                                                                                                                            prgmCDGFD
                                                                                                                                            65


                                                                                                                                            Explanation:



                                                                                                                                            [[0,1,0][0,0,1][1,1,0]]^(Ans+5:Ans(1,1      ;full program (example input: 6)

                                                                                                                                            [[0,1,0][0,0,1][1,1,0]] ;generate the following matrix:
                                                                                                                                            ; [0 1 0]
                                                                                                                                            ; [0 0 1]
                                                                                                                                            ; [1 1 0]
                                                                                                                                            ^(Ans+5 ;then raise it to the power of: input + 5
                                                                                                                                            ; [4 7 5]
                                                                                                                                            ; [5 9 7]
                                                                                                                                            ; [7 12 9]
                                                                                                                                            Ans(1,1 ;get the top-left index and leave it in "Ans"
                                                                                                                                            ;implicitly print Ans






                                                                                                                                            share|improve this answer












                                                                                                                                            share|improve this answer



                                                                                                                                            share|improve this answer










                                                                                                                                            answered 3 hours ago









                                                                                                                                            TauTau

                                                                                                                                            801313




                                                                                                                                            801313























                                                                                                                                                1












                                                                                                                                                $begingroup$

                                                                                                                                                Pyth, 16 bytes



                                                                                                                                                L?<b3!b+y-b2y-b3


                                                                                                                                                This defines the function y. Try it here!



                                                                                                                                                Here's a more fun solution, though it's 9 bytes longer; bytes could be shaved though.



                                                                                                                                                +l{sa.pMf.Am&>d2%d2T./QY!


                                                                                                                                                This uses the definition given by David Callan on the OEIS page: "a(n) = number of compositions of n into parts that are odd and >= 3." Try it here! It takes input directly instead of defining a function.






                                                                                                                                                share|improve this answer









                                                                                                                                                $endgroup$


















                                                                                                                                                  1












                                                                                                                                                  $begingroup$

                                                                                                                                                  Pyth, 16 bytes



                                                                                                                                                  L?<b3!b+y-b2y-b3


                                                                                                                                                  This defines the function y. Try it here!



                                                                                                                                                  Here's a more fun solution, though it's 9 bytes longer; bytes could be shaved though.



                                                                                                                                                  +l{sa.pMf.Am&>d2%d2T./QY!


                                                                                                                                                  This uses the definition given by David Callan on the OEIS page: "a(n) = number of compositions of n into parts that are odd and >= 3." Try it here! It takes input directly instead of defining a function.






                                                                                                                                                  share|improve this answer









                                                                                                                                                  $endgroup$
















                                                                                                                                                    1












                                                                                                                                                    1








                                                                                                                                                    1





                                                                                                                                                    $begingroup$

                                                                                                                                                    Pyth, 16 bytes



                                                                                                                                                    L?<b3!b+y-b2y-b3


                                                                                                                                                    This defines the function y. Try it here!



                                                                                                                                                    Here's a more fun solution, though it's 9 bytes longer; bytes could be shaved though.



                                                                                                                                                    +l{sa.pMf.Am&>d2%d2T./QY!


                                                                                                                                                    This uses the definition given by David Callan on the OEIS page: "a(n) = number of compositions of n into parts that are odd and >= 3." Try it here! It takes input directly instead of defining a function.






                                                                                                                                                    share|improve this answer









                                                                                                                                                    $endgroup$



                                                                                                                                                    Pyth, 16 bytes



                                                                                                                                                    L?<b3!b+y-b2y-b3


                                                                                                                                                    This defines the function y. Try it here!



                                                                                                                                                    Here's a more fun solution, though it's 9 bytes longer; bytes could be shaved though.



                                                                                                                                                    +l{sa.pMf.Am&>d2%d2T./QY!


                                                                                                                                                    This uses the definition given by David Callan on the OEIS page: "a(n) = number of compositions of n into parts that are odd and >= 3." Try it here! It takes input directly instead of defining a function.







                                                                                                                                                    share|improve this answer












                                                                                                                                                    share|improve this answer



                                                                                                                                                    share|improve this answer










                                                                                                                                                    answered 1 hour ago









                                                                                                                                                    RK.RK.

                                                                                                                                                    397111




                                                                                                                                                    397111






























                                                                                                                                                        draft saved

                                                                                                                                                        draft discarded




















































                                                                                                                                                        If this is an answer to a challenge…




                                                                                                                                                        • …Be sure to follow the challenge specification. However, please refrain from exploiting obvious loopholes. Answers abusing any of the standard loopholes are considered invalid. If you think a specification is unclear or underspecified, comment on the question instead.


                                                                                                                                                        • …Try to optimize your score. For instance, answers to code-golf challenges should attempt to be as short as possible. You can always include a readable version of the code in addition to the competitive one.
                                                                                                                                                          Explanations of your answer make it more interesting to read and are very much encouraged.


                                                                                                                                                        • …Include a short header which indicates the language(s) of your code and its score, as defined by the challenge.



                                                                                                                                                        More generally…




                                                                                                                                                        • …Please make sure to answer the question and provide sufficient detail.


                                                                                                                                                        • …Avoid asking for help, clarification or responding to other answers (use comments instead).





                                                                                                                                                        draft saved


                                                                                                                                                        draft discarded














                                                                                                                                                        StackExchange.ready(
                                                                                                                                                        function () {
                                                                                                                                                        StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fcodegolf.stackexchange.com%2fquestions%2f182797%2fpatience-young-padovan%23new-answer', 'question_page');
                                                                                                                                                        }
                                                                                                                                                        );

                                                                                                                                                        Post as a guest















                                                                                                                                                        Required, but never shown





















































                                                                                                                                                        Required, but never shown














                                                                                                                                                        Required, but never shown












                                                                                                                                                        Required, but never shown







                                                                                                                                                        Required, but never shown

































                                                                                                                                                        Required, but never shown














                                                                                                                                                        Required, but never shown












                                                                                                                                                        Required, but never shown







                                                                                                                                                        Required, but never shown







                                                                                                                                                        Popular posts from this blog

                                                                                                                                                        Aikido

                                                                                                                                                        Tivadar Csontváry Kosztka

                                                                                                                                                        Metroo de Marsejlo