Last active
April 13, 2016 15:23
-
-
Save ideadapt/6b4896048062fb005506614615c26976 to your computer and use it in GitHub Desktop.
Revisions
-
ideadapt revised this gist
Apr 13, 2016 . 1 changed file with 1 addition and 4 deletions.There are no files selected for viewing
This file contains hidden or 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 charactersOriginal file line number Diff line number Diff line change @@ -1,7 +1,6 @@ 'use strict' var fs = require('fs') var inFile = '19.txt' var content = fs.readFileSync(inFile, {encoding: 'UTF-8'}) @@ -33,9 +32,7 @@ for(var line of termLines){ let indizes = findAllIndexOf(text, term) let linePermutations = indizes .map(produce.bind(null, text, term, product)) permutations.push(...linePermutations) } permutations = unique(permutations) -
ideadapt created this gist
Apr 13, 2016 .There are no files selected for viewing
This file contains hidden or 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 charactersOriginal file line number Diff line number Diff line change @@ -0,0 +1,45 @@ 'use strict' var fs = require('fs') var crypto = require('crypto') var inFile = '19.txt' var content = fs.readFileSync(inFile, {encoding: 'UTF-8'}) var lines = content.split('\n') var text = lines[lines.length -1] var termLines = lines.slice(0,-1).filter(String) var permutations = [] function findAllIndexOf(text, term){ let match let matches = [] let regexp = new RegExp(term, 'g') while ((match = regexp.exec(text)) != null) { matches.push(match.index) } return matches } function produce(text, term, product, index){ return text.substr(0, index) + product + text.substr(index + term.length) } function unique(array){ return [...new Set(array)] } for(var line of termLines){ let [term, _, product] = line.split(' ') let indizes = findAllIndexOf(text, term) let linePermutations = indizes .map(produce.bind(null, text, term, product)) .map((permutation) => { return crypto.createHash('md5').update(permutation).digest('hex') }) permutations.push(...linePermutations) } permutations = unique(permutations) console.log(permutations.length) // run with `node --harmony_destructuring 19.js`