Skip to content

Instantly share code, notes, and snippets.

@marcmartino
Last active October 5, 2021 03:21
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save marcmartino/54f5547cfbaf44ad28125ef99102dadf to your computer and use it in GitHub Desktop.
Save marcmartino/54f5547cfbaf44ad28125ef99102dadf to your computer and use it in GitHub Desktop.
Euler 2
const fibUntil = (prevSum: number, prevNums = [0,1]): number => {
const nextNum = prevNums[0] + prevNums[1]
return nextNum >= 4_000_000
? prevSum
: fibUntil(
prevSum + (nextNum % 2 === 0 ? nextNum : 0),
[prevNums[1], nextNum]
)
}
console.log(fibUntil(initialFib))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment