Patience, young “Padovan”Fibonacci function or sequenceGenerate a Padovan SpiralGenerate an ASCII Padovan SpiralGolf a Custom Fibonacci SequenceDivinacci SequenceGenerate unseen numbersImplement the Fibonacci sequence… Shifted to the rightDizzy integer enumerationModulus SummationTerms of the EKG sequence

How to deal with fear of taking dependencies

Why did the Germans forbid the possession of pet pigeons in Rostov-on-Don in 1941?

extract characters between two commas?

Is domain driven design an anti-SQL pattern?

Was there ever an axiom rendered a theorem?

What is GPS' 19 year rollover and does it present a cybersecurity issue?

What causes the sudden spool-up sound from an F-16 when enabling afterburner?

A poker game description that does not feel gimmicky

Is ipsum/ipsa/ipse a third person pronoun, or can it serve other functions?

Hosting Wordpress in a EC2 Load Balanced Instance

What is the meaning of "of trouble" in the following sentence?

Where to refill my bottle in India?

Is there a familial term for apples and pears?

Does a dangling wire really electrocute me if I'm standing in water?

Add an angle to a sphere

Why was the "bread communication" in the arena of Catching Fire left out in the movie?

What do the Banks children have against barley water?

Are cabin dividers used to "hide" the flex of the airplane?

Can the Produce Flame cantrip be used to grapple, or as an unarmed strike, in the right circumstances?

If a centaur druid Wild Shapes into a Giant Elk, do their Charge features stack?

Piano - What is the notation for a double stop where both notes in the double stop are different lengths?

Does bootstrapped regression allow for inference?

Check if two datetimes are between two others

Calculate Levenshtein distance between two strings in Python



Patience, young “Padovan”


Fibonacci function or sequenceGenerate a Padovan SpiralGenerate an ASCII Padovan SpiralGolf a Custom Fibonacci SequenceDivinacci SequenceGenerate unseen numbersImplement the Fibonacci sequence… Shifted to the rightDizzy integer enumerationModulus SummationTerms of the EKG sequence













26












$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


(1-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$







  • 2




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










  • $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
    yesterday










  • $begingroup$
    @LuisMendo I believe so. I'll edit the post.
    $endgroup$
    – Tau
    13 hours ago










  • $begingroup$
    Not to detract from the question, but is this the actual definition of the Fibonacci sequence? I was taught it as a sequence of numbers, in which the first two numbers are 1, and the 3rd and subsequent numbers are the sum of the prior two numbers. Then again, I was taught this as an example of a problem to solve with recursion...
    $endgroup$
    – sharur
    3 hours ago










  • $begingroup$
    @sharur this definition for the Fibonacci sequence is the visual definition. Each successive square added has a length of that term in the sequence. The sequence you describe is the numerical reasoning behind it. Both sequences work just as well as the other.
    $endgroup$
    – Tau
    26 mins ago















26












$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


(1-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$







  • 2




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










  • $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
    yesterday










  • $begingroup$
    @LuisMendo I believe so. I'll edit the post.
    $endgroup$
    – Tau
    13 hours ago










  • $begingroup$
    Not to detract from the question, but is this the actual definition of the Fibonacci sequence? I was taught it as a sequence of numbers, in which the first two numbers are 1, and the 3rd and subsequent numbers are the sum of the prior two numbers. Then again, I was taught this as an example of a problem to solve with recursion...
    $endgroup$
    – sharur
    3 hours ago










  • $begingroup$
    @sharur this definition for the Fibonacci sequence is the visual definition. Each successive square added has a length of that term in the sequence. The sequence you describe is the numerical reasoning behind it. Both sequences work just as well as the other.
    $endgroup$
    – Tau
    26 mins ago













26












26








26


2



$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


(1-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


(1-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 13 hours ago







Tau

















asked yesterday









TauTau

911515




911515







  • 2




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










  • $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
    yesterday










  • $begingroup$
    @LuisMendo I believe so. I'll edit the post.
    $endgroup$
    – Tau
    13 hours ago










  • $begingroup$
    Not to detract from the question, but is this the actual definition of the Fibonacci sequence? I was taught it as a sequence of numbers, in which the first two numbers are 1, and the 3rd and subsequent numbers are the sum of the prior two numbers. Then again, I was taught this as an example of a problem to solve with recursion...
    $endgroup$
    – sharur
    3 hours ago










  • $begingroup$
    @sharur this definition for the Fibonacci sequence is the visual definition. Each successive square added has a length of that term in the sequence. The sequence you describe is the numerical reasoning behind it. Both sequences work just as well as the other.
    $endgroup$
    – Tau
    26 mins ago












  • 2




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










  • $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
    yesterday










  • $begingroup$
    @LuisMendo I believe so. I'll edit the post.
    $endgroup$
    – Tau
    13 hours ago










  • $begingroup$
    Not to detract from the question, but is this the actual definition of the Fibonacci sequence? I was taught it as a sequence of numbers, in which the first two numbers are 1, and the 3rd and subsequent numbers are the sum of the prior two numbers. Then again, I was taught this as an example of a problem to solve with recursion...
    $endgroup$
    – sharur
    3 hours ago










  • $begingroup$
    @sharur this definition for the Fibonacci sequence is the visual definition. Each successive square added has a length of that term in the sequence. The sequence you describe is the numerical reasoning behind it. Both sequences work just as well as the other.
    $endgroup$
    – Tau
    26 mins ago







2




2




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




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












$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
yesterday




$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
yesterday












$begingroup$
@LuisMendo I believe so. I'll edit the post.
$endgroup$
– Tau
13 hours ago




$begingroup$
@LuisMendo I believe so. I'll edit the post.
$endgroup$
– Tau
13 hours ago












$begingroup$
Not to detract from the question, but is this the actual definition of the Fibonacci sequence? I was taught it as a sequence of numbers, in which the first two numbers are 1, and the 3rd and subsequent numbers are the sum of the prior two numbers. Then again, I was taught this as an example of a problem to solve with recursion...
$endgroup$
– sharur
3 hours ago




$begingroup$
Not to detract from the question, but is this the actual definition of the Fibonacci sequence? I was taught it as a sequence of numbers, in which the first two numbers are 1, and the 3rd and subsequent numbers are the sum of the prior two numbers. Then again, I was taught this as an example of a problem to solve with recursion...
$endgroup$
– sharur
3 hours ago












$begingroup$
@sharur this definition for the Fibonacci sequence is the visual definition. Each successive square added has a length of that term in the sequence. The sequence you describe is the numerical reasoning behind it. Both sequences work just as well as the other.
$endgroup$
– Tau
26 mins ago




$begingroup$
@sharur this definition for the Fibonacci sequence is the visual definition. Each successive square added has a length of that term in the sequence. The sequence you describe is the numerical reasoning behind it. Both sequences work just as well as the other.
$endgroup$
– Tau
26 mins ago










30 Answers
30






active

oldest

votes


















35












$begingroup$


Jelly, 10 bytes



9s3’Ẓæ*³FṀ


Try it online!



1-indexed. Computes the largest element of: $$beginbmatrix0&0&1 \ 1&0&1 \ 0&1&0endbmatrix^n$$
where the binary matrix is conveniently computed as: $$beginbmatrixmathsfisprime(0)&mathsfisprime(1)&mathsfisprime(2) \ mathsfisprime(3)&mathsfisprime(4)&mathsfisprime(5) \ mathsfisprime(6)&mathsfisprime(7)&mathsfisprime(8)endbmatrix$$



(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$








  • 17




    $begingroup$
    this is clearly some kind of voodoo
    $endgroup$
    – Pureferret
    15 hours ago






  • 6




    $begingroup$
    This should be published.
    $endgroup$
    – YSC
    15 hours ago






  • 2




    $begingroup$
    @YSC It has already been published in A000931. I'd never have guess the primes trick:)
    $endgroup$
    – flawr
    11 hours ago










  • $begingroup$
    @flawr ho... I missed it
    $endgroup$
    – YSC
    10 hours ago






  • 1




    $begingroup$
    ...make that "unless someone can golf two bytes off this one" :) (now that I have a 9 byter)
    $endgroup$
    – Jonathan Allan
    9 hours ago



















18












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




















    16












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




















      14












      $begingroup$


      Jelly,  10 9  8 bytes



      ŻṚm2Jc$S


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



      Try it online!



      How?



      Implements $P(n) = sum_i=0^lfloorfracn2rfloorbinomi+1n-2i$



      ŻṚm2Jc$S - Link: integer, n e.g. 20
      Ż - zero range [0, 1, 2, 3, 4, ..., 19, 20]
      Ṛ - reverse [20, 19, ..., 4, 3, 2, 1, 0]
      m2 - modulo-slice with 2 [20, 18, 16, 14, 12, 10, 8, 6, 4, 2, 0] <- n-2i
      $ - last two links as a monad:
      J - range of length [ 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11] <- i+1
      c - left-choose-right [ 0, 0, 0, 0, 0, 0, 0, 28,126, 45, 1]
      S - sum 200



      And here is a "twofer"

      ...a totally different method also for 8 bytes (this one is 1-indexed, but much slower):



      3ḊṗRẎ§ċ‘ - Link: n
      3Ḋ - 3 dequeued = [2,3]
      R - range = [1,2,3,...,n]
      ṗ - Cartesian power [[[2],[3]],[[2,2],[2,3],[3,2],[3,3]],[[2,2,2],...],...]
      Ẏ - tighten [[2],[3],[2,2],[2,3],[3,2],[3,3],[2,2,2],...]
      § - sums [ 2, 3, 4, 5, 5, 6, 6,...]
      ‘ - increment n+1
      ċ - count occurrences P(n)





      share|improve this answer











      $endgroup$




















        6












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


          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$




















            5












            $begingroup$


            J, 23 bytes



            -1 byte thanks to ngn and Galen



            closed form, 26 bytes



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


            Try it online!



            iterative, 23 bytes



            (],1#._2 _3 














            3












            $begingroup$


            Lua 5.3, 49 48 bytes





            function f(n)return n<4 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.






            sharehBì :Implicit input of integer U
            B :11
            ì :Convert to digit array
            h :Repeat the following until the length of the array is U, pushing the result to the array each time
            È : Take the last element X from the array Z and pass it through the following function
            n : Subtract X from
            Zs : Slice Z
            3n : -3, giving the last 3 elements in the array
            ) : End slice
            x : Reduce by addition
            } : End function





            share|improve this answer











            $endgroup$




















              1












              $begingroup$


              Perl 5, 34 bytes





              sub f"@_"<3


              Try it online!






              share|improve this answer









              $endgroup$




















                1












                $begingroup$


                C++ (gcc), 81 75 bytes



                -6 bytes to small golfing





                int a(int n)int a=1,b=1,c=1,d,i=2;for(;i++<n;)d=a+b,a=b,b=c,c=d;return c;


                Try it online!



                Simple function to compute the values iteratively. No loop occurs for n<3, so the first cases default to the initial 1.






                share|improve this answer











                $endgroup$




















                  1












                  $begingroup$

                  Java, 41 bytes



                  Can't use a lambda (runtime error). Port of this Javascript answer



                  int f(int n)return n<3?1:f(n-2)+f(n-3);


                  TIO






                  share|improve this answer









                  $endgroup$




















                    1












                    $begingroup$

                    x86 32-bit machine code, 17 bytes



                    53 33 db f7 e3 43 83 c1 04 03 d8 93 92 e2 fa 5b c3


                    Disassembly:



                    00CE1250 53 push ebx 
                    00CE1251 33 DB xor ebx,ebx
                    00CE1253 F7 E3 mul eax,ebx
                    00CE1255 43 inc ebx
                    00CE1256 83 C1 04 add ecx,4
                    00CE1259 03 D8 add ebx,eax
                    00CE125B 93 xchg eax,ebx
                    00CE125C 92 xchg eax,edx
                    00CE125D E2 FA loop myloop (0CE1259h)
                    00CE125F 5B pop ebx
                    00CE1260 C3 ret


                    It is 0-indexed. The initialization is conveniently achieved by calculating eax * 0. The 128-bit result is 0, and it goes in edx:eax.



                    At the beginning of each iteration, the order of the registers is ebx, eax, edx. I had to choose the right order to take advantage of the encoding for the xchg eax instruction - 1 byte.



                    I had to add 4 to the loop counter in order to let the output reach eax, which holds the function's return value in the fastcall convention.



                    I could use some other calling convention, which doesn't require saving and restoring ebx, but fastcall is fun anyway :)






                    share|improve this answer









                    $endgroup$












                    • $begingroup$
                      I love to see machine code answers on PP&CG! +1
                      $endgroup$
                      – Tau
                      24 mins ago


















                    0












                    $begingroup$


                    Gaia, 16 14 bytes



                    7b@((⟨ṇ;(++⟩ₓ)


                    Try it online!



                    7b		| push [1 1 1]
                    @(( | push input, decrement twice
                    ⟨ ⟩ₓ | do the following that many times (0 times if 0 or less)
                    ṇ | pop the first element and leave the rest below
                    ; | copy from below
                    ( | take the first element
                    + | add the two together
                    + | and concatenate to the list. End loop.
                    ) | finally, take the last element





                    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

























                      30 Answers
                      30






                      active

                      oldest

                      votes








                      30 Answers
                      30






                      active

                      oldest

                      votes









                      active

                      oldest

                      votes






                      active

                      oldest

                      votes









                      35












                      $begingroup$


                      Jelly, 10 bytes



                      9s3’Ẓæ*³FṀ


                      Try it online!



                      1-indexed. Computes the largest element of: $$beginbmatrix0&0&1 \ 1&0&1 \ 0&1&0endbmatrix^n$$
                      where the binary matrix is conveniently computed as: $$beginbmatrixmathsfisprime(0)&mathsfisprime(1)&mathsfisprime(2) \ mathsfisprime(3)&mathsfisprime(4)&mathsfisprime(5) \ mathsfisprime(6)&mathsfisprime(7)&mathsfisprime(8)endbmatrix$$



                      (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$








                      • 17




                        $begingroup$
                        this is clearly some kind of voodoo
                        $endgroup$
                        – Pureferret
                        15 hours ago






                      • 6




                        $begingroup$
                        This should be published.
                        $endgroup$
                        – YSC
                        15 hours ago






                      • 2




                        $begingroup$
                        @YSC It has already been published in A000931. I'd never have guess the primes trick:)
                        $endgroup$
                        – flawr
                        11 hours ago










                      • $begingroup$
                        @flawr ho... I missed it
                        $endgroup$
                        – YSC
                        10 hours ago






                      • 1




                        $begingroup$
                        ...make that "unless someone can golf two bytes off this one" :) (now that I have a 9 byter)
                        $endgroup$
                        – Jonathan Allan
                        9 hours ago
















                      35












                      $begingroup$


                      Jelly, 10 bytes



                      9s3’Ẓæ*³FṀ


                      Try it online!



                      1-indexed. Computes the largest element of: $$beginbmatrix0&0&1 \ 1&0&1 \ 0&1&0endbmatrix^n$$
                      where the binary matrix is conveniently computed as: $$beginbmatrixmathsfisprime(0)&mathsfisprime(1)&mathsfisprime(2) \ mathsfisprime(3)&mathsfisprime(4)&mathsfisprime(5) \ mathsfisprime(6)&mathsfisprime(7)&mathsfisprime(8)endbmatrix$$



                      (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$








                      • 17




                        $begingroup$
                        this is clearly some kind of voodoo
                        $endgroup$
                        – Pureferret
                        15 hours ago






                      • 6




                        $begingroup$
                        This should be published.
                        $endgroup$
                        – YSC
                        15 hours ago






                      • 2




                        $begingroup$
                        @YSC It has already been published in A000931. I'd never have guess the primes trick:)
                        $endgroup$
                        – flawr
                        11 hours ago










                      • $begingroup$
                        @flawr ho... I missed it
                        $endgroup$
                        – YSC
                        10 hours ago






                      • 1




                        $begingroup$
                        ...make that "unless someone can golf two bytes off this one" :) (now that I have a 9 byter)
                        $endgroup$
                        – Jonathan Allan
                        9 hours ago














                      35












                      35








                      35





                      $begingroup$


                      Jelly, 10 bytes



                      9s3’Ẓæ*³FṀ


                      Try it online!



                      1-indexed. Computes the largest element of: $$beginbmatrix0&0&1 \ 1&0&1 \ 0&1&0endbmatrix^n$$
                      where the binary matrix is conveniently computed as: $$beginbmatrixmathsfisprime(0)&mathsfisprime(1)&mathsfisprime(2) \ mathsfisprime(3)&mathsfisprime(4)&mathsfisprime(5) \ mathsfisprime(6)&mathsfisprime(7)&mathsfisprime(8)endbmatrix$$



                      (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: $$beginbmatrix0&0&1 \ 1&0&1 \ 0&1&0endbmatrix^n$$
                      where the binary matrix is conveniently computed as: $$beginbmatrixmathsfisprime(0)&mathsfisprime(1)&mathsfisprime(2) \ mathsfisprime(3)&mathsfisprime(4)&mathsfisprime(5) \ mathsfisprime(6)&mathsfisprime(7)&mathsfisprime(8)endbmatrix$$



                      (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 yesterday









                      LynnLynn

                      50.5k898233




                      50.5k898233







                      • 17




                        $begingroup$
                        this is clearly some kind of voodoo
                        $endgroup$
                        – Pureferret
                        15 hours ago






                      • 6




                        $begingroup$
                        This should be published.
                        $endgroup$
                        – YSC
                        15 hours ago






                      • 2




                        $begingroup$
                        @YSC It has already been published in A000931. I'd never have guess the primes trick:)
                        $endgroup$
                        – flawr
                        11 hours ago










                      • $begingroup$
                        @flawr ho... I missed it
                        $endgroup$
                        – YSC
                        10 hours ago






                      • 1




                        $begingroup$
                        ...make that "unless someone can golf two bytes off this one" :) (now that I have a 9 byter)
                        $endgroup$
                        – Jonathan Allan
                        9 hours ago













                      • 17




                        $begingroup$
                        this is clearly some kind of voodoo
                        $endgroup$
                        – Pureferret
                        15 hours ago






                      • 6




                        $begingroup$
                        This should be published.
                        $endgroup$
                        – YSC
                        15 hours ago






                      • 2




                        $begingroup$
                        @YSC It has already been published in A000931. I'd never have guess the primes trick:)
                        $endgroup$
                        – flawr
                        11 hours ago










                      • $begingroup$
                        @flawr ho... I missed it
                        $endgroup$
                        – YSC
                        10 hours ago






                      • 1




                        $begingroup$
                        ...make that "unless someone can golf two bytes off this one" :) (now that I have a 9 byter)
                        $endgroup$
                        – Jonathan Allan
                        9 hours ago








                      17




                      17




                      $begingroup$
                      this is clearly some kind of voodoo
                      $endgroup$
                      – Pureferret
                      15 hours ago




                      $begingroup$
                      this is clearly some kind of voodoo
                      $endgroup$
                      – Pureferret
                      15 hours ago




                      6




                      6




                      $begingroup$
                      This should be published.
                      $endgroup$
                      – YSC
                      15 hours ago




                      $begingroup$
                      This should be published.
                      $endgroup$
                      – YSC
                      15 hours ago




                      2




                      2




                      $begingroup$
                      @YSC It has already been published in A000931. I'd never have guess the primes trick:)
                      $endgroup$
                      – flawr
                      11 hours ago




                      $begingroup$
                      @YSC It has already been published in A000931. I'd never have guess the primes trick:)
                      $endgroup$
                      – flawr
                      11 hours ago












                      $begingroup$
                      @flawr ho... I missed it
                      $endgroup$
                      – YSC
                      10 hours ago




                      $begingroup$
                      @flawr ho... I missed it
                      $endgroup$
                      – YSC
                      10 hours ago




                      1




                      1




                      $begingroup$
                      ...make that "unless someone can golf two bytes off this one" :) (now that I have a 9 byter)
                      $endgroup$
                      – Jonathan Allan
                      9 hours ago





                      $begingroup$
                      ...make that "unless someone can golf two bytes off this one" :) (now that I have a 9 byter)
                      $endgroup$
                      – Jonathan Allan
                      9 hours ago












                      18












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

















                        18












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















                          18












                          18








                          18





                          $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 yesterday









                          EmignaEmigna

                          47.6k433145




                          47.6k433145





















                              16












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

















                                16












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















                                  16












                                  16








                                  16





                                  $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 yesterday









                                  xnorxnor

                                  93.6k18190450




                                  93.6k18190450





















                                      14












                                      $begingroup$


                                      Jelly,  10 9  8 bytes



                                      ŻṚm2Jc$S


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



                                      Try it online!



                                      How?



                                      Implements $P(n) = sum_i=0^lfloorfracn2rfloorbinomi+1n-2i$



                                      ŻṚm2Jc$S - Link: integer, n e.g. 20
                                      Ż - zero range [0, 1, 2, 3, 4, ..., 19, 20]
                                      Ṛ - reverse [20, 19, ..., 4, 3, 2, 1, 0]
                                      m2 - modulo-slice with 2 [20, 18, 16, 14, 12, 10, 8, 6, 4, 2, 0] <- n-2i
                                      $ - last two links as a monad:
                                      J - range of length [ 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11] <- i+1
                                      c - left-choose-right [ 0, 0, 0, 0, 0, 0, 0, 28,126, 45, 1]
                                      S - sum 200



                                      And here is a "twofer"

                                      ...a totally different method also for 8 bytes (this one is 1-indexed, but much slower):



                                      3ḊṗRẎ§ċ‘ - Link: n
                                      3Ḋ - 3 dequeued = [2,3]
                                      R - range = [1,2,3,...,n]
                                      ṗ - Cartesian power [[[2],[3]],[[2,2],[2,3],[3,2],[3,3]],[[2,2,2],...],...]
                                      Ẏ - tighten [[2],[3],[2,2],[2,3],[3,2],[3,3],[2,2,2],...]
                                      § - sums [ 2, 3, 4, 5, 5, 6, 6,...]
                                      ‘ - increment n+1
                                      ċ - count occurrences P(n)





                                      share|improve this answer











                                      $endgroup$

















                                        14












                                        $begingroup$


                                        Jelly,  10 9  8 bytes



                                        ŻṚm2Jc$S


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



                                        Try it online!



                                        How?



                                        Implements $P(n) = sum_i=0^lfloorfracn2rfloorbinomi+1n-2i$



                                        ŻṚm2Jc$S - Link: integer, n e.g. 20
                                        Ż - zero range [0, 1, 2, 3, 4, ..., 19, 20]
                                        Ṛ - reverse [20, 19, ..., 4, 3, 2, 1, 0]
                                        m2 - modulo-slice with 2 [20, 18, 16, 14, 12, 10, 8, 6, 4, 2, 0] <- n-2i
                                        $ - last two links as a monad:
                                        J - range of length [ 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11] <- i+1
                                        c - left-choose-right [ 0, 0, 0, 0, 0, 0, 0, 28,126, 45, 1]
                                        S - sum 200



                                        And here is a "twofer"

                                        ...a totally different method also for 8 bytes (this one is 1-indexed, but much slower):



                                        3ḊṗRẎ§ċ‘ - Link: n
                                        3Ḋ - 3 dequeued = [2,3]
                                        R - range = [1,2,3,...,n]
                                        ṗ - Cartesian power [[[2],[3]],[[2,2],[2,3],[3,2],[3,3]],[[2,2,2],...],...]
                                        Ẏ - tighten [[2],[3],[2,2],[2,3],[3,2],[3,3],[2,2,2],...]
                                        § - sums [ 2, 3, 4, 5, 5, 6, 6,...]
                                        ‘ - increment n+1
                                        ċ - count occurrences P(n)





                                        share|improve this answer











                                        $endgroup$















                                          14












                                          14








                                          14





                                          $begingroup$


                                          Jelly,  10 9  8 bytes



                                          ŻṚm2Jc$S


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



                                          Try it online!



                                          How?



                                          Implements $P(n) = sum_i=0^lfloorfracn2rfloorbinomi+1n-2i$



                                          ŻṚm2Jc$S - Link: integer, n e.g. 20
                                          Ż - zero range [0, 1, 2, 3, 4, ..., 19, 20]
                                          Ṛ - reverse [20, 19, ..., 4, 3, 2, 1, 0]
                                          m2 - modulo-slice with 2 [20, 18, 16, 14, 12, 10, 8, 6, 4, 2, 0] <- n-2i
                                          $ - last two links as a monad:
                                          J - range of length [ 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11] <- i+1
                                          c - left-choose-right [ 0, 0, 0, 0, 0, 0, 0, 28,126, 45, 1]
                                          S - sum 200



                                          And here is a "twofer"

                                          ...a totally different method also for 8 bytes (this one is 1-indexed, but much slower):



                                          3ḊṗRẎ§ċ‘ - Link: n
                                          3Ḋ - 3 dequeued = [2,3]
                                          R - range = [1,2,3,...,n]
                                          ṗ - Cartesian power [[[2],[3]],[[2,2],[2,3],[3,2],[3,3]],[[2,2,2],...],...]
                                          Ẏ - tighten [[2],[3],[2,2],[2,3],[3,2],[3,3],[2,2,2],...]
                                          § - sums [ 2, 3, 4, 5, 5, 6, 6,...]
                                          ‘ - increment n+1
                                          ċ - count occurrences P(n)





                                          share|improve this answer











                                          $endgroup$




                                          Jelly,  10 9  8 bytes



                                          ŻṚm2Jc$S


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



                                          Try it online!



                                          How?



                                          Implements $P(n) = sum_i=0^lfloorfracn2rfloorbinomi+1n-2i$



                                          ŻṚm2Jc$S - Link: integer, n e.g. 20
                                          Ż - zero range [0, 1, 2, 3, 4, ..., 19, 20]
                                          Ṛ - reverse [20, 19, ..., 4, 3, 2, 1, 0]
                                          m2 - modulo-slice with 2 [20, 18, 16, 14, 12, 10, 8, 6, 4, 2, 0] <- n-2i
                                          $ - last two links as a monad:
                                          J - range of length [ 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11] <- i+1
                                          c - left-choose-right [ 0, 0, 0, 0, 0, 0, 0, 28,126, 45, 1]
                                          S - sum 200



                                          And here is a "twofer"

                                          ...a totally different method also for 8 bytes (this one is 1-indexed, but much slower):



                                          3ḊṗRẎ§ċ‘ - Link: n
                                          3Ḋ - 3 dequeued = [2,3]
                                          R - range = [1,2,3,...,n]
                                          ṗ - Cartesian power [[[2],[3]],[[2,2],[2,3],[3,2],[3,3]],[[2,2,2],...],...]
                                          Ẏ - tighten [[2],[3],[2,2],[2,3],[3,2],[3,3],[2,2,2],...]
                                          § - sums [ 2, 3, 4, 5, 5, 6, 6,...]
                                          ‘ - increment n+1
                                          ċ - count occurrences P(n)






                                          share|improve this answer














                                          share|improve this answer



                                          share|improve this answer








                                          edited 2 hours ago

























                                          answered yesterday









                                          Jonathan AllanJonathan Allan

                                          54k535174




                                          54k535174





















                                              6












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

















                                                6












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















                                                  6












                                                  6








                                                  6





                                                  $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 yesterday

























                                                  answered yesterday









                                                  xnorxnor

                                                  93.6k18190450




                                                  93.6k18190450





















                                                      5












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

















                                                        5












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















                                                          5












                                                          5








                                                          5





                                                          $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 yesterday









                                                          J42161217J42161217

                                                          13.9k21353




                                                          13.9k21353





















                                                              5












                                                              $begingroup$


                                                              J, 23 bytes



                                                              -1 byte thanks to ngn and Galen



                                                              closed form, 26 bytes



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


                                                              Try it online!



                                                              iterative, 23 bytes



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


                                                              Try it online!






                                                              sharehBì :Implicit input of integer U
                                                              B :11
                                                              ì :Convert to digit array
                                                              h :Repeat the following until the length of the array is U, pushing the result to the array each time
                                                              È : Take the last element X from the array Z and pass it through the following function
                                                              n : Subtract X from
                                                              Zs : Slice Z
                                                              3n : -3, giving the last 3 elements in the array
                                                              ) : End slice
                                                              x : Reduce by addition
                                                              } : End function





                                                              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



                                                              ÈnZs3n)x}hBì :Implicit input of integer U
                                                              B :11
                                                              ì :Convert to digit array
                                                              h :Repeat the following until the length of the array is U, pushing the result to the array each time
                                                              È : Take the last element X from the array Z and pass it through the following function
                                                              n : Subtract X from
                                                              Zs : Slice Z
                                                              3n : -3, giving the last 3 elements in the array
                                                              ) : End slice
                                                              x : Reduce by addition
                                                              } : End function






                                                              share|improve this answer














                                                              share|improve this answer



                                                              share|improve this answer








                                                              edited 17 hours ago

























                                                              answered yesterday









                                                              ShaggyShaggy

                                                              18.9k21768




                                                              18.9k21768





















                                                                  1












                                                                  $begingroup$


                                                                  Perl 5, 34 bytes





                                                                  sub f"@_"<3


                                                                  Try it online!






                                                                  share|improve this answer









                                                                  $endgroup$

















                                                                    1












                                                                    $begingroup$


                                                                    Perl 5, 34 bytes





                                                                    sub f"@_"<3


                                                                    Try it online!






                                                                    share|improve this answer









                                                                    $endgroup$















                                                                      1












                                                                      1








                                                                      1





                                                                      $begingroup$


                                                                      Perl 5, 34 bytes





                                                                      sub f"@_"<3


                                                                      Try it online!






                                                                      share|improve this answer









                                                                      $endgroup$




                                                                      Perl 5, 34 bytes





                                                                      sub f"@_"<3


                                                                      Try it online!







                                                                      share|improve this answer












                                                                      share|improve this answer



                                                                      share|improve this answer










                                                                      answered 9 hours ago









                                                                      XcaliXcali

                                                                      5,465520




                                                                      5,465520





















                                                                          1












                                                                          $begingroup$


                                                                          C++ (gcc), 81 75 bytes



                                                                          -6 bytes to small golfing





                                                                          int a(int n)int a=1,b=1,c=1,d,i=2;for(;i++<n;)d=a+b,a=b,b=c,c=d;return c;


                                                                          Try it online!



                                                                          Simple function to compute the values iteratively. No loop occurs for n<3, so the first cases default to the initial 1.






                                                                          share|improve this answer











                                                                          $endgroup$

















                                                                            1












                                                                            $begingroup$


                                                                            C++ (gcc), 81 75 bytes



                                                                            -6 bytes to small golfing





                                                                            int a(int n)int a=1,b=1,c=1,d,i=2;for(;i++<n;)d=a+b,a=b,b=c,c=d;return c;


                                                                            Try it online!



                                                                            Simple function to compute the values iteratively. No loop occurs for n<3, so the first cases default to the initial 1.






                                                                            share|improve this answer











                                                                            $endgroup$















                                                                              1












                                                                              1








                                                                              1





                                                                              $begingroup$


                                                                              C++ (gcc), 81 75 bytes



                                                                              -6 bytes to small golfing





                                                                              int a(int n)int a=1,b=1,c=1,d,i=2;for(;i++<n;)d=a+b,a=b,b=c,c=d;return c;


                                                                              Try it online!



                                                                              Simple function to compute the values iteratively. No loop occurs for n<3, so the first cases default to the initial 1.






                                                                              share|improve this answer











                                                                              $endgroup$




                                                                              C++ (gcc), 81 75 bytes



                                                                              -6 bytes to small golfing





                                                                              int a(int n)int a=1,b=1,c=1,d,i=2;for(;i++<n;)d=a+b,a=b,b=c,c=d;return c;


                                                                              Try it online!



                                                                              Simple function to compute the values iteratively. No loop occurs for n<3, so the first cases default to the initial 1.







                                                                              share|improve this answer














                                                                              share|improve this answer



                                                                              share|improve this answer








                                                                              edited 7 hours ago

























                                                                              answered 7 hours ago









                                                                              Neil A.Neil A.

                                                                              1,348120




                                                                              1,348120





















                                                                                  1












                                                                                  $begingroup$

                                                                                  Java, 41 bytes



                                                                                  Can't use a lambda (runtime error). Port of this Javascript answer



                                                                                  int f(int n)return n<3?1:f(n-2)+f(n-3);


                                                                                  TIO






                                                                                  share|improve this answer









                                                                                  $endgroup$

















                                                                                    1












                                                                                    $begingroup$

                                                                                    Java, 41 bytes



                                                                                    Can't use a lambda (runtime error). Port of this Javascript answer



                                                                                    int f(int n)return n<3?1:f(n-2)+f(n-3);


                                                                                    TIO






                                                                                    share|improve this answer









                                                                                    $endgroup$















                                                                                      1












                                                                                      1








                                                                                      1





                                                                                      $begingroup$

                                                                                      Java, 41 bytes



                                                                                      Can't use a lambda (runtime error). Port of this Javascript answer



                                                                                      int f(int n)return n<3?1:f(n-2)+f(n-3);


                                                                                      TIO






                                                                                      share|improve this answer









                                                                                      $endgroup$



                                                                                      Java, 41 bytes



                                                                                      Can't use a lambda (runtime error). Port of this Javascript answer



                                                                                      int f(int n)return n<3?1:f(n-2)+f(n-3);


                                                                                      TIO







                                                                                      share|improve this answer












                                                                                      share|improve this answer



                                                                                      share|improve this answer










                                                                                      answered 6 hours ago









                                                                                      Benjamin UrquhartBenjamin Urquhart

                                                                                      37017




                                                                                      37017





















                                                                                          1












                                                                                          $begingroup$

                                                                                          x86 32-bit machine code, 17 bytes



                                                                                          53 33 db f7 e3 43 83 c1 04 03 d8 93 92 e2 fa 5b c3


                                                                                          Disassembly:



                                                                                          00CE1250 53 push ebx 
                                                                                          00CE1251 33 DB xor ebx,ebx
                                                                                          00CE1253 F7 E3 mul eax,ebx
                                                                                          00CE1255 43 inc ebx
                                                                                          00CE1256 83 C1 04 add ecx,4
                                                                                          00CE1259 03 D8 add ebx,eax
                                                                                          00CE125B 93 xchg eax,ebx
                                                                                          00CE125C 92 xchg eax,edx
                                                                                          00CE125D E2 FA loop myloop (0CE1259h)
                                                                                          00CE125F 5B pop ebx
                                                                                          00CE1260 C3 ret


                                                                                          It is 0-indexed. The initialization is conveniently achieved by calculating eax * 0. The 128-bit result is 0, and it goes in edx:eax.



                                                                                          At the beginning of each iteration, the order of the registers is ebx, eax, edx. I had to choose the right order to take advantage of the encoding for the xchg eax instruction - 1 byte.



                                                                                          I had to add 4 to the loop counter in order to let the output reach eax, which holds the function's return value in the fastcall convention.



                                                                                          I could use some other calling convention, which doesn't require saving and restoring ebx, but fastcall is fun anyway :)






                                                                                          share|improve this answer









                                                                                          $endgroup$












                                                                                          • $begingroup$
                                                                                            I love to see machine code answers on PP&CG! +1
                                                                                            $endgroup$
                                                                                            – Tau
                                                                                            24 mins ago















                                                                                          1












                                                                                          $begingroup$

                                                                                          x86 32-bit machine code, 17 bytes



                                                                                          53 33 db f7 e3 43 83 c1 04 03 d8 93 92 e2 fa 5b c3


                                                                                          Disassembly:



                                                                                          00CE1250 53 push ebx 
                                                                                          00CE1251 33 DB xor ebx,ebx
                                                                                          00CE1253 F7 E3 mul eax,ebx
                                                                                          00CE1255 43 inc ebx
                                                                                          00CE1256 83 C1 04 add ecx,4
                                                                                          00CE1259 03 D8 add ebx,eax
                                                                                          00CE125B 93 xchg eax,ebx
                                                                                          00CE125C 92 xchg eax,edx
                                                                                          00CE125D E2 FA loop myloop (0CE1259h)
                                                                                          00CE125F 5B pop ebx
                                                                                          00CE1260 C3 ret


                                                                                          It is 0-indexed. The initialization is conveniently achieved by calculating eax * 0. The 128-bit result is 0, and it goes in edx:eax.



                                                                                          At the beginning of each iteration, the order of the registers is ebx, eax, edx. I had to choose the right order to take advantage of the encoding for the xchg eax instruction - 1 byte.



                                                                                          I had to add 4 to the loop counter in order to let the output reach eax, which holds the function's return value in the fastcall convention.



                                                                                          I could use some other calling convention, which doesn't require saving and restoring ebx, but fastcall is fun anyway :)






                                                                                          share|improve this answer









                                                                                          $endgroup$












                                                                                          • $begingroup$
                                                                                            I love to see machine code answers on PP&CG! +1
                                                                                            $endgroup$
                                                                                            – Tau
                                                                                            24 mins ago













                                                                                          1












                                                                                          1








                                                                                          1





                                                                                          $begingroup$

                                                                                          x86 32-bit machine code, 17 bytes



                                                                                          53 33 db f7 e3 43 83 c1 04 03 d8 93 92 e2 fa 5b c3


                                                                                          Disassembly:



                                                                                          00CE1250 53 push ebx 
                                                                                          00CE1251 33 DB xor ebx,ebx
                                                                                          00CE1253 F7 E3 mul eax,ebx
                                                                                          00CE1255 43 inc ebx
                                                                                          00CE1256 83 C1 04 add ecx,4
                                                                                          00CE1259 03 D8 add ebx,eax
                                                                                          00CE125B 93 xchg eax,ebx
                                                                                          00CE125C 92 xchg eax,edx
                                                                                          00CE125D E2 FA loop myloop (0CE1259h)
                                                                                          00CE125F 5B pop ebx
                                                                                          00CE1260 C3 ret


                                                                                          It is 0-indexed. The initialization is conveniently achieved by calculating eax * 0. The 128-bit result is 0, and it goes in edx:eax.



                                                                                          At the beginning of each iteration, the order of the registers is ebx, eax, edx. I had to choose the right order to take advantage of the encoding for the xchg eax instruction - 1 byte.



                                                                                          I had to add 4 to the loop counter in order to let the output reach eax, which holds the function's return value in the fastcall convention.



                                                                                          I could use some other calling convention, which doesn't require saving and restoring ebx, but fastcall is fun anyway :)






                                                                                          share|improve this answer









                                                                                          $endgroup$



                                                                                          x86 32-bit machine code, 17 bytes



                                                                                          53 33 db f7 e3 43 83 c1 04 03 d8 93 92 e2 fa 5b c3


                                                                                          Disassembly:



                                                                                          00CE1250 53 push ebx 
                                                                                          00CE1251 33 DB xor ebx,ebx
                                                                                          00CE1253 F7 E3 mul eax,ebx
                                                                                          00CE1255 43 inc ebx
                                                                                          00CE1256 83 C1 04 add ecx,4
                                                                                          00CE1259 03 D8 add ebx,eax
                                                                                          00CE125B 93 xchg eax,ebx
                                                                                          00CE125C 92 xchg eax,edx
                                                                                          00CE125D E2 FA loop myloop (0CE1259h)
                                                                                          00CE125F 5B pop ebx
                                                                                          00CE1260 C3 ret


                                                                                          It is 0-indexed. The initialization is conveniently achieved by calculating eax * 0. The 128-bit result is 0, and it goes in edx:eax.



                                                                                          At the beginning of each iteration, the order of the registers is ebx, eax, edx. I had to choose the right order to take advantage of the encoding for the xchg eax instruction - 1 byte.



                                                                                          I had to add 4 to the loop counter in order to let the output reach eax, which holds the function's return value in the fastcall convention.



                                                                                          I could use some other calling convention, which doesn't require saving and restoring ebx, but fastcall is fun anyway :)







                                                                                          share|improve this answer












                                                                                          share|improve this answer



                                                                                          share|improve this answer










                                                                                          answered 5 hours ago









                                                                                          anatolyganatolyg

                                                                                          7,2392166




                                                                                          7,2392166











                                                                                          • $begingroup$
                                                                                            I love to see machine code answers on PP&CG! +1
                                                                                            $endgroup$
                                                                                            – Tau
                                                                                            24 mins ago
















                                                                                          • $begingroup$
                                                                                            I love to see machine code answers on PP&CG! +1
                                                                                            $endgroup$
                                                                                            – Tau
                                                                                            24 mins ago















                                                                                          $begingroup$
                                                                                          I love to see machine code answers on PP&CG! +1
                                                                                          $endgroup$
                                                                                          – Tau
                                                                                          24 mins ago




                                                                                          $begingroup$
                                                                                          I love to see machine code answers on PP&CG! +1
                                                                                          $endgroup$
                                                                                          – Tau
                                                                                          24 mins ago











                                                                                          0












                                                                                          $begingroup$


                                                                                          Gaia, 16 14 bytes



                                                                                          7b@((⟨ṇ;(++⟩ₓ)


                                                                                          Try it online!



                                                                                          7b		| push [1 1 1]
                                                                                          @(( | push input, decrement twice
                                                                                          ⟨ ⟩ₓ | do the following that many times (0 times if 0 or less)
                                                                                          ṇ | pop the first element and leave the rest below
                                                                                          ; | copy from below
                                                                                          ( | take the first element
                                                                                          + | add the two together
                                                                                          + | and concatenate to the list. End loop.
                                                                                          ) | finally, take the last element





                                                                                          share|improve this answer











                                                                                          $endgroup$

















                                                                                            0












                                                                                            $begingroup$


                                                                                            Gaia, 16 14 bytes



                                                                                            7b@((⟨ṇ;(++⟩ₓ)


                                                                                            Try it online!



                                                                                            7b		| push [1 1 1]
                                                                                            @(( | push input, decrement twice
                                                                                            ⟨ ⟩ₓ | do the following that many times (0 times if 0 or less)
                                                                                            ṇ | pop the first element and leave the rest below
                                                                                            ; | copy from below
                                                                                            ( | take the first element
                                                                                            + | add the two together
                                                                                            + | and concatenate to the list. End loop.
                                                                                            ) | finally, take the last element





                                                                                            share|improve this answer











                                                                                            $endgroup$















                                                                                              0












                                                                                              0








                                                                                              0





                                                                                              $begingroup$


                                                                                              Gaia, 16 14 bytes



                                                                                              7b@((⟨ṇ;(++⟩ₓ)


                                                                                              Try it online!



                                                                                              7b		| push [1 1 1]
                                                                                              @(( | push input, decrement twice
                                                                                              ⟨ ⟩ₓ | do the following that many times (0 times if 0 or less)
                                                                                              ṇ | pop the first element and leave the rest below
                                                                                              ; | copy from below
                                                                                              ( | take the first element
                                                                                              + | add the two together
                                                                                              + | and concatenate to the list. End loop.
                                                                                              ) | finally, take the last element





                                                                                              share|improve this answer











                                                                                              $endgroup$




                                                                                              Gaia, 16 14 bytes



                                                                                              7b@((⟨ṇ;(++⟩ₓ)


                                                                                              Try it online!



                                                                                              7b		| push [1 1 1]
                                                                                              @(( | push input, decrement twice
                                                                                              ⟨ ⟩ₓ | do the following that many times (0 times if 0 or less)
                                                                                              ṇ | pop the first element and leave the rest below
                                                                                              ; | copy from below
                                                                                              ( | take the first element
                                                                                              + | add the two together
                                                                                              + | and concatenate to the list. End loop.
                                                                                              ) | finally, take the last element






                                                                                              share|improve this answer














                                                                                              share|improve this answer



                                                                                              share|improve this answer








                                                                                              edited 6 hours ago

























                                                                                              answered 7 hours ago









                                                                                              GiuseppeGiuseppe

                                                                                              17.6k31153




                                                                                              17.6k31153



























                                                                                                  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

                                                                                                  Reverse int within the 32-bit signed integer range: [−2^31, 2^31 − 1]Combining two 32-bit integers into one 64-bit integerDetermine if an int is within rangeLossy packing 32 bit integer to 16 bitComputing the square root of a 64-bit integerKeeping integer addition within boundsSafe multiplication of two 64-bit signed integersLeetcode 10: Regular Expression MatchingSigned integer-to-ascii x86_64 assembler macroReverse the digits of an Integer“Add two numbers given in reverse order from a linked list”

                                                                                                  Category:Fedor von Bock Media in category "Fedor von Bock"Navigation menuUpload mediaISNI: 0000 0000 5511 3417VIAF ID: 24712551GND ID: 119294796Library of Congress authority ID: n96068363BnF ID: 12534305fSUDOC authorities ID: 034604189Open Library ID: OL338253ANKCR AUT ID: jn19990000869National Library of Israel ID: 000514068National Thesaurus for Author Names ID: 341574317ReasonatorScholiaStatistics

                                                                                                  Kiel Indholdsfortegnelse Historie | Transport og færgeforbindelser | Sejlsport og anden sport | Kultur | Kendte personer fra Kiel | Noter | Litteratur | Eksterne henvisninger | Navigationsmenuwww.kiel.de54°19′31″N 10°8′26″Ø / 54.32528°N 10.14056°Ø / 54.32528; 10.14056Oberbürgermeister Dr. Ulf Kämpferwww.statistik-nord.deDen danske Stats StatistikKiels hjemmesiderrrWorldCat312794080n790547494030481-4