Skip to content

Commit

Permalink
Solution for 2015 Day 5 part 1 (C++)
Browse files Browse the repository at this point in the history
Signed-off-by: Sebastian Lukas <[email protected]>
  • Loading branch information
SebaLukas committed Jan 25, 2023
1 parent 95ff019 commit c94afb6
Show file tree
Hide file tree
Showing 2 changed files with 1,078 additions and 0 deletions.
78 changes: 78 additions & 0 deletions 2015/Day5/day5.cpp
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();

}
Loading

0 comments on commit c94afb6

Please sign in to comment.