This commit is contained in:
grant 2022-12-07 21:25:52 -06:00
commit 481aa01717
6 changed files with 152 additions and 0 deletions

12
.gitignore vendored Normal file
View File

@ -0,0 +1,12 @@
#ignore all files
*
#unignore all extensions
!*.*
#unignore dirs
!*/
#include justfile & license
!justfile
!LICENSE

25
2022/day-1.cpp Normal file
View File

@ -0,0 +1,25 @@
#include <iostream>
#include <vector>
#include <string>
#include <algorithm>
int main(int argc, char* argv[]){
std::cout<<"paste input followed by a ;\n";
std::vector<int> inp;
std::string line;
int index = 0;
inp.push_back(0);
while(getline(std::cin, line)){
if(line==";")
break;
if(line==""){
index++;
inp.push_back(0);
}
else
inp[index]+=std::stoi(line);
}
std::sort(inp.begin(),inp.end(),std::greater<int>());
std::cout<<"part 1 :"<<inp[0]<<std::endl;
std::cout<<"part 2 :"<<inp[0]+inp[1]+inp[2];
return 0;
}

85
2022/day-2.cpp Normal file
View File

@ -0,0 +1,85 @@
#include <iostream>
#include <vector>
#include <string>
#include <algorithm>
int rps(char user, char opp){ // 0 = lose, 1 = win, 2 = draw
if(user=='X'){
if(opp=='A')
return 2;
if(opp=='B')
return 0;
if(opp=='C')
return 1;
} else if(user=='Y'){
if(opp=='A')
return 1;
if(opp=='B')
return 2;
if(opp=='C')
return 0;
}
if(opp=='A')
return 0;
if(opp=='B')
return 1;
if(opp=='C')
return 2;
return 3;
}
int p2_rps(char user,char opp){
int p = 0;
if(user=='Y'){
if(opp=='A'){
return 1+3;
} else if(opp=='B'){
return 2+3;
}
return 3+3;
}
else if(user=='Z'){
if(opp=='A'){
return 2+6;
} else if(opp=='B'){
return 3+6;
}
return 1+6;
}
if(opp=='A'){
return 3;
} else if(opp=='B'){
return 1;
}
return 2;
}
int main(int argc, char* argv[]){
std::cout<<"paste input followed by a ;\n";
std::vector<int> inp;
std::string line;
int points = 0;
int p2_points = 0;
while(getline(std::cin, line)){
if(line==";")
break;
if(rps(line[2],line[0])==2)
points+=3;
else if(rps(line[2],line[0])==1)
points+=6;
if(line[2]=='X')
points+=1;
else if(line[2]=='Y')
points+=2;
else
points+=3;
//split
p2_points+=p2_rps(line[2],line[0]);
}
std::cout<<"part 1 :"<<points<<std::endl;
std::cout<<"part 2 :"<<p2_points;
//std::cout<<"part 1 :"<<inp[0]<<std::endl;
//std::cout<<"part 2 :"<<inp[0]+inp[1]+inp[2];
return 0;
}

7
LICENSE Normal file
View File

@ -0,0 +1,7 @@
Copyright © 2022 <grantsquires@disroot.org>
Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the “Software”), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED “AS IS”, WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.

12
justfile Normal file
View File

@ -0,0 +1,12 @@
#list all options
default:
just --list
#list total lines of c++ code
lines:
wc -l */*.cpp
#2022 day 1 ~ both parts
y22-d1:
g++ -o ./2022/day-1 ./2022/day-1.cpp && ./2022/day-1
#2022 day 2 ~ both parts
y22-d2:
g++ -o ./2022/day-2 ./2022/day-2.cpp && ./2022/day-2

11
readme.md Normal file
View File

@ -0,0 +1,11 @@
# Advent Of Code
[https://adventofcode.com/](https://adventofcode.com/)
this is a repository of all of my code used in these challenges
this is not at all complete! and i will have to redo my work that i have done prior to 2022
this is not made for others to cheat, more as proof of completion, but use it as you will!
check out the justfile for builds and running:)