2015/5
This commit is contained in:
37
src/2015/5/1/index.ts
Normal file
37
src/2015/5/1/index.ts
Normal file
@@ -0,0 +1,37 @@
|
||||
export default async function runner(inputPath: string){
|
||||
const input = await Bun.file(inputPath).text();
|
||||
|
||||
let nice = 0;
|
||||
|
||||
["aa", "bb", "cc", "dd", "ee", "ff", "gg", "hh", "ii", "jj"]
|
||||
|
||||
input.split("\n").forEach(line => {
|
||||
if(line.trim() === "") return;
|
||||
if(_countVowels(line)<3) {
|
||||
return;
|
||||
}
|
||||
if(line.indexOf("ab") !== -1) return;
|
||||
if(line.indexOf("cd") !== -1) return;
|
||||
if(line.indexOf("pq") !== -1) return;
|
||||
if(line.indexOf("xy") !== -1) return;
|
||||
if(!_hasDouble(line)) return;
|
||||
nice++;
|
||||
return;
|
||||
}
|
||||
)
|
||||
console.log(nice)
|
||||
}
|
||||
|
||||
function _countVowels(string: string){
|
||||
return string.split('').filter(value => 'aeiou'.indexOf(value)!==-1).length
|
||||
}
|
||||
|
||||
function _hasDouble(string: string) {
|
||||
let ret = false;
|
||||
string.split('').forEach((value, index, array) => {
|
||||
if(array[index+1] === value) {
|
||||
ret = true;
|
||||
}
|
||||
})
|
||||
return ret;
|
||||
}
|
||||
38
src/2015/5/2/index.ts
Normal file
38
src/2015/5/2/index.ts
Normal file
@@ -0,0 +1,38 @@
|
||||
export default async function runner(inputPath: string){
|
||||
const input = await Bun.file(inputPath).text();
|
||||
|
||||
let nice = 0;
|
||||
|
||||
["aa", "bb", "cc", "dd", "ee", "ff", "gg", "hh", "ii", "jj"]
|
||||
|
||||
input.split("\n").forEach(line => {
|
||||
if(line.trim() === "") return;
|
||||
if(!_hasDoubleWithGap(line)) return;
|
||||
if(!_hasDoublePair(line)) return;
|
||||
nice++;
|
||||
return;
|
||||
}
|
||||
)
|
||||
console.log(nice)
|
||||
}
|
||||
|
||||
function _hasDoublePair(string: string){
|
||||
let ret = false;
|
||||
|
||||
string.split('').forEach((value, index, array) => {
|
||||
const search = `${value}${array[index+1]}`
|
||||
if(string.substring(index+2).indexOf(search) !== -1) ret = true;
|
||||
})
|
||||
|
||||
return ret;
|
||||
}
|
||||
|
||||
function _hasDoubleWithGap(string: string) {
|
||||
let ret = false;
|
||||
string.split('').forEach((value, index, array) => {
|
||||
if(array[index+2] === value) {
|
||||
ret = true;
|
||||
}
|
||||
})
|
||||
return ret;
|
||||
}
|
||||
Reference in New Issue
Block a user