diff --git a/day5/data/testInput.txt b/day5/data/testInput.txt new file mode 100644 index 0000000..b258f68 --- /dev/null +++ b/day5/data/testInput.txt @@ -0,0 +1,10 @@ +0,9 -> 5,9 +8,0 -> 0,8 +9,4 -> 3,4 +2,2 -> 2,1 +7,0 -> 7,4 +6,4 -> 2,0 +0,9 -> 2,9 +3,4 -> 1,4 +0,0 -> 8,8 +5,5 -> 8,2 diff --git a/day5/day5Part1 b/day5/day5Part1 new file mode 100755 index 0000000..7242d12 Binary files /dev/null and b/day5/day5Part1 differ diff --git a/day5/day5Part1.cpp b/day5/day5Part1.cpp new file mode 100644 index 0000000..659f05a --- /dev/null +++ b/day5/day5Part1.cpp @@ -0,0 +1,61 @@ +#include +#include +#include +using namespace std; + +int arrayDimension = 1000; +int inputLineCount = 500; +int main (void) +{ + int map[arrayDimension][arrayDimension] = {}; + string rawInput; + int x1[inputLineCount] = {}; + int x2[inputLineCount] = {}; + int y1[inputLineCount] = {}; + int y2[inputLineCount] = {}; + string comma = ","; + string arrow = " -> "; + int lineNumber = 0; + int overlapCount = 0; + ifstream readFile ("data/input.txt", ios::in); + + //Read file into arrays + while(getline(readFile, rawInput)) + { + size_t x1End = rawInput.find(comma); + x1[lineNumber] = stoi(rawInput.substr(0,x1End)); + size_t y1End = rawInput.find(arrow); + y1[lineNumber] = stoi(rawInput.substr(x1End+1,y1End)); + size_t x2End = rawInput.find(comma, y1End); + x2[lineNumber] = stoi(rawInput.substr(y1End+4,x2End)); + size_t y2End = rawInput.length()-1; + y2[lineNumber] = stoi(rawInput.substr(x2End+1,y2End)); + lineNumber++; + } + + for(int i=0;i1)overlapCount++; + } + } + + cout << overlapCount << endl; + + return 0; +} diff --git a/day5/day5Part2 b/day5/day5Part2 new file mode 100755 index 0000000..df94b25 Binary files /dev/null and b/day5/day5Part2 differ diff --git a/day5/day5Part2.cpp b/day5/day5Part2.cpp new file mode 100644 index 0000000..6bee011 --- /dev/null +++ b/day5/day5Part2.cpp @@ -0,0 +1,101 @@ +#include +#include +#include +using namespace std; + +int arrayDimension = 10;//1000; +int inputLineCount = 10;//500; +int main (void) +{ + int map[arrayDimension][arrayDimension] = {}; + string rawInput; + int x1[inputLineCount] = {}; + int x2[inputLineCount] = {}; + int y1[inputLineCount] = {}; + int y2[inputLineCount] = {}; + string comma = ","; + string arrow = " -> "; + int lineNumber = 0; + int overlapCount = 0; + ifstream readFile ("data/testInput.txt", ios::in); + + //Read file into arrays + while(getline(readFile, rawInput)) + { + size_t x1End = rawInput.find(comma); + x1[lineNumber] = stoi(rawInput.substr(0,x1End)); + size_t y1End = rawInput.find(arrow); + y1[lineNumber] = stoi(rawInput.substr(x1End+1,y1End)); + size_t x2End = rawInput.find(comma, y1End); + x2[lineNumber] = stoi(rawInput.substr(y1End+4,x2End)); + size_t y2End = rawInput.length()-1; + y2[lineNumber] = stoi(rawInput.substr(x2End+1,y2End)); + lineNumber++; + } + + for(int index=0;index1])overlapCount++; + } + cout << endl; + } + + cout << overlapCount << endl; + + return 0; +} diff --git a/day5/part2Instructions.txt b/day5/part2Instructions.txt new file mode 100644 index 0000000..eac5868 --- /dev/null +++ b/day5/part2Instructions.txt @@ -0,0 +1,23 @@ +Unfortunately, considering only horizontal and vertical lines doesn't give you the full picture; you need to also consider diagonal lines. + +Because of the limits of the hydrothermal vent mapping system, the lines in your list will only ever be horizontal, vertical, or a diagonal line at exactly 45 degrees. In other words: + + An entry like 1,1 -> 3,3 covers points 1,1, 2,2, and 3,3. + An entry like 9,7 -> 7,9 covers points 9,7, 8,8, and 7,9. + +Considering all lines from the above example would now produce the following diagram: + +1.1....11. +.111...2.. +..2.1.111. +...1.2.2.. +.112313211 +...1.2.... +..1...1... +.1.....1.. +1.......1. +222111.... + +You still need to determine the number of points where at least two lines overlap. In the above example, this is still anywhere in the diagram with a 2 or larger - now a total of 12 points. + +Consider all of the lines. At how many points do at least two lines overlap?