mirror of
https://github.com/Aviortheking/advent-of-code.git
synced 2025-07-28 22:59:51 +00:00
1000
2015/day-5/input.txt
Normal file
1000
2015/day-5/input.txt
Normal file
File diff suppressed because it is too large
Load Diff
39
2015/day-5/part-1.ts
Normal file
39
2015/day-5/part-1.ts
Normal file
@ -0,0 +1,39 @@
|
||||
import fs from 'fs'
|
||||
|
||||
|
||||
const input = fs.readFileSync(__dirname + '/input.txt').toString()
|
||||
.split('\n')
|
||||
|
||||
|
||||
|
||||
function isNice(str: string) {
|
||||
if (str.includes('ab') || str.includes('cd') || str.includes('pq') || str.includes('xy')) {
|
||||
return false
|
||||
}
|
||||
let vowelCount = 0
|
||||
let lastCharacter = ''
|
||||
let hasDoubleChar = false
|
||||
for (const char of str.split('')) {
|
||||
if (char === lastCharacter) {
|
||||
hasDoubleChar = true
|
||||
}
|
||||
lastCharacter = char
|
||||
|
||||
if ('aeiou'.includes(char)) {
|
||||
vowelCount++
|
||||
}
|
||||
|
||||
if (vowelCount >= 3 && hasDoubleChar) {
|
||||
return true
|
||||
}
|
||||
}
|
||||
|
||||
return false
|
||||
}
|
||||
|
||||
const filteredList = input.filter((it) => isNice(it))
|
||||
|
||||
|
||||
console.log(
|
||||
"Result:", filteredList.length
|
||||
)
|
43
2015/day-5/part-2.ts
Normal file
43
2015/day-5/part-2.ts
Normal file
@ -0,0 +1,43 @@
|
||||
import fs from 'fs'
|
||||
|
||||
|
||||
// const input = fs.readFileSync(__dirname + '/input.txt').toString()
|
||||
// .split('\n')
|
||||
const input = ['qjhvhtzxzqqjkmpb', 'xxyxx', 'uurcxstgmygtbstg', 'ieodomkazucvgmuy', 'xxxx']
|
||||
|
||||
|
||||
|
||||
function isNice(str: string) {
|
||||
// console.log("Looking at", str)
|
||||
let hasRepeat = false
|
||||
for (let i = 2; i < str.length; i++) {
|
||||
const currentLetter = str[i];
|
||||
const otherLetter = str[i - 2];
|
||||
if (currentLetter === otherLetter) {
|
||||
hasRepeat = true
|
||||
break
|
||||
}
|
||||
}
|
||||
if (!hasRepeat) {
|
||||
// console.log(str, 'has no repeat')
|
||||
return false
|
||||
}
|
||||
|
||||
for (let i = 0; i < str.length; i += 2) {
|
||||
const combo = str.substr(i, 2);
|
||||
if (str.includes(combo, i + 2)) {
|
||||
console.log(combo, str, 'is nice!')
|
||||
return true
|
||||
}
|
||||
}
|
||||
// console.log(str, 'has no pairs')
|
||||
|
||||
return false
|
||||
}
|
||||
|
||||
const filteredList = input.filter((it) => isNice(it))
|
||||
|
||||
|
||||
console.log(
|
||||
"Result:", filteredList.length
|
||||
)
|
Reference in New Issue
Block a user