Prototype maps transform sequentially in input order. Final maps using at most min(workers,input size) background std::threads, preserves output order and invokes transform exactly once per value on a successful call. workers<=0 throws invalid_argument even for empty input. Empty input invokes no callback. Transform is callable and safe for concurrent use; it may throw. Capture a failure, join ALL started threads, and rethrow a callback exception on the caller thread; no partial result is returned. Input remains unchanged. Do not detach threads. Already performed callback side effects are outside rollback. Standard threads/mutex/atomics only; no wall-clock-dependent result rules.

C++ contract conventions: numeric values use signed Int (long long); all inputs and intermediate arithmetic are within its representable range. Opt<T> means std::optional<T> and absence is std::nullopt; Vec<T> means std::vector<T>. Invalid documented arguments throw std::invalid_argument. Inputs passed by const reference remain caller owned. Returned containers and records own their contents. No runtime type coercion is required; C++ static types exclude many dynamic-language type errors. Unless a lesson states otherwise, string ordering is lexicographic over Unicode code points (Text) or UTF-8 identifiers (std::string).

cpp

inline Vec<Int> prototype(const Vec<Int>& values,const std::function<Int(Int)>& transform);
inline Vec<Int> solve(const Vec<Int>& values,Int workers,const std::function<Int(Int)>& transform);

Compile and run from this directory:

Shell
c++ -std=c++20 -O2 -Wall -Wextra -pedantic -pthread main.cpp -o practice
./practice --stage prototype
./practice --stage final

Edit exercise.hpp. Both stages start unfinished and must report failures until implemented. Keep main.cpp as the executable contract. The runner returns nonzero for a failed check, an unexpected exception, an invalid stage, or an empty suite. C++20 and only the standard library are required.

Drag or use the arrow keys to resize. Home collapses the question; End collapses the editor. Enter or double-click resets the split.
Loading editor…
No results yet.

Complete the starter code, then run the checks.
Results and errors will appear here.

C++ runtime powered by Wasmer.