Day 1: Part 2
This commit is contained in:
parent
939cf8b74a
commit
911a30b931
8
.idea/.gitignore
vendored
Normal file
8
.idea/.gitignore
vendored
Normal file
@ -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
|
8
Aufgabe1/.idea/.gitignore
vendored
Normal file
8
Aufgabe1/.idea/.gitignore
vendored
Normal file
@ -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
|
2
Aufgabe1/.idea/Aufgabe1.iml
Normal file
2
Aufgabe1/.idea/Aufgabe1.iml
Normal file
@ -0,0 +1,2 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<module classpath="CMake" type="CPP_MODULE" version="4" />
|
@ -117,6 +117,25 @@ int solve(std::vector<int>& left, std::vector<int>& right) {
|
||||
return sum;
|
||||
}
|
||||
|
||||
int countOccurenceInList(std::vector<int>& vec, int element) {
|
||||
int occurences = 0;
|
||||
for(const auto& i: vec) {
|
||||
if(i == element) {
|
||||
occurences++;
|
||||
}
|
||||
}
|
||||
return occurences;
|
||||
}
|
||||
|
||||
int calcSimilarity(std::vector<int>& left, std::vector<int>& 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<std::string> 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;
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user