diff --git a/03/ans2 b/03/ans2 new file mode 100755 index 0000000..dcef7ec Binary files /dev/null and b/03/ans2 differ diff --git a/03/answer b/03/answer index 86fc302..a126e61 100755 Binary files a/03/answer and b/03/answer differ diff --git a/03/p2_solution.cpp b/03/p2_solution.cpp new file mode 100644 index 0000000..0712289 --- /dev/null +++ b/03/p2_solution.cpp @@ -0,0 +1,62 @@ +#include +#include +#include +#include +#include +using namespace std; + + +int intoPriority(char ch) +{ + int initalP = ch; + if (initalP < 97) + { + initalP -= 38; + } else {initalP -= 96;} + return initalP; +} + + +int main() +{ + string inputStr; + ifstream inputFile("input.txt"); + + int i {0}; + // This will be reset every 3 lines + map itemCounts; + int badgePrioity {0}; + while (getline(inputFile, inputStr)) + { + i++; + // These are the items we've seen this line + vector seenVec; + // Increment the item counter for each item not already seen in this line + for (char c: inputStr) + { + // Check that we haven't already seen this char + if (find(seenVec.begin(), seenVec.end(), c) != seenVec.end()) {continue;} + seenVec.push_back(c); + itemCounts[c]++; + } + + // If this is the 3rd line we need to check for the badge and reset itemCounts + if (i%3==0) + { + map::iterator itr; + // Look through the map for something that occured three times + for (itr = itemCounts.begin(); itr != itemCounts.end(); itr++) + { + if (itr->second == 3) + { + // Add that items value to our total + badgePrioity += intoPriority(itr->first); + } + } + // Erase everything in the count map as we're now in a new group + itemCounts.clear(); + } + } + cout << badgePrioity << endl; + +} \ No newline at end of file diff --git a/03/solution.cpp b/03/solution.cpp index 530de75..cb39bce 100644 --- a/03/solution.cpp +++ b/03/solution.cpp @@ -14,29 +14,6 @@ int intoPriority(char ch) return initalP; } -class CharCount -{ - char key; - int count; -}; - - -class CharCounter -{ - vector cc; - -public: - int insert(char ch) - { - // This is terrible, DO NOT COMMIT - for (int i {0}; i < 26; i++) - { - CharCount charCount = this.cc[i]; - } - } -}; - - class RuckSack { @@ -89,19 +66,9 @@ int main() int groupPrioritySum {0}; - - set groupBTree; - int i {0}; while (getline(inputFile, inputStr)) { - i++; - if (i % 3 == 0) - set groupBTree; - for (char c : inputStr) - { - - } RuckSack curRuckSack {RuckSack(inputStr)}; cout << curRuckSack.aString() << "\t\t\t" << curRuckSack.bString() << endl;