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

namespace aoc2020 {

std::pair<int, int> day4(line_view file) {
  const char* p1 = file.line;
  const char* p2 = file.line + file.length;
  const char* p = p1;
  int t0{0};
  int t1{0};
  bool b1{false};
  bool b2{false};
  while (p < p2) {
    if (*p == '\n' && *(p + 1) == '\n') {
      passport pass{p1, p};
      // std::cout << pass << std::endl;
      pass.is_valid(&b1, &b2);
      t0 += int(b1);
      t1 += int(b2);
      p1 = p + 2;
    }
    p++;
  }
  passport{p1, p}.is_valid(&b1, &b2);
  t0 += int(b1);
  t1 += int(b2);
  return {t0, t1};
}

} // namespace aoc2020