~ttt/sudoku

47fcedfc3486135be01612af02c5892f36879811 — Tomasz Kłak 3 years ago 2a2f02a
Removed one sort.
1 files changed, 17 insertions(+), 7 deletions(-)

M main.cc
M main.cc => main.cc +17 -7
@@ 371,24 371,21 @@ struct Board {
    void findUniqueInUnit(const Unit& unit, PosToPiece& out) const {
        thread_local std::vector<std::pair<Piece, Pos>> tmp;
        tmp.clear();
        std::array<uint8_t, 10> count{0};
        for (const auto pos : unit) {
            const auto& field = get(pos);
            if (!field.isUnique())
            {
                field.forEach([&tmp, pos](const Piece piece) {
                field.forEach([&tmp, &count, pos](const Piece piece) {
                    tmp.emplace_back(piece, pos);
                    count[piece]++;
                });
            }
        }
        std::sort(tmp.begin(), tmp.end(),
            [](const auto& l, const auto& r) { return l.first < r.first; });
        Piece last = 0;
        for (size_t i = 0; i != tmp.size(); ++i) {
            if (tmp[i].first > last &&
                    (i+1 == tmp.size() || tmp[i].first != tmp[i+1].first)) {
            if (count[tmp[i].first] == 1) {
                out.emplace(tmp[i].second, tmp[i].first);
            }
            last = tmp[i].first;
        }
    }



@@ 767,6 764,8 @@ void testHardest() {
        "..............8..................................................................",
        "..............8..........................3.......................................",
        "1.............8..........................3.......................................",
        ".....6....59.....82....8....45........3........6..3.54...325..6..................",
        // ".....5.8....6.1.43..........1.5........1.6...3.......553.....61........4.........",
    };
    std::cout << "hardest" << std::endl;
    for (const auto& in : input) {


@@ 783,7 782,15 @@ void testHardest() {
        std::cerr << std::endl;
#endif
    }
}

void testInvalid() {
    std::vector<std::string> input{
        ".....5.8....6.1.43..........1.5........1.6...3.......553.....61........4.........",
    };
    for (const auto& in : input) {
        assert(!Board::parse(in).solve());
    }
}

void testField() {


@@ 948,4 955,7 @@ int main() {
    testHard();
#endif
    testHardest();
#ifdef SLOW
    testInvalid();
#endif
}