Added older advents
This commit is contained in:
parent
8db2505049
commit
9cf858b860
78 changed files with 13807 additions and 0 deletions
1000
advent_of_code_2015/day5/input.in
Normal file
1000
advent_of_code_2015/day5/input.in
Normal file
File diff suppressed because it is too large
Load diff
59
advent_of_code_2015/day5/main1.cc
Normal file
59
advent_of_code_2015/day5/main1.cc
Normal file
|
|
@ -0,0 +1,59 @@
|
|||
#include <algorithm>
|
||||
#include <iostream>
|
||||
#include <string>
|
||||
|
||||
using namespace std;
|
||||
|
||||
bool has_forbidden(string const &str)
|
||||
{
|
||||
if (str.find("ab") != string::npos) return true;
|
||||
if (str.find("cd") != string::npos) return true;
|
||||
if (str.find("pq") != string::npos) return true;
|
||||
if (str.find("xy") != string::npos) return true;
|
||||
return false;
|
||||
}
|
||||
|
||||
bool has_repeating(string const &str)
|
||||
{
|
||||
for (size_t idx = 0; idx != str.size() - 1; ++idx)
|
||||
{
|
||||
if (str[idx] == str[idx + 1])
|
||||
return true;
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
bool vowels_ok(string const &str)
|
||||
{
|
||||
size_t vowels = 0;
|
||||
|
||||
vowels += count(str.begin(), str.end(), 'a');
|
||||
vowels += count(str.begin(), str.end(), 'e');
|
||||
vowels += count(str.begin(), str.end(), 'i');
|
||||
vowels += count(str.begin(), str.end(), 'o');
|
||||
vowels += count(str.begin(), str.end(), 'u');
|
||||
|
||||
return vowels >= 3;
|
||||
}
|
||||
|
||||
int main()
|
||||
{
|
||||
|
||||
string buffer;
|
||||
size_t count = 0;
|
||||
|
||||
while(getline(cin, buffer))
|
||||
{
|
||||
cout << "'" << buffer << "'\n";
|
||||
|
||||
if (vowels_ok(buffer)
|
||||
&& has_repeating(buffer)
|
||||
&& !has_forbidden(buffer))
|
||||
{
|
||||
++count;
|
||||
}
|
||||
}
|
||||
|
||||
cout << "Nice strings: " << count << "\n";
|
||||
}
|
||||
50
advent_of_code_2015/day5/main2.cc
Normal file
50
advent_of_code_2015/day5/main2.cc
Normal file
|
|
@ -0,0 +1,50 @@
|
|||
#include <algorithm>
|
||||
#include <iostream>
|
||||
#include <string>
|
||||
|
||||
using namespace std;
|
||||
|
||||
bool has_repeating_pair(string const &text)
|
||||
{
|
||||
for (size_t idx = 0; idx < text.size() - 2; ++idx)
|
||||
{
|
||||
if (text.find(text.substr(idx, 2), idx + 2) != string::npos)
|
||||
{
|
||||
cout << "'" << text << "' has repeating pair: '";
|
||||
cout << text.substr(idx, 2) << "'\n";
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
// cout << "'" << text << "' has no repeating pair\n";
|
||||
return false;
|
||||
}
|
||||
|
||||
bool repeats_plus_one(string const &text)
|
||||
{
|
||||
for (size_t idx = 0; idx < text.size() - 2; ++idx)
|
||||
{
|
||||
if (text[idx] == text[idx + 2])
|
||||
return true;
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
int main()
|
||||
{
|
||||
string buffer;
|
||||
size_t count = 0;
|
||||
|
||||
while (getline(cin, buffer))
|
||||
{
|
||||
if (has_repeating_pair(buffer)
|
||||
&& repeats_plus_one(buffer))
|
||||
{
|
||||
++count;
|
||||
}
|
||||
}
|
||||
|
||||
cout << "Nice strings: " << count << "\n";
|
||||
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue