amos 8b7616bfd8 Batch 22 (20261027-C-hwe-hard-22): add 63 calibrated HWE hard-design tasks
From the 101 lk/man/pth code-gen sources: 63 tasks (C11 36, C++17 27,
11 canonical families), 38 skipped for scope or duplication. Each task
has at least one independent contract-edge defect, boundary types
rotate, and public docs state trap clauses as plain contract prose.
Claude reviewed 63/63 USABLE against current digests. Difficulty is
unmeasured.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2026-10-27 16:14:57 +08:00

201 lines
7.5 KiB
C++

#define main candidate_application_main
#include "capture.hpp"
#undef main
#include <iostream>
#include <sstream>
#include <string>
#include <vector>
using namespace capture;
std::vector<std::uint8_t> raw_bytes(const std::string& word)
{
std::vector<std::uint8_t> result;
if (word == "-") return result;
for (std::size_t i = 0; i < word.size(); i += 2) {
result.push_back(static_cast<std::uint8_t>(std::stoul(word.substr(i, 2), nullptr, 16)));
}
return result;
}
std::string raw_hex(const std::vector<std::uint8_t>& value)
{
std::string result;
const char* digits = "0123456789abcdef";
for (auto byte : value) {
result += digits[byte >> 4];
result += digits[byte & 15];
}
return result;
}
std::string text_hex(const std::string& value)
{
return raw_hex(std::vector<std::uint8_t>(value.begin(), value.end()));
}
void show_entry(const Entry& entry)
{
std::cout << '[' << (entry.present ? 1 : 0) << ',' << entry.stamp.sec << ',';
std::cout << entry.stamp.nsec << ',' << entry.sequence << ",\"";
std::cout << raw_hex(entry.payload) << "\"]";
}
void show_books(const Book (&books)[2])
{
std::cout << '[';
for (int b = 0; b < 2; ++b) {
if (b) std::cout << ',';
std::cout << '[' << books[b].accepted << ",[";
for (std::size_t i = 0; i < channel_count; ++i) {
if (i) std::cout << ',';
show_entry(books[b].entries[i]);
}
std::cout << "]]";
}
std::cout << ']';
}
int main()
{
Book books[2];
std::string line;
while (std::getline(std::cin, line)) {
std::istringstream input(line);
std::string op;
input >> op;
if (op == "N") {
std::int64_t sec, nsec;
Stamp out;
int nil;
input >> sec >> nsec >> out.sec >> out.nsec >> nil;
auto status = normalize(sec, nsec, nil ? nullptr : &out);
std::cout << '[' << int(status) << ',' << out.sec << ',' << out.nsec << ']';
} else if (op == "D" || op == "C") {
Stamp a, b;
std::int64_t initial;
int nil;
input >> a.sec >> a.nsec >> b.sec >> b.nsec >> initial >> nil;
std::int64_t delta = initial;
int comparison = static_cast<int>(initial);
auto status = op == "D" ? delta_microseconds(a, b, nil ? nullptr : &delta) :
compare_stamp(a, b, nil ? nullptr : &comparison);
std::cout << '[' << int(status) << ',' << (op == "D" ? delta : comparison);
std::cout << ',' << a.sec << ',' << a.nsec << ',' << b.sec << ',' << b.nsec << ']';
} else if (op == "P") {
std::string word;
std::int64_t out;
int nil;
input >> word >> out >> nil;
auto bytes = raw_bytes(word);
std::string text(bytes.begin(), bytes.end());
auto status = parse_i64(text, nil ? nullptr : &out);
std::cout << '[' << int(status) << ',' << out << ",\"" << text_hex(text) << "\"]";
} else if (op == "H" || op == "E") {
std::string word, initial;
int nil;
input >> word >> initial >> nil;
auto bytes = raw_bytes(word);
auto seed = raw_bytes(initial);
std::string text(bytes.begin(), bytes.end());
std::string output(seed.begin(), seed.end());
if (op == "H") {
auto status = decode_hex(text, nil ? nullptr : &seed);
std::cout << '[' << int(status) << ",\"" << raw_hex(seed) << "\",\"" << text_hex(text) << "\"]";
} else {
auto status = encode_hex(bytes, nil ? nullptr : &output);
std::cout << '[' << int(status) << ",\"" << text_hex(output) << "\",\"" << raw_hex(bytes) << "\"]";
}
} else if (op == "G") {
std::string word;
input >> word;
auto bytes = raw_bytes(word);
auto digest = payload_digest(bytes);
std::cout << '[' << digest << ",\"" << raw_hex(bytes) << "\"]";
} else if (op == "S") {
int value;
input >> value;
const char* result = status_name(static_cast<Status>(value));
std::cout << "[\"" << (result ? text_hex(result) : "NULL") << "\"]";
} else if (op == "F") {
Entry entry;
int present, nil;
std::string word, initial;
input >> present >> entry.stamp.sec >> entry.stamp.nsec >> entry.sequence >> word >> initial >> nil;
entry.present = present;
entry.payload = raw_bytes(word);
auto seed = raw_bytes(initial);
std::string out(seed.begin(), seed.end());
auto status = format_entry(entry, nil ? nullptr : &out);
std::cout << '[' << int(status) << ",\"" << text_hex(out) << "\",";
show_entry(entry);
std::cout << ']';
} else if (op == "W") {
int b, nil;
std::uint32_t ch;
std::int64_t sec, nsec;
std::string word;
input >> b >> ch >> sec >> nsec >> word >> nil;
auto payload = raw_bytes(word);
auto status = book_capture(nil ? nullptr : &books[b], ch, sec, nsec, payload);
std::cout << '[' << int(status) << ",\"" << raw_hex(payload) << "\",";
show_books(books);
std::cout << ']';
} else if (op == "R") {
int b, present, book_nil, out_nil;
std::uint32_t ch;
Entry out;
std::string word;
input >> b >> ch >> present >> out.stamp.sec >> out.stamp.nsec >> out.sequence >> word >> book_nil >> out_nil;
out.present = present;
out.payload = raw_bytes(word);
auto status = book_snapshot(book_nil ? nullptr : &books[b], ch, out_nil ? nullptr : &out);
std::cout << '[' << int(status) << ',';
show_entry(out);
std::cout << ',';
show_books(books);
std::cout << ']';
} else if (op == "M") {
int b, present;
std::uint32_t ch, sequence;
std::int64_t sec;
std::int32_t nsec;
std::string word;
input >> b >> ch >> present >> sec >> nsec >> sequence >> word;
Entry out;
auto first_status = book_snapshot(&books[b], ch, &out);
out.present = present;
out.stamp.sec = sec;
out.stamp.nsec = nsec;
out.sequence = sequence;
out.payload = raw_bytes(word);
Entry again;
auto second_status = book_snapshot(&books[b], ch, &again);
std::cout << '[' << int(first_status) << ',';
show_entry(out);
std::cout << ',' << int(second_status) << ',';
show_entry(again);
std::cout << ',';
show_books(books);
std::cout << ']';
} else if (op == "X" || op == "Z") {
int b, nil;
std::uint32_t ch;
input >> b >> ch >> nil;
auto status = op == "X" ? book_clear(nil ? nullptr : &books[b], ch) :
book_reset(nil ? nullptr : &books[b]);
std::cout << '[' << int(status) << ',';
show_books(books);
std::cout << ']';
} else if (op == "Q") {
int source, target;
input >> source >> target;
books[target] = books[source];
std::cout << '[';
show_books(books);
std::cout << ']';
}
std::cout << '\n';
}
}