Created
February 11, 2020 17:41
-
-
Save kylehovey/2e5b1cbc3f849b205d6bfa42828ebbba to your computer and use it in GitHub Desktop.
This file contains hidden or 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
const mapper = predicate => n => predicate(n) ? 1 : 0; | |
const [isEven, isOdd] = [0,1].map(k => mapper(n => n % 2 === k)); | |
const iverson = k => mapper(n => n === k); | |
const range = n => Array(n).fill().map((_, i) => i); | |
const coverNegative = f => n => n < 0 ? 0 : f(n); | |
const conjugatePair = (a, b) => [a+b, a-b]; | |
const a = coverNegative( | |
n => 4*b(n-1) + 2*a(n-1) + a(n-2) + iverson(0)(n) | |
); | |
const b = coverNegative( | |
n => a(n-1) + b(n-1) | |
); | |
const [alpha, beta] = conjugatePair(1, Math.sqrt(3)); | |
const A = 1/3; | |
const [B, C] = conjugatePair(1/3, 1/(2*Math.sqrt(3))); | |
const soln = n => A*(-1)**n + B*alpha**n + C*beta**n; | |
console.log( | |
range(10).map(a) | |
); | |
console.log( | |
range(10).map(soln) | |
); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment