Last active
December 5, 2021 09:56
-
-
Save johngian/999bf76be51f81a6551f0967d5547b97 to your computer and use it in GitHub Desktop.
Advent of code 2021 - day1 - solution
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#include <iostream> | |
#include <boost/format.hpp> | |
#include <day1.hpp> | |
namespace day1 | |
{ | |
std::string solution(std::istream &std_input) | |
{ | |
int increased = 0; | |
int prev, curr; | |
std::string line; | |
std::getline(std_input, line); | |
prev = std::stoi(line); | |
while (std::getline(std_input, line)) | |
{ | |
curr = std::stoi(line); | |
if (curr > prev) | |
{ | |
increased++; | |
} | |
prev = curr; | |
} | |
return (boost::format("%d") % increased).str(); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment