diff options
author | kaiwu <kaiwu2004@gmail.com> | 2022-03-16 11:48:19 +0800 |
---|---|---|
committer | kaiwu <kaiwu2004@gmail.com> | 2022-03-16 11:48:19 +0800 |
commit | 6aa919cbe332d7e45c0c3a7954d48166f4b774c0 (patch) | |
tree | a02239ddb071c554448d9cb5f3cc19d9235cb12f /src/2015/day5/aoc.cpp | |
parent | 480dfe85d94d703e10728f6a46cf05ee99ea08f8 (diff) | |
download | advent-of-code-6aa919cbe332d7e45c0c3a7954d48166f4b774c0.tar.gz advent-of-code-6aa919cbe332d7e45c0c3a7954d48166f4b774c0.zip |
strstr
Diffstat (limited to 'src/2015/day5/aoc.cpp')
-rw-r--r-- | src/2015/day5/aoc.cpp | 35 |
1 files changed, 35 insertions, 0 deletions
diff --git a/src/2015/day5/aoc.cpp b/src/2015/day5/aoc.cpp index 1c33c66..d3f310b 100644 --- a/src/2015/day5/aoc.cpp +++ b/src/2015/day5/aoc.cpp @@ -1,5 +1,40 @@ #include "aoc.h" +#include <algorithm> namespace aoc2015 { +int count_vowels(line_view lv, const char* vowels) { + ascii_count ac{lv}; + int total = 0; + per_char(vowels, [&ac, &total](char c) { + total += ac[c]; + return true; + }); + return total; } + +bool is_nice(line_view lv, int repeated) { + const char* p = lv.line; + while (p + repeated < lv.line + lv.length) { + if (is_repeated(p, p + repeated)) { + return true; + } else { + p++; + } + } + return false; +} + +bool is_nice(line_view lv, const char* disallowed[]) { + size_t size = sizeof(disallowed) / sizeof(*disallowed); + if (std::any_of(disallowed, disallowed + size, [&lv](const char* s) -> bool { return lv.contains(s); })) { + return false; + } + return true; +} + +/* +int day5(line_view) {} +*/ + +} // namespace aoc2015 |