Skip to content

Commit 7264e41

Browse files
committed
Day 13 part 2 added
1 parent a8fca75 commit 7264e41

File tree

1 file changed

+21
-1
lines changed

1 file changed

+21
-1
lines changed

day_13/day_13.cpp

+21-1
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@
99
using namespace std;
1010

1111
const bool DEBUG=false;
12+
const bool DEBUG2=false;
1213

1314
bool compare(string l, string r){ //l<=r operation
1415
if(DEBUG) cout<<"comparing "<<l<<" <= "<<r<<endl;
@@ -129,6 +130,24 @@ void part_one(ifstream& inp_file, long int& ans){
129130
}
130131
}
131132

133+
void part_two(ifstream& inp_file, long int& ans){
134+
string s;
135+
136+
137+
string first_key="[[2]]";
138+
int first_key_pos=1;
139+
string second_key="[[6]]";
140+
int second_key_pos=2;
141+
while(getline(inp_file, s)){
142+
if(s.size()==0) continue;
143+
if(DEBUG2) cout<<s<<endl;
144+
if(!compare(first_key,s)) first_key_pos++;
145+
if(!compare(second_key,s)) second_key_pos++;
146+
if(DEBUG2) cout<<first_key_pos<<" * "<<second_key_pos<<endl;
147+
}
148+
ans=first_key_pos*second_key_pos;
149+
}
150+
132151
int main(int argc,char* argv[]){
133152

134153
if(argc>1){
@@ -143,7 +162,8 @@ int main(int argc,char* argv[]){
143162

144163
long int ans=0;
145164

146-
part_one(inp_file,ans);
165+
// part_one(inp_file,ans);
166+
part_two(inp_file,ans);
147167

148168

149169
if(DEBUG) cout<<"\n------------"<<endl;

0 commit comments

Comments
 (0)