-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Dylan Ferris
committed
Sep 3, 2023
1 parent
4a02408
commit 40fa363
Showing
3 changed files
with
30 additions
and
91 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,13 +1,12 @@ | ||
// Fibonacci numbers | ||
// Fibonacci numbers: a(n) = a(n-1) + a(n-2) for n >= 2 with a(0) = 0 and a(1) = 1. | ||
export default function* A000045(): Generator<bigint> { | ||
let previous = 0n, | ||
current = 1n | ||
yield previous | ||
yield current | ||
let a0 = 0n, a1 = 1n | ||
yield a0 | ||
yield a1 | ||
for (;;) { | ||
const sum = current + previous | ||
previous = current | ||
current = sum | ||
yield current | ||
const sum = a0 + a1 | ||
a0 = a1 | ||
a1 = sum | ||
yield a1 | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,45 +1,14 @@ | ||
// Tribonacci numbers: a(n) = a(n-1) + a(n-2) + a(n-3) for n >= 3 with a(0) = a(1) = 0 and a(2) = 1. | ||
export default function* A000073(): Generator<bigint> { | ||
for (const n of [ | ||
0n, | ||
0n, | ||
1n, | ||
1n, | ||
2n, | ||
4n, | ||
7n, | ||
13n, | ||
24n, | ||
44n, | ||
81n, | ||
149n, | ||
274n, | ||
504n, | ||
927n, | ||
1705n, | ||
3136n, | ||
5768n, | ||
10609n, | ||
19513n, | ||
35890n, | ||
66012n, | ||
121415n, | ||
223317n, | ||
410744n, | ||
755476n, | ||
1389537n, | ||
2555757n, | ||
4700770n, | ||
8646064n, | ||
15902591n, | ||
29249425n, | ||
53798080n, | ||
98950096n, | ||
181997601n, | ||
334745777n, | ||
615693474n, | ||
1132436852n, | ||
]) { | ||
yield n | ||
let a0 = 0n, a1 = 0n, a2 = 1n | ||
yield a0 | ||
yield a1 | ||
yield a2 | ||
for (;;) { | ||
const sum = a0 + a1 + a2 | ||
a0 = a1 | ||
a1 = a2 | ||
a2 = sum | ||
yield a2 | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,45 +1,16 @@ | ||
// Tetranacci numbers: a(n) = a(n-1) + a(n-2) + a(n-3) + a(n-4) for n >= 4 with a(0) = a(1) = a(2) = 0 and a(3) = 1. | ||
export default function* A000078(): Generator<bigint> { | ||
for (const n of [ | ||
0n, | ||
0n, | ||
0n, | ||
1n, | ||
1n, | ||
2n, | ||
4n, | ||
8n, | ||
15n, | ||
29n, | ||
56n, | ||
108n, | ||
208n, | ||
401n, | ||
773n, | ||
1490n, | ||
2872n, | ||
5536n, | ||
10671n, | ||
20569n, | ||
39648n, | ||
76424n, | ||
147312n, | ||
283953n, | ||
547337n, | ||
1055026n, | ||
2033628n, | ||
3919944n, | ||
7555935n, | ||
14564533n, | ||
28074040n, | ||
54114452n, | ||
104308960n, | ||
201061985n, | ||
387559437n, | ||
747044834n, | ||
1439975216n, | ||
2775641472n, | ||
]) { | ||
yield n | ||
let a0 = 0n, a1 = 0n, a2 = 0n, a3 = 1n | ||
yield a0 | ||
yield a1 | ||
yield a2 | ||
yield a3 | ||
for (;;) { | ||
const sum = a0 + a1 + a2 + a3 | ||
a0 = a1 | ||
a1 = a2 | ||
a2 = a3 | ||
a3 = sum | ||
yield a3 | ||
} | ||
} |