wip: shield index relations, dev evaluation tasks, Q-063 audit notes
Verifier borrow/provenance work, new phase3 shield_index conformance cases, dev-intervals/dev-lru/dev-shards tasks with evaluate.py harness, and agent skill/hook config.
This commit is contained in:
1 parent
2d750a0525
commit
e3fc896a0a
68 files changed
+2132
-37
No files matched your search
@@ -0,0 +1,6 @@
|
||||
[package]
|
||||
name = "intervals"
|
||||
version = "0.1.0"
|
||||
edition = "2021"
|
||||
|
||||
[dependencies]
|
||||
@@ -0,0 +1,55 @@
|
||||
use std::collections::BTreeMap;
|
||||
use std::io::{Read, Write};
|
||||
|
||||
const LIMIT: u64 = 1 << 63;
|
||||
|
||||
fn number(t: &str) -> Option<u64> {
|
||||
if t.is_empty() || !t.bytes().all(|b| b.is_ascii_digit()) || (t.len() > 1 && t.starts_with('0')) || t.len() > 19 {
|
||||
return None;
|
||||
}
|
||||
t.parse::<u64>().ok().filter(|&v| v < LIMIT)
|
||||
}
|
||||
|
||||
fn main() {
|
||||
let mut input = String::new();
|
||||
std::io::stdin().read_to_string(&mut input).unwrap();
|
||||
let mut lines: Vec<&str> = input.split('\n').collect();
|
||||
if input.ends_with('\n') || input.is_empty() {
|
||||
lines.pop();
|
||||
}
|
||||
let mut set: BTreeMap<u64, u64> = BTreeMap::new(); // start -> end, disjoint, non-touching
|
||||
let mut out = String::new();
|
||||
for line in lines {
|
||||
let parts: Vec<&str> = line.split(' ').collect();
|
||||
let nums: Option<Vec<u64>> = parts[1..].iter().map(|t| number(t)).collect();
|
||||
let Some(nums) = nums else { out.push_str("error\n"); continue };
|
||||
match (parts[0], nums.as_slice()) {
|
||||
("add", &[a, b]) | ("remove", &[a, b]) if a < b => {
|
||||
let (mut a2, mut b2) = (a, b);
|
||||
let hit: Vec<(u64, u64)> = set.range(..=b).filter(|&(_, &y)| y >= a).map(|(&x, &y)| (x, y)).collect();
|
||||
for (x, y) in hit {
|
||||
set.remove(&x);
|
||||
if parts[0] == "add" {
|
||||
a2 = a2.min(x);
|
||||
b2 = b2.max(y);
|
||||
} else {
|
||||
if x < a { set.insert(x, a); }
|
||||
if y > b { set.insert(b, y); }
|
||||
}
|
||||
}
|
||||
if parts[0] == "add" { set.insert(a2, b2); }
|
||||
}
|
||||
("covered", &[x]) => out.push_str(if set.range(..=x).next_back().map_or(false, |(_, &y)| x < y) { "yes\n" } else { "no\n" }),
|
||||
("count", &[]) => out.push_str(&format!("{}\n", set.len())),
|
||||
("total", &[]) => out.push_str(&format!("{}\n", set.iter().map(|(x, y)| y - x).sum::<u64>())),
|
||||
("list", &[]) => {
|
||||
let s: Vec<String> = set.iter().map(|(x, y)| format!("{x}-{y}")).collect();
|
||||
out.push_str(if s.is_empty() { "empty" } else { "" });
|
||||
out.push_str(&s.join(" "));
|
||||
out.push('\n');
|
||||
}
|
||||
_ => out.push_str("error\n"),
|
||||
}
|
||||
}
|
||||
std::io::stdout().write_all(out.as_bytes()).unwrap();
|
||||
}
|
||||
@@ -0,0 +1,19 @@
|
||||
#!/bin/sh
|
||||
# Public test: the example from the task statement.
|
||||
cargo build -q --offline || { echo "FAIL: build"; exit 1; }
|
||||
got=$(printf '%s' 'add 10 20
|
||||
add 20 25
|
||||
covered 24
|
||||
remove 12 14
|
||||
list
|
||||
count
|
||||
total
|
||||
add 5 5
|
||||
' | ./target/debug/intervals) || { echo "FAIL: the program exited with an error"; exit 1; }
|
||||
expected=$(printf "%s" 'yes
|
||||
10-12 14-25
|
||||
2
|
||||
13
|
||||
error
|
||||
')
|
||||
if [ "$got" = "$expected" ]; then echo PASS; else echo "FAIL"; echo "--- expected"; printf '%s' "$expected"; echo "--- got"; printf '%s' "$got"; exit 1; fi
|
||||
Reference in new issue
Block a user