Measure consecutive changes with subtraction in a signed type so decreases remain negative. Work only with supplied input; this does not contact external services or modify input.
Before you start
- Save as recipe.rs and compile with Rust 1.99.0 using: rustc --edition=2021 recipe.rs -o recipe
- Run recipe without any arguments, including help flags, and supply input through stdin.
- Uses only the standard library, with an explicit std::io import. No Cargo, crates, filesystem access, networking, subprocesses, unsafe code or dynamic loading.
- Reads at most 65537 bytes and rejects input exceeding 65536 bytes. Requires strict UTF-8, rejects a leading UTF-8 BOM, and rejects every CR.
- Splits only on LF and discards exactly empty segments. Before numeric classification, rejects more than 100 retained lines or any retained line exceeding 256 UTF-8 bytes. Does not trim, normalize, group or deduplicate.
- Accepts only canonical ASCII decimal integers from 0 through 1000000: no signs, spaces or leading zeroes except the spelling 0.
- Computes each adjacent difference as an i64 subtraction, preserving negative decreases. Empty input and a single value produce {"deltas":[]}.
- Success exits 0 and writes exactly one JSON object followed by a newline, with no stderr. Invalid arguments, invalid input and stdin-read failures exit 2 with no stdout and exactly error: invalid input followed by a newline on stderr, subject to the output-write limitations below.
Build and check
- Save the example as recipe.rs.
- Compile with Rust 1.99.0 using rustc --edition=2021 recipe.rs -o recipe.
- Prepare UTF-8 input.txt following the documented operation-specific conventions.
- Run ./recipe < input.txt.
- Inspect the JSON result. Exit 2 with exactly error: invalid input followed by a newline on stderr and no stdout identifies rejected input or stdin-read failure. Output-write failures may also exit nonzero, without that diagnostic and potentially after partial stdout; these are outside the input-error guarantee.
Limits to understand
- Stdin may block while waiting for data or EOF. The byte bound is not a timeout.
- Memory stores at most 65537 input bytes, 100 retained-line references, 100 i64 values and a small output string. There are at most 99 deltas, each in -1000000..1000000; successful output is at most 904 bytes. Allocation capacities and runtime overhead are additional.
- Successful output reveals the number of adjacent pairs and their signed changes, which may be sensitive. Error diagnostics do not disclose input values.
- Memory-allocation failures and stdout/stderr write or flush failures are outside the input-error guarantee. Output failures can leave partial output; detected stdout failures exit 2 without an additional diagnostic.
Run it
rustc --edition=2021 recipe.rs -o recipe
./recipe < input.txtExample input
5
2
2
9Expected output
{"deltas":[-3,0,7]}
