diff --git a/CMakeLists.txt b/CMakeLists.txt index 5e02161..99188b4 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -17,7 +17,7 @@ link_directories("/usr/local/lib" "/opt/homebrew/opt/llvm/lib") set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} ${OpenMP_CXX_FLAGS} -fopenmp") -set(executables d1 d2 d3 d4 d5) +set(executables d1 d2 d3 d4 d5 d6) foreach(executable ${executables}) add_executable(${executable} "${executable}/main.cxx") diff --git a/d6/input.txt b/d6/input.txt new file mode 100644 index 0000000..b988316 --- /dev/null +++ b/d6/input.txt @@ -0,0 +1,2 @@ +Time: 40 70 98 79 +Distance: 215 1051 2147 1005 \ No newline at end of file diff --git a/d6/main.cxx b/d6/main.cxx new file mode 100644 index 0000000..d8a655a --- /dev/null +++ b/d6/main.cxx @@ -0,0 +1,41 @@ +#include +#include +#include +#include +#include +#include + +int main() +{ + std::ifstream file{"../d6/input.txt"}; + std::string line, temp, strDistance, strTime; + int result{0}; + + std::getline(file, line); + std::stringstream tss(line); + tss >> temp; + while (tss.tellg() != -1) + { + tss >> temp; + strTime.append(temp); + } + + std::getline(file, line); + std::stringstream dss(line); + dss >> temp; + while (dss.tellg() != -1) + { + dss >> temp; + strDistance.append(temp); + } + + long time = std::stol(strTime); + long distance = std::stol(strDistance); + for (int i{0}; i < time; i++) + { + result += distance < (time - i) * i; + } + + std::cout << result << std::endl; + return 0; +}