Skip to content

Instantly share code, notes, and snippets.

@evaletolab
Last active November 10, 2022 14:16
Show Gist options
  • Save evaletolab/5433c3569d0cdfd0851e415380bb8126 to your computer and use it in GitHub Desktop.
Save evaletolab/5433c3569d0cdfd0851e415380bb8126 to your computer and use it in GitHub Desktop.
//
// objectif
// trouver robin dans le premier million des décimales de PI
// --> https://www.pi2e.ch/blog/wp-content/uploads/2017/03/pi_hex_1m.txt
// 1. Il faut convertir un texte en base 16, exadécimal (0xff)
// La table de caractères en ASCII commence à la position 32 et se termine à la position 127 (0x7f)
// https://miro.medium.com/max/1400/1*CE8uSnYm4T-bhEFbUiGYVQ.png
function stringToHex(text) {
const seed = text.split('').reduce((value,char,index) => {
return BigInt(0x7f-32) * value + BigInt(text.charCodeAt(index) - 32);
},BigInt(0));
return seed.toString(16).slice(0,64);
}
// Avec la valeur robin on a le résultat suivant
// stringToHex('robin') => 5012ff54a
// malheureusement on ne te trouve pas :-(
//
// mais si on ne s'intéresse qu'aux caractères de a - z alors on peut compresser le résultat
// le domaine se réduit à 97 pour le a jusqu'à 122 pour le z
function stringToHex(text) {
const seed = text.split('').reduce((value,char,index) => {
return BigInt(25) * value + BigInt(text.charCodeAt(index) - 97);
},BigInt(0));
return seed.toString(16).slice(0,64);
}
// charger le
//
function loadPI(){
const xhr = new XMLHttpRequest();
xhr.open('GET', 'https://www.pi2e.ch/blog/wp-content/uploads/2017/03/pi_hex_1m.txt', true);
xhr.onreadystatechange = function(){
console.log(xhr.responseText);
}
xhr.send(null);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment