Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include "cleanUp.h"
- #include <iostream>
- using namespace std;
- class Position {
- public:
- int x = 0;
- int y = 0;
- string face = "N";
- };
- class Instruction {
- public:
- string direction;
- int distance;
- int intDistance;
- };
- void main() {
- vector <string> baseData = getInputFile("C://temp//AOC//day1Input.txt");
- vector <string> baseDataSplit = cstringsplit(baseData[0], ", ");
- vector <Instruction> InstructionSet;
- for (string C : baseDataSplit) {
- Instruction *instPtr = new Instruction;
- instPtr->distance = String2Int(C.substr(1));
- instPtr->direction = C.substr(0,1);
- InstructionSet.push_back(*instPtr);
- }
- Position myPos;
- for (Instruction Inst : InstructionSet) {
- if (Inst.direction == "R" && myPos.face == "N") { myPos.face = "E"; myPos.x = myPos.x + Inst.distance; }
- else if (Inst.direction == "R" && myPos.face == "E") { myPos.face = "S"; myPos.y = myPos.y - Inst.distance; }
- else if (Inst.direction == "R" && myPos.face == "S") { myPos.face = "W"; myPos.x = myPos.x - Inst.distance; }
- else if (Inst.direction == "R" && myPos.face == "W") { myPos.face = "N"; myPos.y = myPos.y + Inst.distance; }
- else if (Inst.direction == "L" && myPos.face == "N") { myPos.face = "W"; myPos.x = myPos.x - Inst.distance; }
- else if (Inst.direction == "L" && myPos.face == "E") { myPos.face = "N"; myPos.y = myPos.y + Inst.distance; }
- else if (Inst.direction == "L" && myPos.face == "S") { myPos.face = "E"; myPos.x = myPos.x + Inst.distance; }
- else if (Inst.direction == "L" && myPos.face == "W") { myPos.face = "S"; myPos.y = myPos.y - Inst.distance; }
- }
- cout << "X : " << myPos.x << " Y : " << myPos.y << " Total: " << myPos.x + myPos.y << endl;
- system("pause");
- }
Advertisement
Add Comment
Please, Sign In to add comment