Skip to content

Instantly share code, notes, and snippets.

@johngian
Last active December 5, 2021 09:56
Show Gist options
  • Save johngian/999bf76be51f81a6551f0967d5547b97 to your computer and use it in GitHub Desktop.
Save johngian/999bf76be51f81a6551f0967d5547b97 to your computer and use it in GitHub Desktop.
Advent of code 2021 - day1 - solution
#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