Created
March 9, 2020 02:39
-
-
Save funwithtriangles/0eebf7a6e734c0b303e17b28f438416f to your computer and use it in GitHub Desktop.
random fibonacci sequence
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
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