Patience, young “Padovan”Output the van der Corput sequenceGenerate n-ary numbersGenerate a Padovan SpiralGenerate an ASCII Padovan SpiralGolf a Custom Fibonacci SequenceImplement the Fibonacci sequence… Shifted to the rightDizzy integer enumerationModulus SummationFour Spiraling AxesIt's getting harder and harder to be composite these days
Theorems that impeded progress
What do you call something that goes against the spirit of the law, but is legal when interpreting the law to the letter?
How can bays and straits be determined in a procedurally generated map?
Motorized valve interfering with button?
Why CLRS example on residual networks does not follows its formula?
declaring a variable twice in IIFE
What are these boxed doors outside store fronts in New York?
Can I make popcorn with any corn?
Pronouncing Dictionary.com's W.O.D "vade mecum" in English
How to get the available space of $HOME as a variable in shell scripting?
A Journey Through Space and Time
How do I create uniquely male characters?
Why has Russell's definition of numbers using equivalence classes been finally abandoned? ( If it has actually been abandoned).
Find original functions from a composite function
How to add power-LED to my small amplifier?
How long does it take to type this?
What is the command to reset a PC without deleting any files
Patience, young "Padovan"
How to report a triplet of septets in NMR tabulation?
How is it possible for user to changed after storage was encrypted? (on OS X, Android)
The magic money tree problem
Shell script not opening as desktop application
How can the DM most effectively choose 1 out of an odd number of players to be targeted by an attack or effect?
If Manufacturer spice model and Datasheet give different values which should I use?
Patience, young “Padovan”
Output the van der Corput sequenceGenerate n-ary numbersGenerate a Padovan SpiralGenerate an ASCII Padovan SpiralGolf a Custom Fibonacci SequenceImplement the Fibonacci sequence… Shifted to the rightDizzy integer enumerationModulus SummationFour Spiraling AxesIt's getting harder and harder to be composite these days
$begingroup$
Everyone knows the Fibonacci sequence:
You take a square, attach an equal square to it, then repeatedly attach a square whose side length is equal to the largest side length of the resulting rectangle.
The result is a beautiful spiral of squares whose sequence of numbers is the Fibonacci sequence:

But, what if we didn't want to use squares?
If we use equilateral triangles—instead of squares—in a similar fashion, we get an equally beautiful spiral of triangles and a new sequence: the Padovan sequence, aka A000931:

Task:
Given a positive integer, $N$, output $a_N$, the $N$th term in the Padovan sequence OR the first $N$ terms.
Assume that the first three terms of the sequence are all $1$. Thus, the sequence will start as follows:
$$
1,1,1,2,2,3,...
$$
Input:
Any positive integer $Nge0$
Invalid input does not have to be taken into account
Output:
The $N$th term in the Padovan sequence OR the first $N$ terms of the Padovan sequence.
If the first $N$ terms are printed out, the output can be whatever is convenient (list/array, multi-line string, etc.)
Can be either $0$-indexed or $1$-indexed
Test Cases:
(0-indexed, $N$th term)
Input | Output
--------------
0 | 1
1 | 1
2 | 1
4 | 2
6 | 4
14 | 37
20 | 200
33 | 7739
(0-indexed, first $N$ terms)
Input | Output
--------------
1 | 1
3 | 1,1,1
4 | 1,1,1,2
7 | 1,1,1,2,2,3,4
10 | 1,1,1,2,2,3,4,5,7,9
12 | 1,1,1,2,2,3,4,5,7,9,12,16
Rules:
This is code-golf: the fewer bytes, the better!
Standard loopholes are forbidden.
code-golf number sequence
$endgroup$
add a comment |
$begingroup$
Everyone knows the Fibonacci sequence:
You take a square, attach an equal square to it, then repeatedly attach a square whose side length is equal to the largest side length of the resulting rectangle.
The result is a beautiful spiral of squares whose sequence of numbers is the Fibonacci sequence:

But, what if we didn't want to use squares?
If we use equilateral triangles—instead of squares—in a similar fashion, we get an equally beautiful spiral of triangles and a new sequence: the Padovan sequence, aka A000931:

Task:
Given a positive integer, $N$, output $a_N$, the $N$th term in the Padovan sequence OR the first $N$ terms.
Assume that the first three terms of the sequence are all $1$. Thus, the sequence will start as follows:
$$
1,1,1,2,2,3,...
$$
Input:
Any positive integer $Nge0$
Invalid input does not have to be taken into account
Output:
The $N$th term in the Padovan sequence OR the first $N$ terms of the Padovan sequence.
If the first $N$ terms are printed out, the output can be whatever is convenient (list/array, multi-line string, etc.)
Can be either $0$-indexed or $1$-indexed
Test Cases:
(0-indexed, $N$th term)
Input | Output
--------------
0 | 1
1 | 1
2 | 1
4 | 2
6 | 4
14 | 37
20 | 200
33 | 7739
(0-indexed, first $N$ terms)
Input | Output
--------------
1 | 1
3 | 1,1,1
4 | 1,1,1,2
7 | 1,1,1,2,2,3,4
10 | 1,1,1,2,2,3,4,5,7,9
12 | 1,1,1,2,2,3,4,5,7,9,12,16
Rules:
This is code-golf: the fewer bytes, the better!
Standard loopholes are forbidden.
code-golf number sequence
$endgroup$
$begingroup$
Sandbox post can be found here.
$endgroup$
– Tau
1 hour ago
1
$begingroup$
14(0-indexed) is shown as outputting28while I believe it should yield37
$endgroup$
– Jonathan Allan
36 mins ago
$begingroup$
@JonathanAllan yes, you are correct. I fixed the last two test cases for $N$th term but not that one. The post has been edited.
$endgroup$
– Tau
34 mins ago
add a comment |
$begingroup$
Everyone knows the Fibonacci sequence:
You take a square, attach an equal square to it, then repeatedly attach a square whose side length is equal to the largest side length of the resulting rectangle.
The result is a beautiful spiral of squares whose sequence of numbers is the Fibonacci sequence:

But, what if we didn't want to use squares?
If we use equilateral triangles—instead of squares—in a similar fashion, we get an equally beautiful spiral of triangles and a new sequence: the Padovan sequence, aka A000931:

Task:
Given a positive integer, $N$, output $a_N$, the $N$th term in the Padovan sequence OR the first $N$ terms.
Assume that the first three terms of the sequence are all $1$. Thus, the sequence will start as follows:
$$
1,1,1,2,2,3,...
$$
Input:
Any positive integer $Nge0$
Invalid input does not have to be taken into account
Output:
The $N$th term in the Padovan sequence OR the first $N$ terms of the Padovan sequence.
If the first $N$ terms are printed out, the output can be whatever is convenient (list/array, multi-line string, etc.)
Can be either $0$-indexed or $1$-indexed
Test Cases:
(0-indexed, $N$th term)
Input | Output
--------------
0 | 1
1 | 1
2 | 1
4 | 2
6 | 4
14 | 37
20 | 200
33 | 7739
(0-indexed, first $N$ terms)
Input | Output
--------------
1 | 1
3 | 1,1,1
4 | 1,1,1,2
7 | 1,1,1,2,2,3,4
10 | 1,1,1,2,2,3,4,5,7,9
12 | 1,1,1,2,2,3,4,5,7,9,12,16
Rules:
This is code-golf: the fewer bytes, the better!
Standard loopholes are forbidden.
code-golf number sequence
$endgroup$
Everyone knows the Fibonacci sequence:
You take a square, attach an equal square to it, then repeatedly attach a square whose side length is equal to the largest side length of the resulting rectangle.
The result is a beautiful spiral of squares whose sequence of numbers is the Fibonacci sequence:

But, what if we didn't want to use squares?
If we use equilateral triangles—instead of squares—in a similar fashion, we get an equally beautiful spiral of triangles and a new sequence: the Padovan sequence, aka A000931:

Task:
Given a positive integer, $N$, output $a_N$, the $N$th term in the Padovan sequence OR the first $N$ terms.
Assume that the first three terms of the sequence are all $1$. Thus, the sequence will start as follows:
$$
1,1,1,2,2,3,...
$$
Input:
Any positive integer $Nge0$
Invalid input does not have to be taken into account
Output:
The $N$th term in the Padovan sequence OR the first $N$ terms of the Padovan sequence.
If the first $N$ terms are printed out, the output can be whatever is convenient (list/array, multi-line string, etc.)
Can be either $0$-indexed or $1$-indexed
Test Cases:
(0-indexed, $N$th term)
Input | Output
--------------
0 | 1
1 | 1
2 | 1
4 | 2
6 | 4
14 | 37
20 | 200
33 | 7739
(0-indexed, first $N$ terms)
Input | Output
--------------
1 | 1
3 | 1,1,1
4 | 1,1,1,2
7 | 1,1,1,2,2,3,4
10 | 1,1,1,2,2,3,4,5,7,9
12 | 1,1,1,2,2,3,4,5,7,9,12,16
Rules:
This is code-golf: the fewer bytes, the better!
Standard loopholes are forbidden.
code-golf number sequence
code-golf number sequence
edited 33 mins ago
Tau
asked 1 hour ago
TauTau
786313
786313
$begingroup$
Sandbox post can be found here.
$endgroup$
– Tau
1 hour ago
1
$begingroup$
14(0-indexed) is shown as outputting28while I believe it should yield37
$endgroup$
– Jonathan Allan
36 mins ago
$begingroup$
@JonathanAllan yes, you are correct. I fixed the last two test cases for $N$th term but not that one. The post has been edited.
$endgroup$
– Tau
34 mins ago
add a comment |
$begingroup$
Sandbox post can be found here.
$endgroup$
– Tau
1 hour ago
1
$begingroup$
14(0-indexed) is shown as outputting28while I believe it should yield37
$endgroup$
– Jonathan Allan
36 mins ago
$begingroup$
@JonathanAllan yes, you are correct. I fixed the last two test cases for $N$th term but not that one. The post has been edited.
$endgroup$
– Tau
34 mins ago
$begingroup$
Sandbox post can be found here.
$endgroup$
– Tau
1 hour ago
$begingroup$
Sandbox post can be found here.
$endgroup$
– Tau
1 hour ago
1
1
$begingroup$
14 (0-indexed) is shown as outputting 28 while I believe it should yield 37$endgroup$
– Jonathan Allan
36 mins ago
$begingroup$
14 (0-indexed) is shown as outputting 28 while I believe it should yield 37$endgroup$
– Jonathan Allan
36 mins ago
$begingroup$
@JonathanAllan yes, you are correct. I fixed the last two test cases for $N$th term but not that one. The post has been edited.
$endgroup$
– Tau
34 mins ago
$begingroup$
@JonathanAllan yes, you are correct. I fixed the last two test cases for $N$th term but not that one. The post has been edited.
$endgroup$
– Tau
34 mins ago
add a comment |
11 Answers
11
active
oldest
votes
$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.
$endgroup$
add a comment |
$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)
$endgroup$
add a comment |
$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!
$endgroup$
add a comment |
$begingroup$
Python 2, 56 48 bytes
f=lambda n,a=1,b=1,c=1:n>2and f(n-1,b,c,a+b)or c
Try it online!
Returns nth value, 0-indexed.
$endgroup$
add a comment |
$begingroup$
J, 26 bytes
0.5<.@+1.04535%~1.32472^<:
Try it online!
Uses the closed form formula.
$endgroup$
add a comment |
$begingroup$
Jelly, 11 bytes
5B+Ɲ2ị;Ʋ⁸¡Ḣ
Try it online!
0-indexed.
$endgroup$
$begingroup$
Can you specify whether this answer is 0-indexed or 1-indexed?
$endgroup$
– Tau
28 mins ago
$begingroup$
@Tau It's 0-indexed. I've edited it in.
$endgroup$
– Erik the Outgolfer
28 mins ago
add a comment |
$begingroup$
Jelly, 10 bytes
‘HŻcḤạ¥¥‘S
A monadic Link accepting n (1-indexed) which yields P(n).
Try it online!
$endgroup$
add a comment |
$begingroup$
C# (Visual C# Interactive Compiler), 34 bytes
int f(int g)=>g<3?1:f(g-2)+f(g-3);
Try it online!
$endgroup$
add a comment |
$begingroup$
JavaScript (ES6), 23 bytes
Implements the recursive definition of A000931. Returns the $N$th term, 0-indexed.
f=n=>n<3||f(n-2)+f(n-3)
Try it online!
$endgroup$
add a comment |
$begingroup$
Japt -N, 12 bytes
<3ªßUµ2 +ß´U
Try it
$endgroup$
add a comment |
$begingroup$
Retina, 47 bytes
K`0¶1¶0
"$+"+`(.+)¶(.+)¶.+$
$&¶$.($1*_$2*_
6,G`
Try it online! Outputs the first n terms on separate lines. Explanation:
K`0¶1¶0
Replace the input with the terms for -2, -1 and 0.
"$+"+`(.+)¶(.+)¶.+$
$&¶$.($1*_$2*_
Generate the next n terms using the recurrence relation.
6,G`
Discard the first six characters, i.e. the first three lines.
$endgroup$
add a comment |
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
);
);
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
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
11 Answers
11
active
oldest
votes
11 Answers
11
active
oldest
votes
active
oldest
votes
active
oldest
votes
$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.
$endgroup$
add a comment |
$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.
$endgroup$
add a comment |
$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.
$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.
edited 27 mins ago
answered 42 mins ago
xnorxnor
93.3k18190448
93.3k18190448
add a comment |
add a comment |
$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)
$endgroup$
add a comment |
$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)
$endgroup$
add a comment |
$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)
$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)
answered 57 mins ago
EmignaEmigna
47.4k433144
47.4k433144
add a comment |
add a comment |
$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!
$endgroup$
add a comment |
$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!
$endgroup$
add a comment |
$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!
$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!
answered 55 mins ago
J42161217J42161217
13.8k21253
13.8k21253
add a comment |
add a comment |
$begingroup$
Python 2, 56 48 bytes
f=lambda n,a=1,b=1,c=1:n>2and f(n-1,b,c,a+b)or c
Try it online!
Returns nth value, 0-indexed.
$endgroup$
add a comment |
$begingroup$
Python 2, 56 48 bytes
f=lambda n,a=1,b=1,c=1:n>2and f(n-1,b,c,a+b)or c
Try it online!
Returns nth value, 0-indexed.
$endgroup$
add a comment |
$begingroup$
Python 2, 56 48 bytes
f=lambda n,a=1,b=1,c=1:n>2and f(n-1,b,c,a+b)or c
Try it online!
Returns nth value, 0-indexed.
$endgroup$
Python 2, 56 48 bytes
f=lambda n,a=1,b=1,c=1:n>2and f(n-1,b,c,a+b)or c
Try it online!
Returns nth value, 0-indexed.
answered 45 mins ago
Chas BrownChas Brown
5,2091523
5,2091523
add a comment |
add a comment |
$begingroup$
J, 26 bytes
0.5<.@+1.04535%~1.32472^<:
Try it online!
Uses the closed form formula.
$endgroup$
add a comment |
$begingroup$
J, 26 bytes
0.5<.@+1.04535%~1.32472^<:
Try it online!
Uses the closed form formula.
$endgroup$
add a comment |
$begingroup$
J, 26 bytes
0.5<.@+1.04535%~1.32472^<:
Try it online!
Uses the closed form formula.
$endgroup$
J, 26 bytes
0.5<.@+1.04535%~1.32472^<:
Try it online!
Uses the closed form formula.
edited 36 mins ago
answered 46 mins ago
JonahJonah
2,5911017
2,5911017
add a comment |
add a comment |
$begingroup$
Jelly, 11 bytes
5B+Ɲ2ị;Ʋ⁸¡Ḣ
Try it online!
0-indexed.
$endgroup$
$begingroup$
Can you specify whether this answer is 0-indexed or 1-indexed?
$endgroup$
– Tau
28 mins ago
$begingroup$
@Tau It's 0-indexed. I've edited it in.
$endgroup$
– Erik the Outgolfer
28 mins ago
add a comment |
$begingroup$
Jelly, 11 bytes
5B+Ɲ2ị;Ʋ⁸¡Ḣ
Try it online!
0-indexed.
$endgroup$
$begingroup$
Can you specify whether this answer is 0-indexed or 1-indexed?
$endgroup$
– Tau
28 mins ago
$begingroup$
@Tau It's 0-indexed. I've edited it in.
$endgroup$
– Erik the Outgolfer
28 mins ago
add a comment |
$begingroup$
Jelly, 11 bytes
5B+Ɲ2ị;Ʋ⁸¡Ḣ
Try it online!
0-indexed.
$endgroup$
Jelly, 11 bytes
5B+Ɲ2ị;Ʋ⁸¡Ḣ
Try it online!
0-indexed.
edited 27 mins ago
answered 31 mins ago
Erik the OutgolferErik the Outgolfer
33k429106
33k429106
$begingroup$
Can you specify whether this answer is 0-indexed or 1-indexed?
$endgroup$
– Tau
28 mins ago
$begingroup$
@Tau It's 0-indexed. I've edited it in.
$endgroup$
– Erik the Outgolfer
28 mins ago
add a comment |
$begingroup$
Can you specify whether this answer is 0-indexed or 1-indexed?
$endgroup$
– Tau
28 mins ago
$begingroup$
@Tau It's 0-indexed. I've edited it in.
$endgroup$
– Erik the Outgolfer
28 mins ago
$begingroup$
Can you specify whether this answer is 0-indexed or 1-indexed?
$endgroup$
– Tau
28 mins ago
$begingroup$
Can you specify whether this answer is 0-indexed or 1-indexed?
$endgroup$
– Tau
28 mins ago
$begingroup$
@Tau It's 0-indexed. I've edited it in.
$endgroup$
– Erik the Outgolfer
28 mins ago
$begingroup$
@Tau It's 0-indexed. I've edited it in.
$endgroup$
– Erik the Outgolfer
28 mins ago
add a comment |
$begingroup$
Jelly, 10 bytes
‘HŻcḤạ¥¥‘S
A monadic Link accepting n (1-indexed) which yields P(n).
Try it online!
$endgroup$
add a comment |
$begingroup$
Jelly, 10 bytes
‘HŻcḤạ¥¥‘S
A monadic Link accepting n (1-indexed) which yields P(n).
Try it online!
$endgroup$
add a comment |
$begingroup$
Jelly, 10 bytes
‘HŻcḤạ¥¥‘S
A monadic Link accepting n (1-indexed) which yields P(n).
Try it online!
$endgroup$
Jelly, 10 bytes
‘HŻcḤạ¥¥‘S
A monadic Link accepting n (1-indexed) which yields P(n).
Try it online!
answered 25 mins ago
Jonathan AllanJonathan Allan
53.7k535173
53.7k535173
add a comment |
add a comment |
$begingroup$
C# (Visual C# Interactive Compiler), 34 bytes
int f(int g)=>g<3?1:f(g-2)+f(g-3);
Try it online!
$endgroup$
add a comment |
$begingroup$
C# (Visual C# Interactive Compiler), 34 bytes
int f(int g)=>g<3?1:f(g-2)+f(g-3);
Try it online!
$endgroup$
add a comment |
$begingroup$
C# (Visual C# Interactive Compiler), 34 bytes
int f(int g)=>g<3?1:f(g-2)+f(g-3);
Try it online!
$endgroup$
C# (Visual C# Interactive Compiler), 34 bytes
int f(int g)=>g<3?1:f(g-2)+f(g-3);
Try it online!
answered 12 mins ago
Embodiment of IgnoranceEmbodiment of Ignorance
2,798127
2,798127
add a comment |
add a comment |
$begingroup$
JavaScript (ES6), 23 bytes
Implements the recursive definition of A000931. Returns the $N$th term, 0-indexed.
f=n=>n<3||f(n-2)+f(n-3)
Try it online!
$endgroup$
add a comment |
$begingroup$
JavaScript (ES6), 23 bytes
Implements the recursive definition of A000931. Returns the $N$th term, 0-indexed.
f=n=>n<3||f(n-2)+f(n-3)
Try it online!
$endgroup$
add a comment |
$begingroup$
JavaScript (ES6), 23 bytes
Implements the recursive definition of A000931. Returns the $N$th term, 0-indexed.
f=n=>n<3||f(n-2)+f(n-3)
Try it online!
$endgroup$
JavaScript (ES6), 23 bytes
Implements the recursive definition of A000931. Returns the $N$th term, 0-indexed.
f=n=>n<3||f(n-2)+f(n-3)
Try it online!
edited 5 mins ago
answered 11 mins ago
ArnauldArnauld
80.5k797333
80.5k797333
add a comment |
add a comment |
$begingroup$
Japt -N, 12 bytes
<3ªßUµ2 +ß´U
Try it
$endgroup$
add a comment |
$begingroup$
Japt -N, 12 bytes
<3ªßUµ2 +ß´U
Try it
$endgroup$
add a comment |
$begingroup$
Japt -N, 12 bytes
<3ªßUµ2 +ß´U
Try it
$endgroup$
Japt -N, 12 bytes
<3ªßUµ2 +ß´U
Try it
answered 2 mins ago
Embodiment of IgnoranceEmbodiment of Ignorance
2,798127
2,798127
add a comment |
add a comment |
$begingroup$
Retina, 47 bytes
K`0¶1¶0
"$+"+`(.+)¶(.+)¶.+$
$&¶$.($1*_$2*_
6,G`
Try it online! Outputs the first n terms on separate lines. Explanation:
K`0¶1¶0
Replace the input with the terms for -2, -1 and 0.
"$+"+`(.+)¶(.+)¶.+$
$&¶$.($1*_$2*_
Generate the next n terms using the recurrence relation.
6,G`
Discard the first six characters, i.e. the first three lines.
$endgroup$
add a comment |
$begingroup$
Retina, 47 bytes
K`0¶1¶0
"$+"+`(.+)¶(.+)¶.+$
$&¶$.($1*_$2*_
6,G`
Try it online! Outputs the first n terms on separate lines. Explanation:
K`0¶1¶0
Replace the input with the terms for -2, -1 and 0.
"$+"+`(.+)¶(.+)¶.+$
$&¶$.($1*_$2*_
Generate the next n terms using the recurrence relation.
6,G`
Discard the first six characters, i.e. the first three lines.
$endgroup$
add a comment |
$begingroup$
Retina, 47 bytes
K`0¶1¶0
"$+"+`(.+)¶(.+)¶.+$
$&¶$.($1*_$2*_
6,G`
Try it online! Outputs the first n terms on separate lines. Explanation:
K`0¶1¶0
Replace the input with the terms for -2, -1 and 0.
"$+"+`(.+)¶(.+)¶.+$
$&¶$.($1*_$2*_
Generate the next n terms using the recurrence relation.
6,G`
Discard the first six characters, i.e. the first three lines.
$endgroup$
Retina, 47 bytes
K`0¶1¶0
"$+"+`(.+)¶(.+)¶.+$
$&¶$.($1*_$2*_
6,G`
Try it online! Outputs the first n terms on separate lines. Explanation:
K`0¶1¶0
Replace the input with the terms for -2, -1 and 0.
"$+"+`(.+)¶(.+)¶.+$
$&¶$.($1*_$2*_
Generate the next n terms using the recurrence relation.
6,G`
Discard the first six characters, i.e. the first three lines.
answered 2 mins ago
NeilNeil
82.6k745179
82.6k745179
add a comment |
add a comment |
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).
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
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
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
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
$begingroup$
Sandbox post can be found here.
$endgroup$
– Tau
1 hour ago
1
$begingroup$
14(0-indexed) is shown as outputting28while I believe it should yield37$endgroup$
– Jonathan Allan
36 mins ago
$begingroup$
@JonathanAllan yes, you are correct. I fixed the last two test cases for $N$th term but not that one. The post has been edited.
$endgroup$
– Tau
34 mins ago