From d96f65b6b51b78ddd9f51896ea99c8010ed77812 Mon Sep 17 00:00:00 2001 From: kaiwu Date: Thu, 15 Dec 2022 18:09:56 +0800 Subject: 2022 day15 part1 --- src/2022/day15/aoc.cpp | 41 +++++++++++++++++++++++++++++++++++++++-- 1 file changed, 39 insertions(+), 2 deletions(-) (limited to 'src/2022/day15/aoc.cpp') diff --git a/src/2022/day15/aoc.cpp b/src/2022/day15/aoc.cpp index 6e2d7a7..09a923f 100644 --- a/src/2022/day15/aoc.cpp +++ b/src/2022/day15/aoc.cpp @@ -1,9 +1,46 @@ #include "aoc.h" +#include namespace aoc2022 { +int sensor::minx; +int sensor::maxx; -std::pair day15(line_view) { - return {0, 0}; + +int no_beacon(int y, std::vector& ss) { + int count{0}; + for (int x = sensor::minx; x <= sensor::maxx; x++) { + sensor::pos p; + p.x = x; + p.y = y; + size_t n{0}; + for (auto&s : ss) { + if(s.inscope(p)) { + n++; + } + } + // printf("(%d, %d) has %zu\n", x, y, n); + count += (bool) n > 0; + } + return count; +} + +bool valid(sensor::pos p, int dx) { + return p.x >= 0 && p.x <= dx && p.y >= 0 && p.y <= dx; +} + +int only_beacon(int dx, std::vector& ss) { + return 0; +} + +std::pair day15(line_view file) { + std::vector ss; + per_line(file, [&ss](line_view lv){ + ss.emplace_back(lv); + return true; + }); + int n1 = no_beacon(2000000, ss); + int n2 = only_beacon(4000000, ss); + return {n1, n2}; } } -- cgit v1.2.3