Skip to content

Instantly share code, notes, and snippets.

@funwithtriangles
Created March 9, 2020 02:39
Show Gist options
  • Save funwithtriangles/0eebf7a6e734c0b303e17b28f438416f to your computer and use it in GitHub Desktop.
Save funwithtriangles/0eebf7a6e734c0b303e17b28f438416f to your computer and use it in GitHub Desktop.
random fibonacci sequence
const viswanath = 1.1319882487943
const numTurns = 5000
const posNeg = () => Math.random() > 0.5 ? 1 : -1
let prev = 1
let curr = 1
let temp
for (let i = 0; i < numTurns; i++) {
temp = curr
curr = curr + prev * posNeg()
prev = temp
console.log(curr)
}
const ratio = Math.pow(Math.abs(curr), 1/numTurns)
console.log(`
Number of turns: ${numTurns}
Ratio: ${ratio}
Viswanath: ${viswanath}
`)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment