Compare commits
16 Commits
885e836f74
...
main
| Author | SHA1 | Date | |
|---|---|---|---|
| aa49da96bb | |||
| c172b4e1ef | |||
| 2a57da02a9 | |||
| 04d7f1305c | |||
| d24974703f | |||
| 625cb4986f | |||
| 55f05e4f16 | |||
| 08c10aecd5 | |||
| f5551d2de2 | |||
| d1d69d08ad | |||
| a5ce4e5803 | |||
| b4232c905d | |||
| 0d4f948ff5 | |||
| 5a1721acf7 | |||
| 31b1c51bf5 | |||
| 1f7d96ad3f |
39
.vscode/launch.json
vendored
39
.vscode/launch.json
vendored
@@ -1,39 +0,0 @@
|
||||
{
|
||||
"configurations": [
|
||||
{
|
||||
"type": "cmake",
|
||||
"request": "launch",
|
||||
"name": "Debug portfile(s)",
|
||||
"cmakeDebugType": "external",
|
||||
"pipeName": "/tmp/vcpkg_ext_portfile_dbg",
|
||||
"preLaunchTask": "Debug vcpkg commands"
|
||||
},
|
||||
{
|
||||
"name": "C/C++: g++ build and debug active file",
|
||||
"type": "cppdbg",
|
||||
"request": "launch",
|
||||
"program": "${fileDirname}/${fileBasenameNoExtension}",
|
||||
"args": [],
|
||||
"stopAtEntry": false,
|
||||
"cwd": "${fileDirname}",
|
||||
"environment": [],
|
||||
"externalConsole": false,
|
||||
"MIMode": "gdb",
|
||||
"setupCommands": [
|
||||
{
|
||||
"description": "Enable pretty-printing for gdb",
|
||||
"text": "-enable-pretty-printing",
|
||||
"ignoreFailures": true
|
||||
},
|
||||
{
|
||||
"description": "Set Disassembly Flavor to Intel",
|
||||
"text": "-gdb-set disassembly-flavor intel",
|
||||
"ignoreFailures": true
|
||||
}
|
||||
],
|
||||
"preLaunchTask": "C/C++: g++ build active file",
|
||||
"miDebuggerPath": "/usr/bin/gdb"
|
||||
}
|
||||
],
|
||||
"version": "2.0.0"
|
||||
}
|
||||
11
.vscode/settings.json
vendored
11
.vscode/settings.json
vendored
@@ -1,13 +1,6 @@
|
||||
{
|
||||
"vcpkg.target.defaultTriplet": "x64-linux",
|
||||
"vcpkg.target.hostTriplet": "x64-linux",
|
||||
"vcpkg.target.useManifest": false,
|
||||
"vcpkg.target.useStaticLib": false,
|
||||
"cmake.configureArgs": [
|
||||
"-DVCPKG_MANIFEST_MODE=OFF",
|
||||
"-DVCPKG_TARGET_TRIPLET=x64-linux"
|
||||
],
|
||||
"files.associations": {
|
||||
"string.h": "c"
|
||||
"iostream": "cpp",
|
||||
"*.tcc": "cpp"
|
||||
}
|
||||
}
|
||||
36
.vscode/tasks.json
vendored
36
.vscode/tasks.json
vendored
@@ -2,46 +2,26 @@
|
||||
"tasks": [
|
||||
{
|
||||
"type": "cppbuild",
|
||||
"label": "C/C++: gcc build active file",
|
||||
"command": "/usr/bin/g++",
|
||||
"label": "C/C++: cl.exe build active file",
|
||||
"command": "cl.exe",
|
||||
"args": [
|
||||
"-fdiagnostics-color=always",
|
||||
"-g",
|
||||
"${file}",
|
||||
"-o",
|
||||
"${fileDirname}/${fileBasenameNoExtension}"
|
||||
"/Zi",
|
||||
"/EHsc",
|
||||
"/nologo",
|
||||
"/Fe${fileDirname}\\${fileBasenameNoExtension}.exe",
|
||||
"${file}"
|
||||
],
|
||||
"options": {
|
||||
"cwd": "${fileDirname}"
|
||||
},
|
||||
"problemMatcher": [
|
||||
"$gcc"
|
||||
"$msCompile"
|
||||
],
|
||||
"group": {
|
||||
"kind": "build",
|
||||
"isDefault": true
|
||||
},
|
||||
"detail": "Task generated by Debugger."
|
||||
},
|
||||
{
|
||||
"type": "cppbuild",
|
||||
"label": "C/C++: g++ build active file",
|
||||
"command": "/usr/bin/g++",
|
||||
"args": [
|
||||
"-fdiagnostics-color=always",
|
||||
"-g",
|
||||
"${file}",
|
||||
"-o",
|
||||
"${fileDirname}/${fileBasenameNoExtension}"
|
||||
],
|
||||
"options": {
|
||||
"cwd": "${fileDirname}"
|
||||
},
|
||||
"problemMatcher": [
|
||||
"$gcc"
|
||||
],
|
||||
"group": "build",
|
||||
"detail": "Task generated by Debugger."
|
||||
}
|
||||
],
|
||||
"version": "2.0.0"
|
||||
|
||||
39
1/puzzle1.c
39
1/puzzle1.c
@@ -1,40 +1,15 @@
|
||||
#include <stdbool.h>
|
||||
#include <stdio.h>
|
||||
#include <string.h>
|
||||
#define stringSize 20
|
||||
|
||||
int listSize = 0;
|
||||
char readChar = '0';
|
||||
char stringOne[stringSize];
|
||||
char stringTwo[stringSize];
|
||||
|
||||
int readIntoList(char *stringList) {
|
||||
int index = 0;
|
||||
|
||||
while (1) {
|
||||
char next = getchar();
|
||||
if (next == '.') {
|
||||
break;
|
||||
} else if (next != '\n') {
|
||||
stringList[index] = next;
|
||||
index++;
|
||||
}
|
||||
}
|
||||
}
|
||||
FILE *puzzleFile;
|
||||
|
||||
int main() {
|
||||
printf("enter list size: \n");
|
||||
|
||||
scanf("%i", &listSize);
|
||||
int listOne[listSize];
|
||||
int listTwo[listSize];
|
||||
|
||||
memset(listOne, '\0', listSize);
|
||||
memset(listTwo, '\0', listSize);
|
||||
printf("enter list 1: \n");
|
||||
readIntoList(stringOne);
|
||||
printf("enter list 2: \n");
|
||||
readIntoList(stringTwo);
|
||||
|
||||
printf("one: %s \ntwo: %s ", stringOne, stringTwo);
|
||||
puzzleFile = fopen("input.txt", "r");
|
||||
if (puzzleFile==NULL){
|
||||
printf("file unable to be opened");
|
||||
}
|
||||
|
||||
printf("helloworld");
|
||||
}
|
||||
@@ -28,7 +28,7 @@ int main(){
|
||||
listTwo.sort();
|
||||
|
||||
for (int x=0; !listOne.empty();x++){
|
||||
totalDistance += listOne.front() + listTwo.front();
|
||||
totalDistance += abs(listOne.front() - listTwo.front());
|
||||
listOne.pop_front();
|
||||
listTwo.pop_front();
|
||||
}
|
||||
|
||||
BIN
1/puzzle1p2
Executable file
BIN
1/puzzle1p2
Executable file
Binary file not shown.
43
1/puzzle1p2.cpp
Normal file
43
1/puzzle1p2.cpp
Normal file
@@ -0,0 +1,43 @@
|
||||
#include <stdio.h>
|
||||
#include <list>
|
||||
#include <iostream>
|
||||
#include <fstream>
|
||||
#include <unordered_map>
|
||||
|
||||
using namespace std;
|
||||
|
||||
list<int> listOne{};
|
||||
list<int> listTwo{};
|
||||
|
||||
unordered_map<int, int> listTwoMap;
|
||||
|
||||
int simscore = 0;
|
||||
|
||||
int main(){
|
||||
|
||||
ifstream puzzle("input.txt");
|
||||
|
||||
int tempOne, tempTwo;
|
||||
|
||||
while (puzzle >> tempOne >> tempTwo)
|
||||
{
|
||||
listOne.push_back(tempOne);
|
||||
listTwo.push_back(tempTwo);
|
||||
}
|
||||
|
||||
puzzle.close();
|
||||
|
||||
for (int num:listTwo){
|
||||
listTwoMap[num]++;
|
||||
}
|
||||
|
||||
for (int listOneItem = 0; !listOne.empty(); listOneItem= listOne.front()) {
|
||||
if(listTwoMap.contains(listOneItem)){
|
||||
simscore += listOneItem * listTwoMap[listOneItem];
|
||||
}
|
||||
|
||||
listOne.pop_front();
|
||||
}
|
||||
|
||||
printf("total simularity: %i\n", simscore);
|
||||
}
|
||||
1000
2/input.txt
Normal file
1000
2/input.txt
Normal file
File diff suppressed because it is too large
Load Diff
66
2/puzzle2.cpp
Normal file
66
2/puzzle2.cpp
Normal file
@@ -0,0 +1,66 @@
|
||||
#include <stdio.h>
|
||||
#include <list>
|
||||
#include <iostream>
|
||||
#include <fstream>
|
||||
#include <string>
|
||||
#include <vector>
|
||||
#include <sstream>
|
||||
|
||||
using namespace std;
|
||||
|
||||
enum Direction {
|
||||
UP,
|
||||
DOWN
|
||||
};
|
||||
|
||||
int main(){
|
||||
string line;
|
||||
int safeReports = 0;
|
||||
stringstream wholeDoc;
|
||||
|
||||
ifstream puzzle("input.txt", ifstream::in);
|
||||
|
||||
while (getline(puzzle, line)) {
|
||||
istringstream lineStream(line);
|
||||
string numberString;
|
||||
list<int> currentLevels;
|
||||
while (getline(lineStream, numberString, ' ')) {
|
||||
int number = stoi(numberString);
|
||||
currentLevels.push_back(number);
|
||||
}
|
||||
|
||||
int numOfLevelsInLine = currentLevels.size();
|
||||
int numOfLevelsProcessed = 0;
|
||||
|
||||
//need to pull the first one to have something to compare to
|
||||
enum Direction dir;
|
||||
int prevlevel = currentLevels.front();
|
||||
currentLevels.pop_front();
|
||||
numOfLevelsProcessed++;
|
||||
if (prevlevel < currentLevels.front()){
|
||||
dir = DOWN;
|
||||
} else if (prevlevel > currentLevels.front()){
|
||||
dir = UP;
|
||||
} else {
|
||||
currentLevels.clear();
|
||||
}
|
||||
|
||||
|
||||
for (int level = currentLevels.front(); !currentLevels.empty();level=currentLevels.front()){
|
||||
if (abs(prevlevel-level)>3) {currentLevels.clear();break;}
|
||||
if(prevlevel==level){ currentLevels.clear();break;}
|
||||
if(dir==UP&&(prevlevel<currentLevels.front())) {currentLevels.clear();break;}
|
||||
if(dir==DOWN&&(prevlevel>currentLevels.front())) {currentLevels.clear();break;}
|
||||
|
||||
prevlevel=currentLevels.front();
|
||||
currentLevels.pop_front();
|
||||
numOfLevelsProcessed++;
|
||||
|
||||
if(numOfLevelsProcessed==numOfLevelsInLine){
|
||||
safeReports++;
|
||||
}
|
||||
}
|
||||
}
|
||||
cout << safeReports;
|
||||
puzzle.close();
|
||||
}
|
||||
BIN
2/puzzle2.exe
Normal file
BIN
2/puzzle2.exe
Normal file
Binary file not shown.
BIN
2/puzzle2.ilk
Normal file
BIN
2/puzzle2.ilk
Normal file
Binary file not shown.
BIN
2/puzzle2.obj
Normal file
BIN
2/puzzle2.obj
Normal file
Binary file not shown.
BIN
2/puzzle2.pdb
Normal file
BIN
2/puzzle2.pdb
Normal file
Binary file not shown.
BIN
2/puzzle2p2
Executable file
BIN
2/puzzle2p2
Executable file
Binary file not shown.
145
2/puzzle2p2.cpp
Normal file
145
2/puzzle2p2.cpp
Normal file
@@ -0,0 +1,145 @@
|
||||
#include <stdio.h>
|
||||
#include <list>
|
||||
#include <iostream>
|
||||
#include <fstream>
|
||||
#include <string>
|
||||
#include <vector>
|
||||
#include <sstream>
|
||||
#include <iterator>
|
||||
|
||||
using namespace std;
|
||||
|
||||
enum Direction {
|
||||
UP,
|
||||
DOWN,
|
||||
UNSET
|
||||
};
|
||||
|
||||
int main(){
|
||||
string line;
|
||||
int safeReports = 0;
|
||||
stringstream wholeDoc;
|
||||
int linesReadFromFile= 0;
|
||||
|
||||
ifstream puzzle("input.txt", ifstream::in);
|
||||
|
||||
while (getline(puzzle, line)) {
|
||||
istringstream lineStream(line);
|
||||
string numberString;
|
||||
list<int> currentLevels;
|
||||
while (getline(lineStream, numberString, ' ')) {
|
||||
int number = stoi(numberString);
|
||||
currentLevels.push_back(number);
|
||||
}
|
||||
linesReadFromFile++;
|
||||
|
||||
list<int> currentLevelsBackup = currentLevels;
|
||||
int numOfLevelsProcessed = 0;
|
||||
auto curListIt = currentLevels.begin();
|
||||
curListIt++; //point to second item in list
|
||||
auto RevCurListIt = currentLevels.rbegin();
|
||||
RevCurListIt++; //points to second to last item
|
||||
enum Direction dir;
|
||||
bool listDirty =false;
|
||||
list<int>changeFromPrevLevel;
|
||||
list<int>levelGoesUp;
|
||||
list<int>levelGoDown;
|
||||
list<int>levelStaysSame;
|
||||
int totalChange=0;
|
||||
|
||||
//we are going to walk the levels and see what the change is.
|
||||
//the frontIt is the front number (starts at 2nd entry)
|
||||
//backIt is the first entry (starts at 1st entry)
|
||||
|
||||
auto frontIt = currentLevels.begin();
|
||||
frontIt++;
|
||||
auto backIt = currentLevels.begin();
|
||||
|
||||
for(int index = 1;frontIt!=currentLevels.end();index++){
|
||||
int change = (*frontIt) - (*backIt);
|
||||
totalChange+=change;
|
||||
changeFromPrevLevel.push_back(change);
|
||||
frontIt++;
|
||||
backIt++;
|
||||
if (change>0){
|
||||
levelGoesUp.push_front(index);
|
||||
} else if(change<0){
|
||||
levelGoDown.push_front(index);
|
||||
} else {
|
||||
levelStaysSame.push_front(index);
|
||||
}
|
||||
}
|
||||
|
||||
if (totalChange>0){
|
||||
dir= UP;
|
||||
} else if (totalChange<0){
|
||||
dir = DOWN;
|
||||
}
|
||||
|
||||
if(dir==UP&&changeFromPrevLevel.front()<0){
|
||||
currentLevels.erase(currentLevels.begin());
|
||||
levelGoDown.pop_front();
|
||||
listDirty=true;
|
||||
}
|
||||
|
||||
if (dir==UP&&levelGoDown.size()>1){ //if the overall direction goes up and more then 1 level go down the list is bad
|
||||
currentLevels.clear();
|
||||
} else if (dir==DOWN&&levelGoesUp.size()>1){ //same as above but opiosite dirrection
|
||||
currentLevels.clear();
|
||||
}
|
||||
|
||||
if (levelStaysSame.size()>1||(listDirty&&levelStaysSame.size()==0)){ //cant have more then 1 number the same or the list is bad
|
||||
currentLevels.clear();
|
||||
}
|
||||
|
||||
if (!currentLevels.empty()&&levelStaysSame.size()==1){
|
||||
auto itNumberToDelete = currentLevels.begin();
|
||||
advance(itNumberToDelete,levelStaysSame.front());
|
||||
currentLevels.erase(itNumberToDelete);
|
||||
listDirty = true;
|
||||
}
|
||||
|
||||
if(listDirty&&dir==DOWN&&levelGoesUp.size()>0){
|
||||
currentLevels.clear();
|
||||
} else if(listDirty&&dir==UP&&levelGoDown.size()>0){
|
||||
currentLevels.clear();
|
||||
}
|
||||
|
||||
if (!currentLevels.empty()){
|
||||
if (dir==UP&&levelGoDown.size()==1){
|
||||
list<int>::iterator itNumberToDelete = currentLevels.begin();
|
||||
advance(itNumberToDelete,levelGoDown.front());
|
||||
currentLevels.erase(itNumberToDelete);
|
||||
listDirty = true;
|
||||
} else if (dir==DOWN&&levelGoesUp.size()==1){
|
||||
auto itNumberToDelete = currentLevels.begin();
|
||||
advance(itNumberToDelete,levelGoesUp.front());
|
||||
currentLevels.erase(itNumberToDelete);
|
||||
listDirty=true;
|
||||
}
|
||||
|
||||
int numOfLevelsInLine = currentLevels.size();
|
||||
|
||||
//need to pull the first one to have something to compare to
|
||||
int prevlevel = currentLevels.front();
|
||||
currentLevels.pop_front();
|
||||
numOfLevelsProcessed++;
|
||||
|
||||
for (int level = currentLevels.front(); !currentLevels.empty();level=currentLevels.front()){
|
||||
if (abs(prevlevel-level)>3) {currentLevels.clear();break;}
|
||||
|
||||
prevlevel=currentLevels.front();
|
||||
currentLevels.pop_front();
|
||||
numOfLevelsProcessed++;
|
||||
|
||||
if(numOfLevelsProcessed==numOfLevelsInLine){
|
||||
safeReports++;
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
cout <<"lines read in: " << linesReadFromFile<<"\n";
|
||||
cout <<"safe Reports: " << safeReports;
|
||||
puzzle.close();
|
||||
}
|
||||
BIN
2/puzzle2p2.exe
Normal file
BIN
2/puzzle2p2.exe
Normal file
Binary file not shown.
BIN
2/puzzle2p2.ilk
Normal file
BIN
2/puzzle2p2.ilk
Normal file
Binary file not shown.
BIN
2/puzzle2p2.obj
Normal file
BIN
2/puzzle2p2.obj
Normal file
Binary file not shown.
BIN
2/puzzle2p2.pdb
Normal file
BIN
2/puzzle2p2.pdb
Normal file
Binary file not shown.
BIN
2/vc140.pdb
Normal file
BIN
2/vc140.pdb
Normal file
Binary file not shown.
Reference in New Issue
Block a user