Compare commits
No commits in common. "012bf6099df7cf212a36989a4b17be910bb1945a" and "4f75e45108300575f1d7d4e09897c521725a26ae" have entirely different histories.
012bf6099d
...
4f75e45108
Binary file not shown.
@ -1,46 +0,0 @@
|
|||||||
#include <iostream>
|
|
||||||
#include <fstream>
|
|
||||||
#include <vector>
|
|
||||||
#include <algorithm>
|
|
||||||
#include <cmath>
|
|
||||||
#include <chrono>
|
|
||||||
|
|
||||||
int main() {
|
|
||||||
|
|
||||||
std::vector<int> x;
|
|
||||||
std::vector<int> y;
|
|
||||||
int l, r;
|
|
||||||
long t = 0;
|
|
||||||
long t2 = 0;
|
|
||||||
int c = 0;
|
|
||||||
|
|
||||||
std::chrono::steady_clock::time_point begin = std::chrono::steady_clock::now();
|
|
||||||
std::ifstream f("b");
|
|
||||||
while (f >> l >> r) {
|
|
||||||
x.push_back(l);
|
|
||||||
y.push_back(r);
|
|
||||||
}
|
|
||||||
|
|
||||||
std::sort(x.begin(), x.end());
|
|
||||||
std::sort(y.begin(), y.end());
|
|
||||||
|
|
||||||
for (size_t i = 0; i < 4000000; i++) {
|
|
||||||
t += std::abs(x[i] - y[i]);
|
|
||||||
}
|
|
||||||
|
|
||||||
auto p = y.begin();
|
|
||||||
for (size_t i = 0; i < 4000000; i++) {
|
|
||||||
auto b = std::lower_bound(p, y.end(), x[i]);
|
|
||||||
auto u = std::upper_bound(p, y.end(), x[i]);
|
|
||||||
int c = u - b;
|
|
||||||
t2 += x[i] * c;
|
|
||||||
p = b;
|
|
||||||
}
|
|
||||||
|
|
||||||
std::chrono::steady_clock::time_point end = std::chrono::steady_clock::now();
|
|
||||||
|
|
||||||
std::cout << "Part 1: " << t << "\nPart 2: " << t2 << "\n";
|
|
||||||
std::cout << "Time difference = " << std::chrono::duration_cast<std::chrono::microseconds>(end - begin).count() << " microseconds" << std::endl;
|
|
||||||
|
|
||||||
return 0;
|
|
||||||
}
|
|
1000
2024/day1bothparts/m
1000
2024/day1bothparts/m
File diff suppressed because it is too large
Load Diff
@ -1,8 +0,0 @@
|
|||||||
g++ sorter.cpp -o run
|
|
||||||
time ./run
|
|
||||||
time ./run | grep real
|
|
||||||
time ./run | grep real
|
|
||||||
time ./run | grep real
|
|
||||||
time ./run | grep real
|
|
||||||
time ./run | grep real
|
|
||||||
time ./run
|
|
@ -1,30 +0,0 @@
|
|||||||
#include <iostream>
|
|
||||||
#include <fstream>
|
|
||||||
#include <vector>
|
|
||||||
#include <algorithm>
|
|
||||||
#include <cmath>
|
|
||||||
|
|
||||||
int main() {
|
|
||||||
std::ifstream f("b");
|
|
||||||
|
|
||||||
std::vector<int> x;
|
|
||||||
std::vector<int> y;
|
|
||||||
int l, r;
|
|
||||||
|
|
||||||
while (f >> l >> r) {
|
|
||||||
x.push_back(l);
|
|
||||||
y.push_back(r);
|
|
||||||
}
|
|
||||||
|
|
||||||
std::sort(x.begin(), x.end());
|
|
||||||
std::sort(y.begin(), y.end());
|
|
||||||
|
|
||||||
long t = 0;
|
|
||||||
for (size_t i = 0; i < 4000000; i++) {
|
|
||||||
t += std::abs(x[i] - y[i]);
|
|
||||||
}
|
|
||||||
|
|
||||||
std::cout << t;
|
|
||||||
|
|
||||||
return 0;
|
|
||||||
}
|
|
@ -1,36 +0,0 @@
|
|||||||
#include <iostream>
|
|
||||||
#include <fstream>
|
|
||||||
#include <vector>
|
|
||||||
#include <algorithm>
|
|
||||||
#include <cmath>
|
|
||||||
|
|
||||||
int main() {
|
|
||||||
std::ifstream f("b");
|
|
||||||
|
|
||||||
std::vector<int> x;
|
|
||||||
std::vector<int> y;
|
|
||||||
int l, r;
|
|
||||||
|
|
||||||
while (f >> l >> r) {
|
|
||||||
x.push_back(l);
|
|
||||||
y.push_back(r);
|
|
||||||
}
|
|
||||||
|
|
||||||
std::sort(x.begin(), x.end());
|
|
||||||
std::sort(y.begin(), y.end());
|
|
||||||
|
|
||||||
long t = 0;
|
|
||||||
int c = 0;
|
|
||||||
auto p = y.begin();
|
|
||||||
for (size_t i = 0; i < 4000000; i++) {
|
|
||||||
auto b = std::lower_bound(p, y.end(), x[i]);
|
|
||||||
auto u = std::upper_bound(p, y.end(), x[i]);
|
|
||||||
int c = u - b;
|
|
||||||
t += x[i] * c;
|
|
||||||
p = b;
|
|
||||||
}
|
|
||||||
|
|
||||||
std::cout << t;
|
|
||||||
|
|
||||||
return 0;
|
|
||||||
}
|
|
Binary file not shown.
@ -1,6 +0,0 @@
|
|||||||
3 4
|
|
||||||
4 3
|
|
||||||
2 5
|
|
||||||
1 3
|
|
||||||
3 9
|
|
||||||
3 3
|
|
BIN
2024/day2/a.out
BIN
2024/day2/a.out
Binary file not shown.
1000
2024/day2/m
1000
2024/day2/m
File diff suppressed because it is too large
Load Diff
@ -1,81 +0,0 @@
|
|||||||
#include <iostream>
|
|
||||||
#include <fstream>
|
|
||||||
#include <sstream>
|
|
||||||
#include <vector>
|
|
||||||
#include <chrono>
|
|
||||||
|
|
||||||
int main() {
|
|
||||||
std::vector<std::vector<int>> matrix;
|
|
||||||
std::vector<std::string> safeness;
|
|
||||||
int total = 0;
|
|
||||||
int total2 = 0;
|
|
||||||
std::chrono::steady_clock::time_point begin = std::chrono::steady_clock::now();
|
|
||||||
|
|
||||||
std::ifstream file("m");
|
|
||||||
std::string line;
|
|
||||||
while (std::getline(file, line)) {
|
|
||||||
std::vector<int> row; // Vector to store each row's integers
|
|
||||||
std::stringstream ss(line); // Stringstream to split the line into integers
|
|
||||||
int num;
|
|
||||||
|
|
||||||
// Split the line by spaces and store each number in the row vector
|
|
||||||
while (ss >> num) {
|
|
||||||
row.push_back(num);
|
|
||||||
}
|
|
||||||
|
|
||||||
// Add the row to the 2D vector
|
|
||||||
matrix.push_back(row);
|
|
||||||
}
|
|
||||||
|
|
||||||
for (int row = 0; row < matrix.size(); row++) {
|
|
||||||
int direction = 0; // positive for increasing, negative for decreasing
|
|
||||||
int temp_total = 0;
|
|
||||||
int temp_total2 = 0;
|
|
||||||
for (int column = 0; column < matrix[row].size()-1; column++) {
|
|
||||||
int diff = matrix[row][column]-matrix[row][column+1];
|
|
||||||
if (diff < 0 && direction > 0) {
|
|
||||||
temp_total += 1;
|
|
||||||
}
|
|
||||||
else if (diff > 0 && direction < 0) {
|
|
||||||
temp_total += 1;
|
|
||||||
}
|
|
||||||
else if (diff == 0) {
|
|
||||||
temp_total += 1;
|
|
||||||
}
|
|
||||||
else if ((diff > 3) || (diff < -3)) {
|
|
||||||
temp_total += 1;
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
if ((matrix[row].size() - column+3) > 0) {
|
|
||||||
int diff2 = matrix[row][column]-matrix[row][column+2];
|
|
||||||
if (((diff2 < 0 && direction > 0) || (diff2 > 0 && direction < 0)) && ((diff < 0 && direction > 0) || (diff > 0 && direction < 0))) {
|
|
||||||
temp_total2 += 1;
|
|
||||||
}
|
|
||||||
else if (((diff2 > 3) || (diff2 < -3) || (diff2 == 0)) && ((diff > 3) || (diff < -3) || (diff == 0))){
|
|
||||||
temp_total2 += 1;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
if (temp_total > 1) {
|
|
||||||
temp_total = 1;
|
|
||||||
};
|
|
||||||
if (temp_total2 > 1) {
|
|
||||||
temp_total2 = 1;
|
|
||||||
};
|
|
||||||
direction = diff;
|
|
||||||
};
|
|
||||||
total += temp_total;
|
|
||||||
total2 += temp_total2;
|
|
||||||
};
|
|
||||||
|
|
||||||
total = matrix.size() - total;
|
|
||||||
total2 = matrix.size() - total2;
|
|
||||||
|
|
||||||
std::chrono::steady_clock::time_point end = std::chrono::steady_clock::now();
|
|
||||||
|
|
||||||
std::cout << "Part 1: " << total << "\nPart 2: " << total2 << "\n";
|
|
||||||
std::cout << "Time difference = " << std::chrono::duration_cast<std::chrono::microseconds>(end - begin).count() << " microseconds" << std::endl;
|
|
||||||
|
|
||||||
|
|
||||||
return 0;
|
|
||||||
};
|
|
@ -1,6 +0,0 @@
|
|||||||
7 6 4 2 1
|
|
||||||
1 2 7 8 9
|
|
||||||
9 7 6 2 1
|
|
||||||
1 3 2 4 5
|
|
||||||
8 6 4 4 1
|
|
||||||
1 3 6 7 9
|
|
Loading…
x
Reference in New Issue
Block a user