31 lines
629 B
JavaScript
31 lines
629 B
JavaScript
const fs = require('fs');
|
|
|
|
// const inputArray = fs.readFileSync('sample.txt').toString().split("\n");
|
|
const inputArray = fs.readFileSync('input.txt').toString().split("\n");
|
|
const buffer = inputArray[0];
|
|
|
|
// Part One
|
|
|
|
for (let i = 4; i < buffer.length; i++) {
|
|
const chars = buffer.substring(i-4, i).split("");
|
|
let unique = [...new Set(chars)];
|
|
if (unique.length === 4) {
|
|
console.log(i)
|
|
break;
|
|
}
|
|
}
|
|
|
|
|
|
// Part Two
|
|
|
|
for (let i = 14; i < buffer.length; i++) {
|
|
const chars = buffer.substring(i-14, i).split("");
|
|
let unique = [...new Set(chars)];
|
|
if (unique.length === 14) {
|
|
console.log(i)
|
|
break;
|
|
}
|
|
}
|
|
|
|
|