This commit is contained in:
Hugo Mårdbrink 2023-12-07 20:50:03 +01:00
parent 959e247258
commit 57da32dd7a
3 changed files with 44 additions and 1 deletions

View file

@ -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")

2
d6/input.txt Normal file
View file

@ -0,0 +1,2 @@
Time: 40 70 98 79
Distance: 215 1051 2147 1005

41
d6/main.cxx Normal file
View file

@ -0,0 +1,41 @@
#include <iostream>
#include <fstream>
#include <sstream>
#include <string>
#include <vector>
#include <limits>
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;
}