Created
October 1, 2021 07:53
-
-
Save EmpeRoar/a20d6572d55b6163123484ccc5a247f5 to your computer and use it in GitHub Desktop.
Advent Of Code
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
/*---------------part 1-----------------*/ | |
let validCount = 0; | |
input.forEach(s => { | |
let [left, password] = s.split(': '); | |
let [policy, charToCheck] = left.split(' '); | |
let [leastPolicy, mostPolicy] = policy.split('-'); | |
let occurence = password.split(charToCheck).length - 1; | |
if(occurence >= leastPolicy && occurence <= mostPolicy) | |
{ | |
validCount++; | |
} | |
}); | |
/*--------------part 2-------------------*/ | |
let validCount = 0; | |
input.forEach(s => { | |
let [left, password] = s.split(': '); | |
let [policy, charToCheck] = left.split(' '); | |
let [leastPolicy, mostPolicy] = policy.split('-'); | |
let leastIndex = +leastPolicy-1; | |
let mostIndex = +mostPolicy-1; | |
if(password[leastIndex] == charToCheck && | |
password[mostIndex] != charToCheck) { | |
validCount++; | |
} | |
if(password[mostIndex] == charToCheck && | |
password[leastIndex] != charToCheck) { | |
validCount++; | |
} | |
}); | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment