Created
February 12, 2022 01:20
-
-
Save richie3366/246ce728568ad1836cd63694fef7b908 to your computer and use it in GitHub Desktop.
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') | |
const ALPHA = 'ABCDEFGHIJKLMNOPQRSTUVWXYZ'.split('') | |
const RALPHA = new Map(ALPHA.map((e, i)=>[e, i])) | |
const rotBy = (word, n) => word.split('').map((l) => ALPHA[(RALPHA.get(l) + n) % ALPHA.length]).join('') | |
const rotByP = (word, n) => word.split('').map((l, i) => ALPHA[(RALPHA.get(l) + n + i) % ALPHA.length]).join('') | |
let list = fs.readFileSync('./mots.txt').toString().split('\n').filter(Boolean) | |
let set = new Set(list) | |
const stats = [] | |
//for (let i = 0; i < 26; i++) { | |
let rotN = 2//i | |
let rotated = list.filter(mot => set.has(rotByP(mot, rotN))).map(mot => [mot, rotByP(mot, rotN)]) | |
//if (rotN === 13) rotated = rotated.filter(([mot], i, a) => a.find(([,e], i2)=> i2 > i && mot === e)) | |
let maxLen = rotated.reduce((ac,[mot]) => mot.length > ac ? mot.length : ac, 0) | |
stats.push({rotN, maxLen, nb: rotated.length}) | |
console.log(rotated) | |
//} | |
console.table(stats) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment