From 911a30b93157ee708571f6f477d3dc200738517b Mon Sep 17 00:00:00 2001 From: Fawkes100 Date: Sun, 8 Dec 2024 09:12:26 +0100 Subject: [PATCH] Day 1: Part 2 --- .idea/.gitignore | 8 ++++++++ Aufgabe1/.idea/.gitignore | 8 ++++++++ Aufgabe1/.idea/Aufgabe1.iml | 2 ++ Aufgabe1/main.cpp | 22 ++++++++++++++++++++++ 4 files changed, 40 insertions(+) create mode 100644 .idea/.gitignore create mode 100644 Aufgabe1/.idea/.gitignore create mode 100644 Aufgabe1/.idea/Aufgabe1.iml diff --git a/.idea/.gitignore b/.idea/.gitignore new file mode 100644 index 0000000..13566b8 --- /dev/null +++ b/.idea/.gitignore @@ -0,0 +1,8 @@ +# Default ignored files +/shelf/ +/workspace.xml +# Editor-based HTTP Client requests +/httpRequests/ +# Datasource local storage ignored files +/dataSources/ +/dataSources.local.xml diff --git a/Aufgabe1/.idea/.gitignore b/Aufgabe1/.idea/.gitignore new file mode 100644 index 0000000..13566b8 --- /dev/null +++ b/Aufgabe1/.idea/.gitignore @@ -0,0 +1,8 @@ +# Default ignored files +/shelf/ +/workspace.xml +# Editor-based HTTP Client requests +/httpRequests/ +# Datasource local storage ignored files +/dataSources/ +/dataSources.local.xml diff --git a/Aufgabe1/.idea/Aufgabe1.iml b/Aufgabe1/.idea/Aufgabe1.iml new file mode 100644 index 0000000..f08604b --- /dev/null +++ b/Aufgabe1/.idea/Aufgabe1.iml @@ -0,0 +1,2 @@ + + \ No newline at end of file diff --git a/Aufgabe1/main.cpp b/Aufgabe1/main.cpp index 6f06580..53b0b47 100644 --- a/Aufgabe1/main.cpp +++ b/Aufgabe1/main.cpp @@ -117,6 +117,25 @@ int solve(std::vector& left, std::vector& right) { return sum; } +int countOccurenceInList(std::vector& vec, int element) { + int occurences = 0; + for(const auto& i: vec) { + if(i == element) { + occurences++; + } + } + return occurences; +} + +int calcSimilarity(std::vector& left, std::vector& right) { + int similarityScore = 0; + for(int i : left) { + int occurencesInRightList = countOccurenceInList(right, i); + similarityScore += i * occurencesInRightList; + } + return similarityScore; +} + int main() { std::string inputFile = "../input.txt"; std::vector input = readTextFromFile(inputFile); @@ -124,5 +143,8 @@ int main() { int result = solve(leftArray, rightArray); std::cout << "The result is: " << result << std::endl; + + int similarityScore = calcSimilarity(leftArray, rightArray); + std::cout << "The similarity is " << similarityScore << std::endl; return 0; }