wheelsmanx

AOC DAY 1 PART 1 Source.cpp

May 8th, 2017
82
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.70 KB | None | 0 0
  1. #include "cleanUp.h"
  2. #include <iostream>
  3.  
  4. using namespace std;
  5.  
  6. class Position {
  7. public:
  8. int x = 0;
  9. int y = 0;
  10. string face = "N";
  11. };
  12.  
  13. class Instruction {
  14. public:
  15. string direction;
  16. int distance;
  17. int intDistance;
  18. };
  19.  
  20. void main() {
  21. vector <string> baseData = getInputFile("C://temp//AOC//day1Input.txt");
  22. vector <string> baseDataSplit = cstringsplit(baseData[0], ", ");
  23. vector <Instruction> InstructionSet;
  24. for (string C : baseDataSplit) {
  25. Instruction *instPtr = new Instruction;
  26. instPtr->distance = String2Int(C.substr(1));
  27. instPtr->direction = C.substr(0,1);
  28. InstructionSet.push_back(*instPtr);
  29. }
  30. Position myPos;
  31. for (Instruction Inst : InstructionSet) {
  32. if (Inst.direction == "R" && myPos.face == "N") { myPos.face = "E"; myPos.x = myPos.x + Inst.distance; }
  33. else if (Inst.direction == "R" && myPos.face == "E") { myPos.face = "S"; myPos.y = myPos.y - Inst.distance; }
  34. else if (Inst.direction == "R" && myPos.face == "S") { myPos.face = "W"; myPos.x = myPos.x - Inst.distance; }
  35. else if (Inst.direction == "R" && myPos.face == "W") { myPos.face = "N"; myPos.y = myPos.y + Inst.distance; }
  36. else if (Inst.direction == "L" && myPos.face == "N") { myPos.face = "W"; myPos.x = myPos.x - Inst.distance; }
  37. else if (Inst.direction == "L" && myPos.face == "E") { myPos.face = "N"; myPos.y = myPos.y + Inst.distance; }
  38. else if (Inst.direction == "L" && myPos.face == "S") { myPos.face = "E"; myPos.x = myPos.x + Inst.distance; }
  39. else if (Inst.direction == "L" && myPos.face == "W") { myPos.face = "S"; myPos.y = myPos.y - Inst.distance; }
  40. }
  41.  
  42. cout << "X : " << myPos.x << " Y : " << myPos.y << " Total: " << myPos.x + myPos.y << endl;
  43.  
  44.  
  45. system("pause");
  46. }
Advertisement
Add Comment
Please, Sign In to add comment