From 5a23d15ff9bb69d9e9b52e543596e75af3b090f9 Mon Sep 17 00:00:00 2001 From: Sebastiano Tronto Date: Mon, 2 Dec 2024 06:46:28 +0100 Subject: Day 2 2024 --- 2024/02/day02a.cpp | 30 ++++++++++++++++++++++++++++++ 1 file changed, 30 insertions(+) create mode 100644 2024/02/day02a.cpp (limited to '2024/02/day02a.cpp') diff --git a/2024/02/day02a.cpp b/2024/02/day02a.cpp new file mode 100644 index 0000000..cdd9efa --- /dev/null +++ b/2024/02/day02a.cpp @@ -0,0 +1,30 @@ +#include +#include +#include +#include +#include +using namespace std; + +bool isvalid(const string &line) { + int x, y, b; + istringstream s(line); + + s >> x >> y; + b = x > y ? 1 : -1; + do { + int d = b * (x-y); + if (d < 1 || d > 3) + return false; + x = y; + } while (s >> y); + + return true; +} + +int main() { + int tot = 0; + for (string line; getline(cin, line); ) + tot += isvalid(line); + cout << tot << endl; + return 0; +} -- cgit v1.3