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

91 lines
2.2 KiB
C++

#include "group.hpp"
#include <set>
namespace group {
int validate_config(const Config &config)
{
if (config.width == 0 || config.width > max_width) {
return range;
}
if (config.capacity < config.width || config.capacity > max_capacity) {
return range;
}
return 0;
}
int validate_items(Word ticket, const std::vector<Item> &items)
{
if (items.empty() || items.size() > max_width) {
return invalid;
}
if (ticket == 0 || ticket > max_id) {
return range;
}
for (const Item &item : items) {
if (item.id == 0 || item.id > max_id || item.value > max_value) {
return range;
}
}
std::set<Word> seen;
for (const Item &item : items) {
if (!seen.insert(item.id).second) {
return exists;
}
}
return 0;
}
Word take_count(Word queued, Word width, bool closing)
{
if (width == 0 || width > max_width || queued > max_capacity) {
return 0;
}
const Word available = closing ? queued : (queued / width) * width;
return available < width ? available : width;
}
Word digest_items(const std::vector<Item> &items)
{
Word hash = 14695981039346656037ULL;
for (const Item &item : items) {
const Word fields[2] = {item.id, item.value};
for (Word field : fields) {
for (unsigned shift = 0; shift < 64; shift += 8) {
const Word byte = (field >> shift) & 255;
hash ^= byte;
hash *= 1099511628211ULL;
}
}
}
return hash;
}
Receipt summarize(Word ticket, const std::vector<Item> &items)
{
Receipt result;
result.ticket = ticket;
result.count = items.size();
for (const Item &item : items) {
result.total += item.value;
}
result.digest = digest_items(items);
return result;
}
bool same_items(const std::vector<Item> &left, const std::vector<Item> &right)
{
if (left.size() != right.size()) {
return false;
}
for (std::size_t index = 0; index < left.size(); ++index) {
if (left[index].id != right[index].id) {
return false;
}
if (left[index].value != right[index].value) {
return false;
}
}
return true;
}
}