aboutsummaryrefslogtreecommitdiff
path: root/2024/02/day02a.cpp
blob: cdd9efaff3e2c6e00d786887efa28ef9fd457a2a (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
#include <iostream>
#include <sstream>
#include <vector>
#include <algorithm>
#include <string>
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;
}

Generated with cgit - Back to sebastiano.tronto.net