Answers for day 3

master
Griffiths Lott 3 years ago
parent 201f5d28f6
commit 1f87f1bbde
  1. BIN
      03/ans2
  2. BIN
      03/answer
  3. 62
      03/p2_solution.cpp
  4. 33
      03/solution.cpp

Binary file not shown.

Binary file not shown.

@ -0,0 +1,62 @@
#include <iostream>
#include <fstream>
#include <map>
#include <vector>
#include <algorithm>
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<char,int> itemCounts;
int badgePrioity {0};
while (getline(inputFile, inputStr))
{
i++;
// These are the items we've seen this line
vector<char> 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<char, int>::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;
}

@ -14,29 +14,6 @@ int intoPriority(char ch)
return initalP;
}
class CharCount
{
char key;
int count;
};
class CharCounter
{
vector<CharCount> 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<BTreeNode> groupBTree;
int i {0};
while (getline(inputFile, inputStr))
{
i++;
if (i % 3 == 0)
set<BTreeNode> groupBTree;
for (char c : inputStr)
{
}
RuckSack curRuckSack {RuckSack(inputStr)};
cout << curRuckSack.aString() << "\t\t\t" << curRuckSack.bString() << endl;

Loading…
Cancel
Save