Skip to content

Commit f5b4616

Browse files
committed
Day 1 - part 2 (incomplete)
1 parent 2f76f57 commit f5b4616

File tree

2 files changed

+27
-13
lines changed

2 files changed

+27
-13
lines changed

2024/day01/a.out

-38 KB
Binary file not shown.

2024/day01/solution.cpp

+27-13
Original file line numberDiff line numberDiff line change
@@ -44,22 +44,36 @@ int main() {
4444
int c1 = 1, c2 = 1, p1 = 0, p2 = 0;
4545
s = 0;
4646
while(p1 < a.size()) {
47-
while(a[p1+c1] == a[p1+c1-1]) {
48-
if(c1+1 >= a.size()) {
49-
break;
47+
t = 0;
48+
49+
// If both elements are equal
50+
if(a[p1] == b[p2]) {
51+
c1 = 1, c2 = 1;
52+
// Count how many equal elements there are in list a
53+
while(a[p1] == a[p1+c1] && c1 < a.size()) {
54+
c1 += 1;
55+
cout << "igual\n";
56+
cout << a[p1] << " " << a[p1+c1] << "\n";
5057
}
51-
c1 += 1;
52-
}
53-
while(b[p2+c2] == b[p2+c2-1]) {
54-
if(c2+1 >= b.size()) {
55-
break;
58+
// Count how many equal elements there are in list b
59+
while(b[p2] == b[p2+c2] && c2 < b.size() ) {
60+
c2 += 1;
5661
}
57-
c2 += 1;
62+
63+
cout << c1 << " " << c2 << "\n";
64+
t = a[p1]*c1;
65+
t *= c2;
66+
s += t;
67+
p1 += c1;
68+
p2 += c2;
69+
cout << t << "\n";
70+
}
71+
else if(a[p1] < b[p2]) {
72+
p1 += 1;
73+
}
74+
else if(a[p1] > b[p2]) {
75+
p2 += 1;
5876
}
59-
s += a[p1]*b[p2];
60-
p1 += c1;
61-
p2 += c2;
62-
cout << s << "\n";
6377
}
6478

6579
cout << s << "\n";

0 commit comments

Comments
 (0)