-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Solution for 2015 Day 5 part 1 (C++)
Signed-off-by: Sebastian Lukas <[email protected]>
- Loading branch information
Showing
2 changed files
with
1,078 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,78 @@ | ||
#include <iostream> | ||
#include <fstream> | ||
#include <string> | ||
#include <algorithm> | ||
#include <vector> | ||
|
||
const std::vector<std::string> disallowed{"ab", "cd", "pq", "xy"}; | ||
const std::vector<char> vowels{'a', 'e', 'i', 'o', 'u'}; | ||
|
||
bool found_three_vowels(std::string line) { | ||
int found_vowels = 0; | ||
std::string::size_type start_pos = 0; | ||
for (char vowel : vowels) { | ||
while (std::string::npos != (start_pos = line.find(vowel, start_pos))) { | ||
++start_pos; | ||
found_vowels++; | ||
} | ||
start_pos = 0; | ||
} | ||
|
||
if (found_vowels >= 3) { | ||
return true; | ||
} else { | ||
return false; | ||
} | ||
} | ||
|
||
bool found_naughty_word(std::string line) { | ||
for (std::string dis : disallowed) { | ||
if (std::string::npos != line.find(dis)) { | ||
return true; | ||
} | ||
} | ||
return false; | ||
} | ||
|
||
bool found_letter_double(std::string line) { | ||
for (std::string::size_type i = 1; i < line.size(); i++) { | ||
if (line[i-1] == line[i]) { | ||
return true; | ||
} | ||
} | ||
return false; | ||
|
||
} | ||
|
||
void part1() { | ||
std::ifstream input {"input.txt"}; | ||
std::string line; | ||
int nice_strings = 0; | ||
|
||
if (input.good()) { | ||
while (input >> line) { | ||
|
||
if (found_letter_double(line) == false) { | ||
// std::cout << "Double letter not found!\n"; | ||
continue; | ||
} | ||
|
||
if (found_three_vowels(line) == false) { | ||
// std::cout << "Vowels not found!"; | ||
continue; | ||
} | ||
|
||
if (found_naughty_word(line)) { | ||
continue; | ||
} | ||
nice_strings++; | ||
} | ||
} | ||
std::cout << "Nice Strings: " << nice_strings << "\n"; | ||
} | ||
|
||
int main() { | ||
|
||
part1(); | ||
|
||
} |
Oops, something went wrong.