Day 2, Part 1 complete; Part 2 start
This commit is contained in:
parent
ea4c7bb3f1
commit
22deef5120
4 changed files with 1068 additions and 0 deletions
1000
day2/data/input.txt
Normal file
1000
day2/data/input.txt
Normal file
File diff suppressed because it is too large
Load diff
BIN
day2/day2Part1
Executable file
BIN
day2/day2Part1
Executable file
Binary file not shown.
34
day2/day2Part1.cpp
Normal file
34
day2/day2Part1.cpp
Normal file
|
@ -0,0 +1,34 @@
|
||||||
|
#include <iostream>
|
||||||
|
#include <fstream>
|
||||||
|
using namespace std;
|
||||||
|
|
||||||
|
int main (void)
|
||||||
|
{
|
||||||
|
char direction[10];
|
||||||
|
int count = 0;
|
||||||
|
int totalForward = 0;
|
||||||
|
int totalVertical = 0;
|
||||||
|
int finalAnswer = 0;
|
||||||
|
ifstream readFile ("data/input.txt", ios::in);
|
||||||
|
|
||||||
|
while(readFile >> direction >> count)
|
||||||
|
{
|
||||||
|
switch (direction[0])
|
||||||
|
{
|
||||||
|
case 'f':
|
||||||
|
totalForward += count;
|
||||||
|
break;
|
||||||
|
case 'u':
|
||||||
|
totalVertical -= count;
|
||||||
|
break;
|
||||||
|
case 'd':
|
||||||
|
totalVertical += count;
|
||||||
|
break;
|
||||||
|
default:
|
||||||
|
cout << "Error!!!";
|
||||||
|
}
|
||||||
|
}
|
||||||
|
finalAnswer = totalVertical * totalForward;
|
||||||
|
cout << finalAnswer;
|
||||||
|
return 0;
|
||||||
|
}
|
34
day2/day2Part2.cpp
Normal file
34
day2/day2Part2.cpp
Normal file
|
@ -0,0 +1,34 @@
|
||||||
|
#include <iostream>
|
||||||
|
#include <fstream>
|
||||||
|
using namespace std;
|
||||||
|
|
||||||
|
int main (void)
|
||||||
|
{
|
||||||
|
char direction[10];
|
||||||
|
int count = 0;
|
||||||
|
int totalForward = 0;
|
||||||
|
int totalVertical = 0;
|
||||||
|
int finalAnswer = 0;
|
||||||
|
ifstream readFile ("data/input.txt", ios::in);
|
||||||
|
|
||||||
|
while(readFile >> direction >> count)
|
||||||
|
{
|
||||||
|
switch (direction[0])
|
||||||
|
{
|
||||||
|
case 'f':
|
||||||
|
totalForward += count;
|
||||||
|
break;
|
||||||
|
case 'u':
|
||||||
|
totalVertical -= count;
|
||||||
|
break;
|
||||||
|
case 'd':
|
||||||
|
totalVertical += count;
|
||||||
|
break;
|
||||||
|
default:
|
||||||
|
cout << "Error!!!";
|
||||||
|
}
|
||||||
|
}
|
||||||
|
finalAnswer = totalVertical * totalForward;
|
||||||
|
cout << finalAnswer;
|
||||||
|
return 0;
|
||||||
|
}
|
Loading…
Add table
Add a link
Reference in a new issue