-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathDay3.cpp
More file actions
54 lines (48 loc) · 898 Bytes
/
Copy pathDay3.cpp
File metadata and controls
54 lines (48 loc) · 898 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
#include <iostream>
#include <fstream>
#include <vector>
using namespace std;
int tree(vector<string> v,int a,int b)
{
int x = 0;
int y;
int h = 322;
int count = 0;
for(y=0;y<323;y=y+b)
{
if (v[y][x] =='#')
{
x=((x+a)%31);
count++;
}
else{
x=((x+a)%31);
}
}
return count;
}
int main()
{
ifstream indata;
string p;
indata.open("day3data");
if(indata.fail())
{
cout<<"something is wrong"<<endl;
}
vector<string> v;
while(indata>>p)
{
v.push_back(p);
}
int t1=tree(v,1,1);
int t2=tree(v,3,1);
int t3 = tree(v, 5, 1);
int t4 = tree(v, 7, 1);
int t5 = tree(v, 1, 2);
//PART1
cout<<t2<<endl;
//PART2
cout<<(t1*t2*t3*t4*t5)<<endl;//multiply all the values
return 0;
}