diff --git a/src/oeis/A000045.ts b/src/oeis/A000045.ts index c884396bbc..ddff62f2dc 100644 --- a/src/oeis/A000045.ts +++ b/src/oeis/A000045.ts @@ -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 { - 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 } } diff --git a/src/oeis/A000073.ts b/src/oeis/A000073.ts index 33cf2cef94..491246957e 100644 --- a/src/oeis/A000073.ts +++ b/src/oeis/A000073.ts @@ -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 { - 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 } } diff --git a/src/oeis/A000078.ts b/src/oeis/A000078.ts index 5fb5940619..006856c0dd 100644 --- a/src/oeis/A000078.ts +++ b/src/oeis/A000078.ts @@ -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 { - 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 } }