From ed71280dc202130e988dc117cdc7cf1198cfb3f4 Mon Sep 17 00:00:00 2001 From: Matthew Gretton-Dann Date: Thu, 4 Sep 2025 11:09:22 +0200 Subject: [PATCH] Convert largest_square to use pos indices. This makes the code a bit more confusing but no functional change. --- main.cc | 12 +++++++----- 1 file changed, 7 insertions(+), 5 deletions(-) diff --git a/main.cc b/main.cc index 3b4d80b..20b51ae 100644 --- a/main.cc +++ b/main.cc @@ -180,16 +180,18 @@ namespace { * This means we only need to look for the first non-clear position along the * current row. */ - auto b = pos_x(pos); + auto const pos_x = pos % length_; + auto const pos_y0 = pos - pos_x; + auto b = pos; // Make sure we don't go looking in the next row. - auto e = std::min(pos_x(pos) + n, length_); + auto const e = std::min(pos + n, pos_y0 + length_); while (b < e) { - if (grid_[b + pos_y(pos) * length_] != empty) { break; } + if (grid_[b] != empty) { break; } ++b; } // Check that this length fits vertically as well. - auto len = b - pos_x(pos); - auto ye = std::min(pos_y(pos) + len, length_); + auto const len = b - pos; + auto const ye = std::min((pos / length_) + len, length_); return ye - pos_y(pos); }