aboutsummaryrefslogtreecommitdiff
path: root/src/2020/day4/aoc.cpp
blob: 171f42eea9dea23314660ac7be9738283e89fceb (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
#include "aoc.h"

namespace aoc2020 {

int day4(line_view file) {
  const char* p1 = file.line;
  const char* p2 = file.line + file.length;
  const char* p = p1;
  int total{0};
  while (p < p2) {
    if (*p == '\n' && *(p + 1) == '\n') {
      passwort pass{p1, p};
      // std::cout << pass << std::endl;
      if (pass.is_valid()) {
        total++;
      }
      p1 = p + 2;
    }
    p++;
  }
  if (passwort{p1, p}.is_valid()) {
    total++;
  }
  return total;
}

} // namespace aoc2020