First 10 rows of rust
| uuidstring | contentstring | content_formatstring | raw_contentstring | taskstring | analysisstring | solutionstring | teststring | full_contentstring | full_content_formatstring |
|---|---|---|---|---|---|---|---|---|---|
| 0bd303b9-999f-4cbc-9256-8305310df239 | /* Write a Rust function `find_sum_pair` that accepts a slice of 32-bit signed integers `ints` and a target sum `target`, and returns `Option<(i32, i32)>` containing the pair of integers from the slice whose sum equals `target`, with the special requirement that the pair chosen m… | code comment | use std::collections::HashMap; fn sum_pairs(ints: &[i32], s: i32) -> Option<(i32, i32)> { let mut seen = HashMap::new(); for &i in ints { if let Some(&val) = seen.get(&(s - i)) { return Some((val, i)); } seen.insert(i, i); } No… |
| Write a Rust function `find_sum_pair` that accepts a slice of 32-bit signed integers `ints` and a target sum `target`, and returns `Option<(i32, i32)>` containing the pair of integers from the slice whose sum equals `target`, with the special requirement that the pair chosen must… |
| The core algorithm uses a hash map to remember values already encountered while iterating through the slice from left to right. For each element `current` at index `i`, we check if `target - current` exists in the map. If it does, then the pair is `(target - current, current)`, a… |
| use std::collections::HashMap; /// Find the first pair of integers in the slice (ordered by the second element's position) /// whose sum equals the target, returning `Some((first, second))` if found. /// If no pair exists, return `None`. pub fn find_sum_pair(ints: &[i32], target… |
| fn main() { // Basic case from example let l1 = [1, 4, 8, 7, 3, 15]; assert_eq!(find_sum_pair(&l1, 8), Some((1, 7))); // Negative numbers and zero let l2 = [1, -2, 3, 0, -6, 1]; assert_eq!(find_sum_pair(&l2, -6), Some((0, -6))); // No pair exists … |
| Write a Rust function `find_sum_pair` that accepts a slice of 32-bit signed integers `ints` and a target sum `target`, and returns `Option<(i32, i32)>` containing the pair of integers from the slice whose sum equals `target`, with the special requirement that the pair chosen must… |
| standard order |
| 1c84582b-2fe4-4c4d-8a73-3ed95f784724 | Write a Rust function `simulate_agent` that takes a `&str` representing a sequence of movement commands for an agent on a 100x100 grid, along with initial coordinates, direction, and a flag indicating whether movement should wrap or reflect at boundaries. The function should pars… | no fence | mod ast; mod parser; #[macro_use] extern crate lazy_static; use ast::Expression; use std::sync::Mutex; use wasm_bindgen::prelude::*; #[cfg(test)] mod tests; /// Provides traits for evaluating a type onto a state, returning the modified /// state. pub trait Evaluate<BBI, T> wh… | Write a Rust function `simulate_agent` that takes a `&str` representing a sequence of movement commands for an agent on a 100x100 grid, along with initial coordinates, direction, and a flag indicating whether movement should wrap or reflect at boundaries. The function should pars… | The solution involves parsing the command string into tokens and processing each command sequentially. For each MOVE command, we need to simulate step-by-step movement when reflection is enabled, because direction can change mid-move when hitting boundaries. For wrapping, we can … | // A point on the 100x100 grid. #[derive(Debug, Clone, Copy, PartialEq, Eq, Hash)] pub struct Coordinates(pub u32, pub u32); // Simulates an agent driven by a command string, returning all visited cells. pub fn simulate_agent( commands: &str, start_x: u32, start_y: u… | fn main() { // Test wrapping: move east 3 steps from (0,0), wrap to 99, 0, 1 let result_wrap = simulate_agent("MOVE 3", 0, 0, "E", true); assert_eq!( result_wrap, vec![ Coordinates(1, 0), Coordinates(2, 0), Coordinat… | Write a Rust function `simulate_agent` that takes a `&str` representing a sequence of movement commands for an agent on a 100x100 grid, along with initial coordinates, direction, and a flag indicating whether movement should wrap or reflect at boundaries. The function should pars… | commented standard order |
| a7f6ac9a-0ae7-489a-956f-9537e48174e9 | /* Write a Rust function that takes two strings of equal length and returns `true` if they are "visually similar" under the following rule: for each pair of corresponding characters (one from each string at the same index), they are considered similar if the two characters are id… | code comment | use proconio::input; fn main() { input! { _: usize, s: String, t: String, } let is_similar = |a: char, b: char| -> bool { a == b || a.min(b) == '1' && a.max(b) == 'l' || a.min(b) == '0' && a.max(b) == 'o' }; let cond = s.chars… | Write a Rust function that takes two strings of equal length and returns `true` if they are "visually similar" under the following rule: for each pair of corresponding characters (one from each string at the same index), they are considered similar if the two characters are ident… | The core logic is a pairwise comparison of characters from the two input strings. We first check if the lengths differ; if so, return `false` immediately. Otherwise, iterate over both strings simultaneously using `zip` on their character iterators. For each pair `(a, b)`, determi… | // Returns true if two strings are visually similar under the 1/l and 0/o confusion rules. pub fn are_visually_similar(a: &str, b: &str) -> bool { // Different lengths cannot be similar (guaranteed equal length in the problem, but safe check). if a.len() != b.len() { … | fn main() { assert_eq!(are_visually_similar("hello", "he11o"), false); // 'e' vs '1'? Wait, this is wrong. Let's test correct cases. assert!(are_visually_similar("hello", "he11o") == false); // 'e' vs '1' is not similar, so false assert!(are_visually_similar("1", "l")… | // Write a Rust function that takes two strings of equal length and returns `true` if they are "visually similar" under the following rule: for each pair of corresponding characters (one from each string at the same index), they are considered similar if the two characters are id… | commented standard order |
| 7883502d-f417-43e7-978d-c1e8cc40d6d8 | Write a Rust function `lagoon_area` that takes a multi-line string input, where each line describes a digging instruction in the format `DIRECTION LENGTH (#COLOR)` (e.g., `R 6 (#70c710)`). Part 1 uses the direction (`U`, `D`, `L`, `R`) and integer length. Part 2 uses the hex colo… | markdown | use common::day::Day; use util::grid2d::{Coords, Direction}; pub struct Day18 {} impl Day for Day18 { fn star1(&self, input: &str) -> String { let instrs: Vec<_> = input.lines().map(Instruction::parse_pt1).collect(); area(&instrs).to_string() } fn s… | Write a Rust function `lagoon_area` that takes a multi-line string input, where each line describes a digging instruction in the format `DIRECTION LENGTH (#COLOR)` (e.g., `R 6 (#70c710)`). Part 1 uses the direction (`U`, `D`, `L`, `R`) and integer length. Part 2 uses the hex colo… | The problem is a classic application of the shoelace formula and Pick's theorem. For a given set of axis-aligned digging instructions, we can compute the area of the polygon's interior using the shoelace formula on the vertices. The shoelace formula (`area_shoelace`) computes `1/… | // Compute the total area (including boundary) for a list of digging instructions. // For part 1, direction and length are taken directly from the first two fields. pub fn lagoon_area_part1(input: &str) -> i64 { let mut x: i64 = 0; let mut y: i64 = 0; let mut sum_cros… | fn main() { let input = r#"R 6 (#70c710) D 5 (#0dc571) L 2 (#5713f0) D 2 (#d2c081) R 2 (#59c680) D 2 (#411b91) L 5 (#8ceee2) U 2 (#caa173) L 1 (#1b58a2) U 2 (#caa171) R 2 (#7807d2) U 3 (#a77fa3) L 2 (#015232) U 2 (#7a21e3)"#; assert_eq!(lagoon_area_part1(input), 62); … | // Write a Rust function `lagoon_area` that takes a multi-line string input, where each line describes a digging instruction in the format `DIRECTION LENGTH (#COLOR)` (e.g., `R 6 (#70c710)`). Part 1 uses the direction (`U`, `D`, `L`, `R`) and integer length. Part 2 uses the hex c… | test-first order |
| 903fcf49-99f6-498a-bdbb-82f148be772b | Write a Rust function named `count_prime_arrangements` that takes an integer `n` (where `1 <= n <= 100`) and returns the number of permutations of the numbers from `1` to `n` such that prime numbers are placed at prime indices (1-indexed) and composite numbers (and `1`, which is … | markdown | pub fn num_prime_arrangements(n: i32) -> i32 { let m: i64 = 1_000_000_007; let primes: [i32; 25] = [ 2, 3, 5, 7, 11, 13, 17, 19, 23, 29, 31, 37, 41, 43, 47, 53, 59, 61, 67, 71, 73, 79, 83, 89, 97, ]; let factorial_mod = |n: i32| -> i64 { (2..=n as… | Write a Rust function named `count_prime_arrangements` that takes an integer `n` (where `1 <= n <= 100`) and returns the number of permutations of the numbers from `1` to `n` such that prime numbers are placed at prime indices (1-indexed) and composite numbers (and `1`, which is … | The problem reduces to counting permutations where primes occupy only prime positions and non-primes occupy only non-prime positions. The number of such permutations is the product of two factorials: (number of primes ≤ n)! for arranging primes among prime positions, and (number … | // Count permutations of 1..=n where primes occupy prime indices and non-primes occupy non-prime indices, modulo 1_000_000_007. pub fn count_prime_arrangements(n: i32) -> i32 { const MOD: i64 = 1_000_000_007; // All primes up to 100, the maximum n. const PRIMES: [i32;… | fn main() { // Base cases assert_eq!(count_prime_arrangements(1), 1); assert_eq!(count_prime_arrangements(2), 1); assert_eq!(count_prime_arrangements(3), 2); // primes: {2,3} at positions 2,3 -> 2! * 1! = 2 assert_eq!(count_prime_arrangements(4), 2); // primes… | /* Write a Rust function named `count_prime_arrangements` that takes an integer `n` (where `1 <= n <= 100`) and returns the number of permutations of the numbers from `1` to `n` such that prime numbers are placed at prime indices (1-indexed) and composite numbers (and `1`, which … | solution-first order |
| d175aa8b-f17d-4767-a1ac-79068b1c9b94 | /* Write a Rust function named `simulate_tile_agents` that simulates a stochastic tile-drawing process inspired by Turing drawings. The function should take three parameters: `tile_size` (a `u32` representing the square tile dimensions), `restarts` (a `usize` controlling the numb… | code comment | // Inspired by the original "turing drawings": // https://github.com/maximecb/Turing-Drawings/blob/master/programs.js#L44-L48 use image::{imageops, Luma}; use rand::{thread_rng, Rng}; mod tile; use tile::TILE_SIZE; const RESTARTS: usize = 1_000_000; const ITERATIONS: usize = 1… | Write a Rust function named `simulate_tile_agents` that simulates a stochastic tile-drawing process inspired by Turing drawings. The function should take three parameters: `tile_size` (a `u32` representing the square tile dimensions), `restarts` (a `usize` controlling the number … | The core simulation loops over `restarts`, each time creating a fresh random LUT (an array of 62 `u8` values generated via `rand::thread_rng().gen()`). For each restart, it performs `iterations` steps. In each step: read the current tile value (as boolean, convert to `u8`), compu… | use rand::{thread_rng, Rng}; /// Simulates a stochastic tile-drawing process with an agent on a toroidal grid. /// Returns a tuple: (binary tile map as row-major Vec<bool>, heatmap as Vec<f32>). /// The tile map persists across restarts; the agent starts at center with state 0. … | fn main() { // Basic test: small tile, few restarts, check dimensions and ranges let (tile, heatmap) = simulate_tile_agents(4, 10, 5); assert_eq!(tile.len(), 16); assert_eq!(heatmap.len(), 16); assert!(heatmap.iter().all(|&v| v >= 0.0 && v <= 5.0)); // max 0.1… | Write a Rust function named `simulate_tile_agents` that simulates a stochastic tile-drawing process inspired by Turing drawings. The function should take three parameters: `tile_size` (a `u32` representing the square tile dimensions), `restarts` (a `usize` controlling the number … | test-first order |
| f59c65c1-e7c9-40f8-9b47-083c97ddfd1a | /* Implement a Rust function named `zobrist_hash` that takes a square board size `n` (where `n >= 1`) and a slice of `(usize, usize, u8)` tuples representing stone placements on an `n x n` board. Each tuple contains `(row, col, stone)` where stone is `0` for Empty, `1` for Black,… | code comment | extern crate rand; use std::ops::BitXor; use std::ops::Rem; use rand::Rng; use go::VIRT_LEN; use go::VIRT_SIZE; use go::GoGame; use go::Vertex; use go::Stone; use go::stone; #[derive(Copy, Clone, Eq, PartialEq, Hash, Debug)] pub struct PosHash(u64); impl BitXor for PosHash { … | Implement a Rust function named `zobrist_hash` that takes a square board size `n` (where `n >= 1`) and a slice of `(usize, usize, u8)` tuples representing stone placements on an `n x n` board. Each tuple contains `(row, col, stone)` where stone is `0` for Empty, `1` for Black, an… | The solution approach involves creating a fixed lookup table of random 64-bit values for every possible combination of stone type and board position. Since the board is `n x n`, we need `3 * n * n` random values (one for Empty, Black, and White at each position). To ensure determ… | // Compute a deterministic Zobrist hash for a board of size n x n given placements. pub fn zobrist_hash(n: usize, placements: &[(usize, usize, u8)]) -> u64 { // Fixed seed for deterministic random generation. let mut seed: u64 = 0x9E3779B97F4A7C15; // Simple xorshift… | fn main() { // Empty board gives hash 0. assert_eq!(zobrist_hash(3, &[]), 0); // Single black stone at (0,0). let h1 = zobrist_hash(2, &[(0, 0, 1)]); assert_ne!(h1, 0); // Same input gives same hash (deterministic). let h2 = zobrist_hash(2, &[(0, 0, … | // Implement a Rust function named `zobrist_hash` that takes a square board size `n` (where `n >= 1`) and a slice of `(usize, usize, u8)` tuples representing stone placements on an `n x n` board. Each tuple contains `(row, col, stone)` where stone is `0` for Empty, `1` for Black,… | commented standard order |
| 84b70f57-1a02-4286-bb11-97f7726299da | Implement a Rust function named `decode_shares` that takes a vector of `Share<D>` structs where `D` is a field element type implementing the `FieldElement` trait. Each share contains an x-coordinate and a vector of y-values, where each y-value was sampled from a separate polynomi… | markdown | use std::iter::zip; use crate::fields::FieldElement; #[derive(Debug, Clone)] pub struct Share<D: FieldElement> { pub x: D, pub y: Vec<D>, } /// datum: the field element to encode /// xs: the x values at which to sample from the polynomial /// k: the number of shares ne… | Implement a Rust function named `decode_shares` that takes a vector of `Share<D>` structs where `D` is a field element type implementing the `FieldElement` trait. Each share contains an x-coordinate and a vector of y-values, where each y-value was sampled from a separate polynomi… | The solution uses Lagrange interpolation at x=0 for each message position independently. For a given set of distinct x-coordinates `{x_i}`, the Lagrange basis polynomial evaluated at 0 for point `x_i` is: `L_i(0) = (∏_{j≠i} x_j) / (∏_{j≠i} (x_j - x_i))`. The polynomial's value at… | use std::collections::HashSet; use std::hash::Hash; // Reconstruct original data from shares using Lagrange interpolation at x=0. pub fn decode_shares<D: FieldElement>(shares: Vec<Share<D>>) -> Option<Vec<D>> { if shares.is_empty() { return None; } let xs: Ve… | fn main() { // Define a simple test field: modular arithmetic mod 7 (implemented minimal for testing) #[derive(Debug, Clone, PartialEq, Eq, Hash)] struct Mod7(i32); impl FieldElement for Mod7 { const ZERO: Self = Mod7(0); fn sample_n_others(&self, … | // Implement a Rust function named `decode_shares` that takes a vector of `Share<D>` structs where `D` is a field element type implementing the `FieldElement` trait. Each share contains an x-coordinate and a vector of y-values, where each y-value was sampled from a separate polyn… | commented standard order |
| 624751ca-6b46-42d9-8e24-a91477bcdf16 | "Write a standalone Rust function named `octree_point_count` that simulates a simplified fixed-depth | no fence | "use std::{\n collections::HashMap,\n ops::{Add, AddAssign, Div, DivAssign, Mul, MulAssign, Su | "Write a standalone Rust function named `octree_point_count` that simulates a simplified fixed-depth | "The solution models the octree as a recursive structure. The main algorithm: define a recursive hel | "/// Count the number of non-empty leaf octants after inserting all valid points.\npub fn octree_poi | "fn main() {\n // Basic: all points fit in root leaf without splitting (threshold large).\n le | "// Write a standalone Rust function named `octree_point_count` that simulates a simplified fixed-de | test-first order |
| 6753f401-30a9-44be-934d-322b84e39bc7 | "/*\nWrite a Rust function named `hex_floor_black_tiles` that processes a list of directional moveme | code comment | "use nom::{branch::alt, bytes::complete::tag, multi::fold_many1, IResult};\nuse std::collections::Ha | "Write a Rust function named `hex_floor_black_tiles` that processes a list of directional movement s | "The problem requires handling a hex grid with axial coordinates. A convenient coordinate system use | "use std::collections::{HashMap, HashSet};\n\n// Count black tiles after 100 generations of simulati | "fn main() {\n // Test 1: Single tile\n assert_eq!(hex_floor_black_tiles(&[\"e\"]), 0); // fli | "/*\nWrite a Rust function named `hex_floor_black_tiles` that processes a list of directional moveme | solution-first order |