Compare commits

..

2 commits

Author SHA1 Message Date
31b1c51bf5 completed day 1 2024-12-02 11:33:11 +13:00
1f7d96ad3f completed p1p1 2024-12-02 11:06:14 +13:00
5 changed files with 48 additions and 1 deletions

4
.vscode/tasks.json vendored
View file

@ -5,6 +5,8 @@
"label": "C/C++: gcc build active file", "label": "C/C++: gcc build active file",
"command": "/usr/bin/g++", "command": "/usr/bin/g++",
"args": [ "args": [
"--std",
"gnu++23",
"-fdiagnostics-color=always", "-fdiagnostics-color=always",
"-g", "-g",
"${file}", "${file}",
@ -28,6 +30,8 @@
"label": "C/C++: g++ build active file", "label": "C/C++: g++ build active file",
"command": "/usr/bin/g++", "command": "/usr/bin/g++",
"args": [ "args": [
"--std",
"gnu++23",
"-fdiagnostics-color=always", "-fdiagnostics-color=always",
"-g", "-g",
"${file}", "${file}",

BIN
1/puzzle1

Binary file not shown.

View file

@ -28,7 +28,7 @@ int main(){
listTwo.sort(); listTwo.sort();
for (int x=0; !listOne.empty();x++){ for (int x=0; !listOne.empty();x++){
totalDistance += listOne.front() + listTwo.front(); totalDistance += abs(listOne.front() - listTwo.front());
listOne.pop_front(); listOne.pop_front();
listTwo.pop_front(); listTwo.pop_front();
} }

BIN
1/puzzle1p2 Executable file

Binary file not shown.

43
1/puzzle1p2.cpp Normal file
View 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);
}