Finished day 7 aoc
This commit is contained in:
@@ -76,8 +76,20 @@ public:
|
|||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
|
|
||||||
long getAnswerPartTwo(long max_size){
|
long getAnswerPartTwo(long min_size_needed){
|
||||||
|
long result = getContainerSize();
|
||||||
|
if(result >= min_size_needed){
|
||||||
|
for(auto sub : subdirectories){
|
||||||
|
long sub_result = sub->getAnswerPartTwo(min_size_needed);
|
||||||
|
|
||||||
|
if(sub_result < result){
|
||||||
|
result = sub_result;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return result;
|
||||||
|
} else{
|
||||||
|
return 700000000;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
@@ -166,7 +178,13 @@ int main(){
|
|||||||
|
|
||||||
long result = main_directory.getAnswer(100000);
|
long result = main_directory.getAnswer(100000);
|
||||||
|
|
||||||
cout << result << endl;
|
cout << "Sum of directories smaller than 100000: " << result << endl;
|
||||||
|
|
||||||
|
long unused_space = 70000000 - main_directory.getContainerSize();
|
||||||
|
long min_space_needed = 30000000 - unused_space;
|
||||||
|
result = main_directory.getAnswerPartTwo(min_space_needed);
|
||||||
|
|
||||||
|
cout << "Smallest directory larger than " << min_space_needed << ": " << result << endl;
|
||||||
|
|
||||||
// Printing parsed commands
|
// Printing parsed commands
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user