Last active
December 4, 2017 07:13
-
-
Save evilj0e/ceed1f10da4b824ad45f852f9b9fc738 to your computer and use it in GitHub Desktop.
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 characters
var fs = require('fs'); | |
var text = fs.readFileSync('input.txt', 'utf8'); | |
var data = text.split('\n'); | |
function isValid(password) { | |
var parts = password.split(' '); | |
var isValid = true; | |
var hash = {}; | |
for (var i = 0; i < parts.length; i++) { | |
var part = parts[i]; | |
if (hash[part] && hash[part] === 1) { | |
isValid = false; | |
break; | |
} else { | |
hash[part] = hash[part] ? (hash[part] + 1) : 1; | |
} | |
}; | |
return isValid; | |
} | |
function checkArray(data) { | |
return data.reduce(function (acc, item) { | |
return acc + isValid(item); | |
}, 0); | |
} | |
console.log(checkArray(data)); |
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 characters
var fs = require('fs'); | |
var text = fs.readFileSync('input.txt', 'utf8'); | |
var data = text.split('\n'); | |
function isValid(password) { | |
var parts = password.split(' '); | |
var isValid = true; | |
var hash = {}; | |
for (var i = 0; i < parts.length; i++) { | |
var part = parts[i].split('').sort().join(''); | |
if (hash[part] && hash[part] === 1) { | |
isValid = false; | |
break; | |
} else { | |
hash[part] = hash[part] ? (hash[part] + 1) : 1; | |
} | |
}; | |
return isValid; | |
} | |
function checkArray(data) { | |
return data.reduce(function (acc, item) { | |
return acc + isValid(item); | |
}, 0); | |
} | |
console.log(checkArray(data)); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment