Signed-off-by: Avior <f.bouillon@aptatio.com>
This commit is contained in:
2022-11-24 11:55:20 +01:00
parent 1060cb8a09
commit 5349c91116
7 changed files with 1352 additions and 0 deletions

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
View 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
View 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
)