Communities

Writing
Writing
Codidact Meta
Codidact Meta
The Great Outdoors
The Great Outdoors
Photography & Video
Photography & Video
Scientific Speculation
Scientific Speculation
Cooking
Cooking
Electrical Engineering
Electrical Engineering
Judaism
Judaism
Languages & Linguistics
Languages & Linguistics
Software Development
Software Development
Mathematics
Mathematics
Christianity
Christianity
Code Golf
Code Golf
Music
Music
Physics
Physics
Linux Systems
Linux Systems
Power Users
Power Users
Tabletop RPGs
Tabletop RPGs
Community Proposals
Community Proposals
tag:snake search within a tag
answers:0 unanswered questions
user:xxxx search by author id
score:0.5 posts with 0.5+ score
"snake oil" exact phrase
votes:4 posts with 4+ votes
created:<1w created < 1 week ago
post_type:xxxx type of post
Search help
Notifications
Mark all as read See all your notifications »
Sandbox

Post History

60%
+1 −0
Sandbox The Pell Numbers[FINALIZED]

posted 4y ago by Razetime‭  ·  edited 4y ago by Razetime‭

#3: Post edited by user avatar Razetime‭ · 2021-02-17T04:42:02Z (almost 4 years ago)
finalized
  • The Pell Numbers
  • The Pell Numbers[FINALIZED]
  • # Introduction
  • The Pell(no, not Bell) Numbers are a simple, Fibonacci-like sequence, defined by the following relation:
  • \$P_n=\begin{cases}0&\mbox{if }n=0;\\\\1&\mbox{if }n=1;\\\\2P_{n-1}+P_{n-2}&\mbox{otherwise.}\end{cases}\$
  • They also have a closed form:
  • \$P_n=\frac{\left(1+\sqrt2\right)^n-\left(1-\sqrt2\right)^n}{2\sqrt2}\$
  • And a matrix multiplication based form, for the daring:
  • \$\begin{pmatrix} P_{n+1} & P_n \\\\ P_n & P_{n-1} \end{pmatrix} = \begin{pmatrix} 2 & 1 \\\\ 1 & 0 \end{pmatrix}^n.\$
  • # Challenge
  • Your mission, should you choose to accept it, is to do any one of the following:
  • 1. Given \$n\$, calculate the \$n^{th}\$ term of the sequence (0 or 1-indexed).
  • 2. Given \$n\$, calculate the first \$n\$ elements of the sequence.
  • 3. Output the sequence indefinitely.
  • # Scoring
  • This is code-golf. Shortest answer in each language wins.
  • # Introduction
  • The [Pell](https://en.wikipedia.org/wiki/Pell_number)(no, not Bell) Numbers are a simple, Fibonacci-like sequence, defined by the following relation:
  • \$P_n=\begin{cases}0&\mbox{if }n=0;\\\\1&\mbox{if }n=1;\\\\2P_{n-1}+P_{n-2}&\mbox{otherwise.}\end{cases}\$
  • They also have a closed form:
  • \$P_n=\frac{\left(1+\sqrt2\right)^n-\left(1-\sqrt2\right)^n}{2\sqrt2}\$
  • And a matrix multiplication based form, for the daring:
  • \$\begin{pmatrix} P_{n+1} & P_n \\\\ P_n & P_{n-1} \end{pmatrix} = \begin{pmatrix} 2 & 1 \\\\ 1 & 0 \end{pmatrix}^n.\$
  • # Challenge
  • Your mission, should you choose to accept it, is to do any one of the following:
  • 1. Given \$n\$, calculate the \$n^{th}\$ term of the sequence (0 or 1-indexed).
  • 2. Given \$n\$, calculate the first \$n\$ elements of the sequence.
  • 3. Output the sequence indefinitely.
  • # Scoring
  • This is code-golf. Shortest answer in each language wins.
#2: Post edited by user avatar Razetime‭ · 2021-02-10T04:10:53Z (almost 4 years ago)
  • # Introduction
  • The Pell(no, not Bell) Numbers are a simple, Fibonacci-like sequence, defined by the following relation:
  • \$P_n=\begin{cases}0&\mbox{if }n=0;\\\\1&\mbox{if }n=1;\\\\2P_{n-1}+P_{n-2}&\mbox{otherwise.}\end{cases}\$
  • They also have a closed form:
  • \$P_n=\frac{\left(1+\sqrt2\right)^n-\left(1-\sqrt2\right)^n}{2\sqrt2}\$
  • And a matrix multiplication based form, for the daring:
  • \$\begin{pmatrix} P_{n+1} & P_n \\\\ P_n & P_{n-1} \end{pmatrix} = \begin{pmatrix} 2 & 1 \\\\ 1 & 0 \end{pmatrix}^n.\$
  • # Challenge
  • Your mission, should you choose to accept it, is to do any one of the following:
  • 1. Given \$n\$, calculate the \$n^{th}\$ number of the sequence.
  • 2. Given \$n\$, calculate the first \$n\$ elements of the sequence.
  • 3. Output the sequence indefinitely.
  • # Scoring
  • This is code-golf. Shortest answer in each language wins.
  • # Introduction
  • The Pell(no, not Bell) Numbers are a simple, Fibonacci-like sequence, defined by the following relation:
  • \$P_n=\begin{cases}0&\mbox{if }n=0;\\\\1&\mbox{if }n=1;\\\\2P_{n-1}+P_{n-2}&\mbox{otherwise.}\end{cases}\$
  • They also have a closed form:
  • \$P_n=\frac{\left(1+\sqrt2\right)^n-\left(1-\sqrt2\right)^n}{2\sqrt2}\$
  • And a matrix multiplication based form, for the daring:
  • \$\begin{pmatrix} P_{n+1} & P_n \\\\ P_n & P_{n-1} \end{pmatrix} = \begin{pmatrix} 2 & 1 \\\\ 1 & 0 \end{pmatrix}^n.\$
  • # Challenge
  • Your mission, should you choose to accept it, is to do any one of the following:
  • 1. Given \$n\$, calculate the \$n^{th}\$ term of the sequence (0 or 1-indexed).
  • 2. Given \$n\$, calculate the first \$n\$ elements of the sequence.
  • 3. Output the sequence indefinitely.
  • # Scoring
  • This is code-golf. Shortest answer in each language wins.
#1: Initial revision by user avatar Razetime‭ · 2021-02-10T04:09:35Z (almost 4 years ago)
The Pell Numbers
# Introduction

The Pell(no, not Bell) Numbers are a simple, Fibonacci-like sequence, defined by the following relation:

\$P_n=\begin{cases}0&\mbox{if }n=0;\\\\1&\mbox{if }n=1;\\\\2P_{n-1}+P_{n-2}&\mbox{otherwise.}\end{cases}\$

They also have a closed form:

\$P_n=\frac{\left(1+\sqrt2\right)^n-\left(1-\sqrt2\right)^n}{2\sqrt2}\$

And a matrix multiplication based form, for the daring:

\$\begin{pmatrix} P_{n+1} & P_n \\\\ P_n & P_{n-1} \end{pmatrix} = \begin{pmatrix} 2 & 1 \\\\ 1 & 0 \end{pmatrix}^n.\$


# Challenge

Your mission, should you choose to accept it, is to do any one of the following:

1. Given \$n\$, calculate the \$n^{th}\$ number of the sequence.

2. Given \$n\$, calculate the first \$n\$ elements of the sequence.

3. Output the sequence indefinitely.

# Scoring

This is code-golf. Shortest answer in each language wins.