Created
July 17, 2020 17:23
-
-
Save EsteveSegura/d7677423b2454aa83a6bb7cb170cf06d to your computer and use it in GitHub Desktop.
Encontrar strings dentro de pi!
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 fs = require('fs') | |
let preLoadPi = fs.readFileSync('./pi-billion.txt', 'utf-8') | |
function findIndexInPi(str,pi){ | |
let n = parseInt(str,36) | |
let index = preLoadPi.indexOf(n) | |
let nL = n.toString().split("").length | |
let numInPi = "" | |
for(let i = 0; i < nL+8 ; i++){ | |
numInPi += pi[(index-4) + i] | |
} | |
if(!numInPi.includes("undefined")){ | |
return `El string: ${str} convertido a base36 nos da el numero: ${n} tiene un indice en pi: ${index} y aparece en pi como: ${numInPi} y su remplazo: ${numInPi.replace(n,str)}` | |
}else{ | |
return `No esta en el primer "billion" de numeros dentro de PI` | |
} | |
} | |
let phrase = findIndexInPi("vendo opel corsa",preLoadPi) | |
console.log(phrase) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment