Compare commits
6 Commits
justi
...
b2272ba0dd
| Author | SHA1 | Date | |
|---|---|---|---|
| b2272ba0dd | |||
| a03473f567 | |||
| 78e28f6959 | |||
| 63db42f55a | |||
| cef11b36ff | |||
| 95db0b1fa8 |
@@ -0,0 +1,2 @@
|
|||||||
|
*/**
|
||||||
|
!*/*.cpp
|
||||||
@@ -0,0 +1,25 @@
|
|||||||
|
#include <iostream>
|
||||||
|
#include <string>
|
||||||
|
|
||||||
|
int main(int argc, char* argv[])
|
||||||
|
{
|
||||||
|
std::string line;
|
||||||
|
int total = 0;
|
||||||
|
int max = 0;
|
||||||
|
while(std::getline(std::cin, line))
|
||||||
|
{
|
||||||
|
if (0 == line.size())
|
||||||
|
{
|
||||||
|
if (total > max)
|
||||||
|
{
|
||||||
|
max = total;
|
||||||
|
}
|
||||||
|
total = 0;
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
total += stoi(line);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
std::cout << max << std::endl;
|
||||||
|
}
|
||||||
@@ -0,0 +1,26 @@
|
|||||||
|
#include <iostream>
|
||||||
|
#include <string>
|
||||||
|
#include <vector>
|
||||||
|
#include <algorithm>
|
||||||
|
|
||||||
|
int main(int argc, char* argv[])
|
||||||
|
{
|
||||||
|
std::string line;
|
||||||
|
int total = 0;
|
||||||
|
std::vector<int> sums;
|
||||||
|
while(std::getline(std::cin, line))
|
||||||
|
{
|
||||||
|
if (0 == line.size())
|
||||||
|
{
|
||||||
|
sums.push_back(total);
|
||||||
|
total = 0;
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
total += stoi(line);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
std::sort(sums.begin(), sums.end(), std::greater<>());
|
||||||
|
std::cout << sums[0] + sums[1] + sums[2] << std::endl;
|
||||||
|
}
|
||||||
@@ -0,0 +1,20 @@
|
|||||||
|
#include <iostream>
|
||||||
|
#include <string>
|
||||||
|
#include <algorithm>
|
||||||
|
|
||||||
|
using namespace std;
|
||||||
|
|
||||||
|
string plays[] = {"A X", "A Y", "A Z", "B X", "B Y", "B Z", "C X", "C Y", "C Z"};
|
||||||
|
int play_scores[] = {1 + 3, 2 + 6, 3 + 0, 1 + 0, 2 + 3, 3 + 6, 1 + 6, 2 + 0, 3 + 3};
|
||||||
|
|
||||||
|
int main(int argc, char* argv[])
|
||||||
|
{
|
||||||
|
int total_score = 0;
|
||||||
|
string line;
|
||||||
|
while(getline(cin, line))
|
||||||
|
{
|
||||||
|
int i = find(&plays[0], &plays[9], line)-&plays[0];
|
||||||
|
total_score += play_scores[i];
|
||||||
|
}
|
||||||
|
cout << total_score << endl;
|
||||||
|
}
|
||||||
@@ -0,0 +1,20 @@
|
|||||||
|
#include <iostream>
|
||||||
|
#include <string>
|
||||||
|
#include <algorithm>
|
||||||
|
|
||||||
|
using namespace std;
|
||||||
|
|
||||||
|
string plays[] = {"A X", "A Y", "A Z", "B X", "B Y", "B Z", "C X", "C Y", "C Z"};
|
||||||
|
int play_scores[] = {3 + 0, 1 + 3, 2 + 6, 1 + 0, 2 + 3, 3 + 6, 2 + 0, 3 + 3, 1 + 6};
|
||||||
|
|
||||||
|
int main(int argc, char* argv[])
|
||||||
|
{
|
||||||
|
int total_score = 0;
|
||||||
|
string line;
|
||||||
|
while(getline(cin, line))
|
||||||
|
{
|
||||||
|
int i = find(&plays[0], &plays[9], line)-&plays[0];
|
||||||
|
total_score += play_scores[i];
|
||||||
|
}
|
||||||
|
cout << total_score << endl;
|
||||||
|
}
|
||||||
@@ -0,0 +1,36 @@
|
|||||||
|
#include <iostream>
|
||||||
|
#include <string>
|
||||||
|
#include <algorithm>
|
||||||
|
|
||||||
|
using namespace std;
|
||||||
|
|
||||||
|
int main(int argc, char* argv[])
|
||||||
|
{
|
||||||
|
int total = 0;
|
||||||
|
|
||||||
|
string line;
|
||||||
|
while(getline(cin, line))
|
||||||
|
{
|
||||||
|
string half1 = line.substr(0, line.size()/2);
|
||||||
|
string half2 = line.substr(line.size()/2);
|
||||||
|
|
||||||
|
sort(half1.begin(), half1.end());
|
||||||
|
sort(half2.begin(), half2.end());
|
||||||
|
|
||||||
|
string remaining;
|
||||||
|
set_intersection(half1.begin(), half1.end(), half2.begin(), half2.end(), back_inserter(remaining));
|
||||||
|
|
||||||
|
int value;
|
||||||
|
if (remaining[0] >= 'a')
|
||||||
|
{
|
||||||
|
value = remaining[0]-'a'+1;
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
value = remaining[0]-'A'+27;
|
||||||
|
}
|
||||||
|
|
||||||
|
total += value;
|
||||||
|
}
|
||||||
|
cout << total << endl;
|
||||||
|
}
|
||||||
@@ -0,0 +1,38 @@
|
|||||||
|
#include <iostream>
|
||||||
|
#include <string>
|
||||||
|
#include <algorithm>
|
||||||
|
|
||||||
|
using namespace std;
|
||||||
|
|
||||||
|
int main(int argc, char* argv[])
|
||||||
|
{
|
||||||
|
int total = 0;
|
||||||
|
|
||||||
|
string line1,line2,line3;
|
||||||
|
while(getline(cin, line1))
|
||||||
|
{
|
||||||
|
getline(cin, line2);
|
||||||
|
getline(cin, line3);
|
||||||
|
|
||||||
|
sort(line1.begin(), line1.end());
|
||||||
|
sort(line2.begin(), line2.end());
|
||||||
|
sort(line3.begin(), line3.end());
|
||||||
|
|
||||||
|
string first_intersection, second_intersection;
|
||||||
|
set_intersection(line1.begin(), line1.end(), line2.begin(), line2.end(), back_inserter(first_intersection));
|
||||||
|
set_intersection(first_intersection.begin(), first_intersection.end(), line3.begin(), line3.end(), back_inserter(second_intersection));
|
||||||
|
|
||||||
|
int value;
|
||||||
|
if (second_intersection[0] >= 'a')
|
||||||
|
{
|
||||||
|
value = second_intersection[0]-'a'+1;
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
value = second_intersection[0]-'A'+27;
|
||||||
|
}
|
||||||
|
|
||||||
|
total += value;
|
||||||
|
}
|
||||||
|
cout << total << endl;
|
||||||
|
}
|
||||||
@@ -0,0 +1,33 @@
|
|||||||
|
#include <iostream>
|
||||||
|
#include <string>
|
||||||
|
#include <algorithm>
|
||||||
|
|
||||||
|
using namespace std;
|
||||||
|
|
||||||
|
int main(int argc, char* argv[])
|
||||||
|
{
|
||||||
|
int total = 0;
|
||||||
|
|
||||||
|
string line;
|
||||||
|
while(getline(cin, line))
|
||||||
|
{
|
||||||
|
string::size_type n = line.find(',');
|
||||||
|
string half1 = line.substr(0,n);
|
||||||
|
string half2 = line.substr(n+1);
|
||||||
|
|
||||||
|
n = half1.find('-');
|
||||||
|
int half1_start = stoi(half1.substr(0,n));
|
||||||
|
int half1_end = stoi(half1.substr(n+1));
|
||||||
|
|
||||||
|
n = half2.find('-');
|
||||||
|
int half2_start = stoi(half2.substr(0,n));
|
||||||
|
int half2_end = stoi(half2.substr(n+1));
|
||||||
|
|
||||||
|
if ((half1_start <= half2_start && half1_end >= half2_end) ||
|
||||||
|
(half2_start <= half1_start && half2_end >= half1_end))
|
||||||
|
{
|
||||||
|
total++;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
cout << total << endl;
|
||||||
|
}
|
||||||
@@ -0,0 +1,32 @@
|
|||||||
|
#include <iostream>
|
||||||
|
#include <string>
|
||||||
|
#include <algorithm>
|
||||||
|
|
||||||
|
using namespace std;
|
||||||
|
|
||||||
|
int main(int argc, char* argv[])
|
||||||
|
{
|
||||||
|
int total = 0;
|
||||||
|
|
||||||
|
string line;
|
||||||
|
while(getline(cin, line))
|
||||||
|
{
|
||||||
|
string::size_type n = line.find(',');
|
||||||
|
string half1 = line.substr(0,n);
|
||||||
|
string half2 = line.substr(n+1);
|
||||||
|
|
||||||
|
n = half1.find('-');
|
||||||
|
int half1_start = stoi(half1.substr(0,n));
|
||||||
|
int half1_end = stoi(half1.substr(n+1));
|
||||||
|
|
||||||
|
n = half2.find('-');
|
||||||
|
int half2_start = stoi(half2.substr(0,n));
|
||||||
|
int half2_end = stoi(half2.substr(n+1));
|
||||||
|
|
||||||
|
if (!(half1_end < half2_start || half2_end < half1_start))
|
||||||
|
{
|
||||||
|
total++;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
cout << total << endl;
|
||||||
|
}
|
||||||
@@ -0,0 +1,91 @@
|
|||||||
|
#include <iostream>
|
||||||
|
#include <string>
|
||||||
|
#include <unordered_map>
|
||||||
|
#include <vector>
|
||||||
|
#include <algorithm>
|
||||||
|
|
||||||
|
using namespace std;
|
||||||
|
|
||||||
|
int main(int argc, char* argv[])
|
||||||
|
{
|
||||||
|
bool instruction_mode = false;
|
||||||
|
string line;
|
||||||
|
unordered_map<int, string> stacks;
|
||||||
|
|
||||||
|
struct Instruction
|
||||||
|
{
|
||||||
|
int quantity;
|
||||||
|
int from;
|
||||||
|
int to;
|
||||||
|
};
|
||||||
|
|
||||||
|
vector<Instruction> instructions;
|
||||||
|
|
||||||
|
int stack_max = 0;
|
||||||
|
|
||||||
|
while (getline(cin, line))
|
||||||
|
{
|
||||||
|
if (0 == line.size())
|
||||||
|
{
|
||||||
|
instruction_mode = true;
|
||||||
|
|
||||||
|
for (auto &it : stacks)
|
||||||
|
{
|
||||||
|
it.second = it.second.substr(0, it.second.size()-1);
|
||||||
|
}
|
||||||
|
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (instruction_mode)
|
||||||
|
{
|
||||||
|
Instruction instruction;
|
||||||
|
line = line.substr(5);
|
||||||
|
string::size_type n = line.find(' ');
|
||||||
|
instruction.quantity = stoi(line.substr(0,n));
|
||||||
|
line = line.substr(n+6);
|
||||||
|
n = line.find(' ');
|
||||||
|
instruction.from = stoi(line.substr(0,n));
|
||||||
|
line = line.substr(n+4);
|
||||||
|
instruction.to = stoi(line);
|
||||||
|
|
||||||
|
instructions.push_back(instruction);
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
for (int i = 1, s = 1; i < line.size(); i+=4, s++)
|
||||||
|
{
|
||||||
|
if (line[i] == ' ')
|
||||||
|
{
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (!stacks.contains(s))
|
||||||
|
{
|
||||||
|
stacks[s] = "";
|
||||||
|
}
|
||||||
|
|
||||||
|
stacks[s] += line[i];
|
||||||
|
|
||||||
|
if (s > stack_max)
|
||||||
|
{
|
||||||
|
stack_max = s;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
for (unsigned int i = 0; i < instructions.size(); i++)
|
||||||
|
{
|
||||||
|
string taken = stacks[instructions[i].from].substr(0, instructions[i].quantity);
|
||||||
|
reverse(taken.begin(), taken.end());
|
||||||
|
stacks[instructions[i].from] = stacks[instructions[i].from].substr(instructions[i].quantity);
|
||||||
|
stacks[instructions[i].to] = taken + stacks[instructions[i].to];
|
||||||
|
}
|
||||||
|
|
||||||
|
for(int s = 1; s <= stack_max; s++)
|
||||||
|
{
|
||||||
|
cout << stacks[s][0];
|
||||||
|
}
|
||||||
|
cout << endl;
|
||||||
|
}
|
||||||
@@ -0,0 +1,90 @@
|
|||||||
|
#include <iostream>
|
||||||
|
#include <string>
|
||||||
|
#include <unordered_map>
|
||||||
|
#include <vector>
|
||||||
|
#include <algorithm>
|
||||||
|
|
||||||
|
using namespace std;
|
||||||
|
|
||||||
|
int main(int argc, char* argv[])
|
||||||
|
{
|
||||||
|
bool instruction_mode = false;
|
||||||
|
string line;
|
||||||
|
unordered_map<int, string> stacks;
|
||||||
|
|
||||||
|
struct Instruction
|
||||||
|
{
|
||||||
|
int quantity;
|
||||||
|
int from;
|
||||||
|
int to;
|
||||||
|
};
|
||||||
|
|
||||||
|
vector<Instruction> instructions;
|
||||||
|
|
||||||
|
int stack_max = 0;
|
||||||
|
|
||||||
|
while (getline(cin, line))
|
||||||
|
{
|
||||||
|
if (0 == line.size())
|
||||||
|
{
|
||||||
|
instruction_mode = true;
|
||||||
|
|
||||||
|
for (auto &it : stacks)
|
||||||
|
{
|
||||||
|
it.second = it.second.substr(0, it.second.size()-1);
|
||||||
|
}
|
||||||
|
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (instruction_mode)
|
||||||
|
{
|
||||||
|
Instruction instruction;
|
||||||
|
line = line.substr(5);
|
||||||
|
string::size_type n = line.find(' ');
|
||||||
|
instruction.quantity = stoi(line.substr(0,n));
|
||||||
|
line = line.substr(n+6);
|
||||||
|
n = line.find(' ');
|
||||||
|
instruction.from = stoi(line.substr(0,n));
|
||||||
|
line = line.substr(n+4);
|
||||||
|
instruction.to = stoi(line);
|
||||||
|
|
||||||
|
instructions.push_back(instruction);
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
for (int i = 1, s = 1; i < line.size(); i+=4, s++)
|
||||||
|
{
|
||||||
|
if (line[i] == ' ')
|
||||||
|
{
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (!stacks.contains(s))
|
||||||
|
{
|
||||||
|
stacks[s] = "";
|
||||||
|
}
|
||||||
|
|
||||||
|
stacks[s] += line[i];
|
||||||
|
|
||||||
|
if (s > stack_max)
|
||||||
|
{
|
||||||
|
stack_max = s;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
for (unsigned int i = 0; i < instructions.size(); i++)
|
||||||
|
{
|
||||||
|
string taken = stacks[instructions[i].from].substr(0, instructions[i].quantity);
|
||||||
|
stacks[instructions[i].from] = stacks[instructions[i].from].substr(instructions[i].quantity);
|
||||||
|
stacks[instructions[i].to] = taken + stacks[instructions[i].to];
|
||||||
|
}
|
||||||
|
|
||||||
|
for(int s = 1; s <= stack_max; s++)
|
||||||
|
{
|
||||||
|
cout << stacks[s][0];
|
||||||
|
}
|
||||||
|
cout << endl;
|
||||||
|
}
|
||||||
@@ -0,0 +1,22 @@
|
|||||||
|
#include <iostream>
|
||||||
|
#include <string>
|
||||||
|
#include <algorithm>
|
||||||
|
|
||||||
|
using namespace std;
|
||||||
|
|
||||||
|
int main(int argc, char* argv[])
|
||||||
|
{
|
||||||
|
string signal;
|
||||||
|
cin >> signal;
|
||||||
|
|
||||||
|
for (int i = 0; i < signal.size()-4; i++)
|
||||||
|
{
|
||||||
|
string segment = signal.substr(i,4);
|
||||||
|
sort(segment.begin(), segment.end());
|
||||||
|
if (segment.end() == std::unique(segment.begin(), segment.end()))
|
||||||
|
{
|
||||||
|
cout << i+4 << endl;
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,22 @@
|
|||||||
|
#include <iostream>
|
||||||
|
#include <string>
|
||||||
|
#include <algorithm>
|
||||||
|
|
||||||
|
using namespace std;
|
||||||
|
|
||||||
|
int main(int argc, char* argv[])
|
||||||
|
{
|
||||||
|
string signal;
|
||||||
|
cin >> signal;
|
||||||
|
|
||||||
|
for (int i = 0; i < signal.size()-14; i++)
|
||||||
|
{
|
||||||
|
string segment = signal.substr(i,14);
|
||||||
|
sort(segment.begin(), segment.end());
|
||||||
|
if (segment.end() == std::unique(segment.begin(), segment.end()))
|
||||||
|
{
|
||||||
|
cout << i+14 << endl;
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -2,12 +2,6 @@
|
|||||||
|
|
||||||
Advent of Code for 2022
|
Advent of Code for 2022
|
||||||
|
|
||||||
## How to contribute
|
# Branch format
|
||||||
|
|
||||||
To contribute to the Advent of Code 2022, please pull master and create a branch with your name.
|
Uploading code files at partX.cpp in each day's folder. Compile the part with `g++ partX.cpp -o partX`. Download your input file as `inptuX` and run the program with `./partX < inputX`.
|
||||||
|
|
||||||
Recommended folder structure is `{Day}\{Language}\{Part}`
|
|
||||||
|
|
||||||
## Tips
|
|
||||||
|
|
||||||
It is recommended to include small document on how the program works and how to compile & run the program.
|
|
||||||
Reference in New Issue
Block a user