Compare commits
2 commits
885e836f74
...
31b1c51bf5
| Author | SHA1 | Date | |
|---|---|---|---|
| 31b1c51bf5 | |||
| 1f7d96ad3f |
5 changed files with 48 additions and 1 deletions
4
.vscode/tasks.json
vendored
4
.vscode/tasks.json
vendored
|
|
@ -5,6 +5,8 @@
|
|||
"label": "C/C++: gcc build active file",
|
||||
"command": "/usr/bin/g++",
|
||||
"args": [
|
||||
"--std",
|
||||
"gnu++23",
|
||||
"-fdiagnostics-color=always",
|
||||
"-g",
|
||||
"${file}",
|
||||
|
|
@ -28,6 +30,8 @@
|
|||
"label": "C/C++: g++ build active file",
|
||||
"command": "/usr/bin/g++",
|
||||
"args": [
|
||||
"--std",
|
||||
"gnu++23",
|
||||
"-fdiagnostics-color=always",
|
||||
"-g",
|
||||
"${file}",
|
||||
|
|
|
|||
BIN
1/puzzle1
BIN
1/puzzle1
Binary file not shown.
|
|
@ -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);
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue