Skip to content

Instantly share code, notes, and snippets.

@EsteveSegura
Created July 17, 2020 17:23
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 EsteveSegura/d7677423b2454aa83a6bb7cb170cf06d to your computer and use it in GitHub Desktop.
Save EsteveSegura/d7677423b2454aa83a6bb7cb170cf06d to your computer and use it in GitHub Desktop.
Encontrar strings dentro de pi!
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