All MicroEvals
city builder eval
Create MicroEval

city builder eval

Prompt

You are implementing part of a deterministic city-builder simulation in Rust (std only, no crates). All math is integer, iteration order must be stable, and identical inputs must give identical outputs. pub struct Stockpile { pub id: u32, pub pos: (i32, i32), pub wood: u32 } pub struct Hauler { pub id: u32, pub pos: (i32, i32), pub capacity: u32 } pub struct Order { pub id: u32, pub pos: (i32, i32), pub wood_needed: u32 } pub struct Trip { pub hauler: u32, pub from: u32, pub to: u32, pub amount: u32 } pub fn plan_trips(stockpiles: &[Stockpile], haulers: &[Hauler], orders: &[Order]) -> Vec<Trip> Rules: 1. Process orders in ascending id. Inputs may arrive unsorted. 2. For each order, while it still needs wood, a hauler is free and some stockpile has wood: pick the free hauler with the smallest Manhattan distance to the order (tie: lowest id), then the stockpile with wood that minimizes distance(hauler, stockpile) + distance(stockpile, order) (tie: lowest id). The amount is min(hauler capacity, stockpile wood, wood still needed). Each hauler makes at most one trip. Subtract the amount from the stockpile and from the order. 3. Wood is never created or lost: for every stockpile, the sum of its trips is at most its starting wood. 4. Return trips in the order they were planned. Deliver: the code, and unit tests covering unsorted input, ties on both picks, an order that cannot be fully filled, and a conservation check. If any rule is ambiguous, say which and how you resolved it, in at most 3 lines.

Drag to resize
Drag to resize
Tencent logoTencent
Hy3
Drag to resize
Drag to resize