Dataset Viewer
Auto-converted to Parquet Duplicate
id
stringlengths
18
18
chunk_id
stringlengths
16
16
repo
stringclasses
6 values
repo_url
stringclasses
6 values
commit
stringclasses
6 values
license
stringclasses
4 values
path
stringlengths
10
68
kind
stringclasses
1 value
name
stringlengths
5
44
context
stringlengths
10
68
start_line
int32
1
1
end_line
int32
3
1.42k
num_lines
int32
3
1.42k
question
stringlengths
133
1.46k
answer
stringlengths
44
54.5k
model
stringclasses
1 value
fe41c1b7152c17a4-0
fe41c1b7152c17a4
TheAlgorithms/Rust
https://github.com/TheAlgorithms/Rust
fed66cb0c74c4a939ec5163648458a8c2b46fd4c
MIT
src/backtracking/graph_coloring.rs
file
graph_coloring.rs
src/backtracking/graph_coloring.rs
1
370
370
I need a Rust module that generates all valid colorings of a graph represented by an adjacency matrix. The implementation should use backtracking to assign colors from 0 to num_colors-1 to each vertex, ensuring no two adjacent vertices share the same color (checking both adjacency_matrix[i][j] and adjacency_matrix[j][i...
//! This module provides functionality for generating all possible colorings of a undirected (or directed) graph //! given a certain number of colors. It includes the GraphColoring struct and methods //! for validating color assignments and finding all valid colorings. /// Represents potential errors when coloring on ...
nvidia/nemotron-3.5-lightning-30b-a3b
e3d9fc4214373c94-0
e3d9fc4214373c94
TheAlgorithms/Rust
https://github.com/TheAlgorithms/Rust
fed66cb0c74c4a939ec5163648458a8c2b46fd4c
MIT
src/backtracking/hamiltonian_cycle.rs
file
hamiltonian_cycle.rs
src/backtracking/hamiltonian_cycle.rs
1
310
310
I need a Rust module for finding a Hamiltonian cycle in a directed or undirected graph represented by an adjacency matrix. The module should expose an error enum with variants for empty/malformed matrices and out-of-bounds start vertices, a `Graph` struct wrapping the adjacency matrix, and a public function that takes ...
//! This module provides functionality to find a Hamiltonian cycle in a directed or undirected graph. //! Source: [Wikipedia](https://en.wikipedia.org/wiki/Hamiltonian_path_problem) /// Represents potential errors when finding hamiltonian cycle on an adjacency matrix. #[derive(Debug, PartialEq, Eq)] pub enum FindHamil...
nvidia/nemotron-3.5-lightning-30b-a3b
0ef042b601d34e7f-0
0ef042b601d34e7f
TheAlgorithms/Rust
https://github.com/TheAlgorithms/Rust
fed66cb0c74c4a939ec5163648458a8c2b46fd4c
MIT
src/backtracking/permutations.rs
file
permutations.rs
src/backtracking/permutations.rs
1
141
141
I need a Rust function `permute` that generates all distinct permutations of a vector of integers. The function should sort the input vector first to handle duplicates effectively, then use a recursive backtracking algorithm that tracks which elements have been used and skips over duplicate values when the previous ide...
//! This module provides a function to generate all possible distinct permutations //! of a given collection of integers using a backtracking algorithm. /// Generates all possible distinct permutations of a given vector of integers. /// /// # Arguments /// /// * `nums` - A vector of integers. The input vector is sorte...
nvidia/nemotron-3.5-lightning-30b-a3b
17bd026994000658-0
17bd026994000658
TheAlgorithms/Rust
https://github.com/TheAlgorithms/Rust
fed66cb0c74c4a939ec5163648458a8c2b46fd4c
MIT
src/backtracking/mod.rs
file
mod.rs
src/backtracking/mod.rs
1
21
21
I need a Rust module that declares several backtracking algorithm submodules and re-exports their public functions. The module should define submodules named all_combination_of_size_k, graph_coloring, hamiltonian_cycle, knight_tour, n_queens, parentheses_generator, permutations, rat_in_maze, subset_sum, and sudoku. It ...
mod all_combination_of_size_k; mod graph_coloring; mod hamiltonian_cycle; mod knight_tour; mod n_queens; mod parentheses_generator; mod permutations; mod rat_in_maze; mod subset_sum; mod sudoku; pub use all_combination_of_size_k::generate_all_combinations; pub use graph_coloring::generate_colorings; pub use hamiltonia...
nvidia/nemotron-3.5-lightning-30b-a3b
025753790b6f4339-0
025753790b6f4339
TheAlgorithms/Rust
https://github.com/TheAlgorithms/Rust
fed66cb0c74c4a939ec5163648458a8c2b46fd4c
MIT
src/backtracking/n_queens.rs
file
n_queens.rs
src/backtracking/n_queens.rs
1
221
221
I need a Rust module that solves the N-Queens problem using backtracking. The module should define a public function `n_queens_solver(n: usize) -> Vec<Vec<String>>` that returns all distinct solutions for an `n×n` board, where each solution is a vector of strings representing rows with `'Q'` for queens and `'.'` for em...
//! This module provides functionality to solve the N-Queens problem. //! //! The N-Queens problem is a classic chessboard puzzle where the goal is to //! place N queens on an NxN chessboard so that no two queens threaten each //! other. Queens can attack each other if they share the same row, column, or //! diagonal. ...
nvidia/nemotron-3.5-lightning-30b-a3b
095318a5152a36f4-0
095318a5152a36f4
TheAlgorithms/Rust
https://github.com/TheAlgorithms/Rust
fed66cb0c74c4a939ec5163648458a8c2b46fd4c
MIT
src/backtracking/all_combination_of_size_k.rs
file
all_combination_of_size_k.rs
src/backtracking/all_combination_of_size_k.rs
1
123
123
I need a Rust module that generates all possible combinations of `k` numbers chosen from the range `0` to `n-1` using a backtracking algorithm. The module should define a public error enum `CombinationError` with two variants: `KGreaterThanN` and `InvalidZeroRange`. Provide a public function `generate_all_combinations(...
//! This module provides a function to generate all possible combinations //! of `k` numbers out of `0...n-1` using a backtracking algorithm. /// Custom error type for combination generation. #[derive(Debug, PartialEq)] pub enum CombinationError { KGreaterThanN, InvalidZeroRange, } /// Generates all possible ...
nvidia/nemotron-3.5-lightning-30b-a3b
9062a572e1244df7-0
9062a572e1244df7
TheAlgorithms/Rust
https://github.com/TheAlgorithms/Rust
fed66cb0c74c4a939ec5163648458a8c2b46fd4c
MIT
src/backtracking/sudoku.rs
file
sudoku.rs
src/backtracking/sudoku.rs
1
164
164
I need a Rust module that implements a Sudoku solver using the backtracking algorithm. The module should expose a public function `sudoku_solver` that accepts a `&[[u8; 9]; 9]` and returns `Option<[[u8; 9]; 9]>`, returning the solved board or `None` if unsolvable. Additionally, define a `SudokuSolver` struct with a `bo...
//! A Rust implementation of Sudoku solver using Backtracking. //! //! This module provides functionality to solve Sudoku puzzles using the backtracking algorithm. //! //! GeeksForGeeks: [Sudoku Backtracking](https://www.geeksforgeeks.org/sudoku-backtracking-7/) /// Solves a Sudoku puzzle. /// /// Given a partially fi...
nvidia/nemotron-3.5-lightning-30b-a3b
99fbf83e1ab99c58-0
99fbf83e1ab99c58
TheAlgorithms/Rust
https://github.com/TheAlgorithms/Rust
fed66cb0c74c4a939ec5163648458a8c2b46fd4c
MIT
src/backtracking/subset_sum.rs
file
subset_sum.rs
src/backtracking/subset_sum.rs
1
55
55
I need a Rust function `has_subset_with_sum` that determines if a subset of a given slice of `isize` integers adds up to a target `isize`. The function should use recursive backtracking: at each step, it either skips the current element or includes it by subtracting it from the target. A helper function `backtrack` sho...
//! This module provides functionality to check if there exists a subset of a given set of integers //! that sums to a target value. The implementation uses a recursive backtracking approach. /// Checks if there exists a subset of the given set that sums to the target value. pub fn has_subset_with_sum(set: &[isize], t...
nvidia/nemotron-3.5-lightning-30b-a3b
32de02c803b75dbf-0
32de02c803b75dbf
TheAlgorithms/Rust
https://github.com/TheAlgorithms/Rust
fed66cb0c74c4a939ec5163648458a8c2b46fd4c
MIT
src/big_integer/fast_factorial.rs
file
fast_factorial.rs
src/big_integer/fast_factorial.rs
1
87
87
I need a Rust function `fast_factorial` that computes the factorial of a non-negative integer `n` using Peter Borwein's 1985 algorithm. The input is a `usize` and the output is a `num_bigint::BigUint`. The algorithm should first generate all primes up to `n` using a function `sieve_of_eratosthenes`. Then, for each prim...
// Algorithm created by Peter Borwein in 1985 // https://doi.org/10.1016/0196-6774(85)90006-9 use crate::math::sieve_of_eratosthenes; use num_bigint::BigUint; use num_traits::One; use std::collections::BTreeMap; /// Calculate the sum of n / p^i with integer division for all values of i fn index(p: usize, n: usize) ->...
nvidia/nemotron-3.5-lightning-30b-a3b
060d812d7a308209-0
060d812d7a308209
TheAlgorithms/Rust
https://github.com/TheAlgorithms/Rust
fed66cb0c74c4a939ec5163648458a8c2b46fd4c
MIT
src/backtracking/knight_tour.rs
file
knight_tour.rs
src/backtracking/knight_tour.rs
1
195
195
Write a Rust module for the Knight's Tour problem using backtracking. The module must export a function `find_knight_tour(size_x: usize, size_y: usize, start_x: usize, start_y: usize) -> Option<Vec<Vec<usize>>>` that returns a board matrix of move orders, or `None` if no tour exists. Include a `KnightTour` struct with ...
//! This module contains the implementation of the Knight's Tour problem. //! //! The Knight's Tour is a classic chess problem where the objective is to move a knight to every square on a chessboard exactly once. /// Finds the Knight's Tour starting from the specified position. /// /// # Arguments /// /// * `size_x` -...
nvidia/nemotron-3.5-lightning-30b-a3b
4710d1a963b9ea27-0
4710d1a963b9ea27
TheAlgorithms/Rust
https://github.com/TheAlgorithms/Rust
fed66cb0c74c4a939ec5163648458a8c2b46fd4c
MIT
src/bit_manipulation/counting_bits.rs
file
counting_bits.rs
src/bit_manipulation/counting_bits.rs
1
54
54
I need a Rust function that counts the number of set bits (1s) in the binary representation of an unsigned integer using Brian Kernighan's algorithm. The function should accept a usize and return a usize. It should iteratively clear the least significant set bit via n &= n - 1 until n is zero, running in O(k) time wher...
//! This module implements a function to count the number of set bits (1s) //! in the binary representation of an unsigned integer. //! It uses Brian Kernighan's algorithm, which efficiently clears the least significant //! set bit in each iteration until all bits are cleared. //! The algorithm runs in O(k), where k is...
nvidia/nemotron-3.5-lightning-30b-a3b
f37c8db473350605-0
f37c8db473350605
TheAlgorithms/Rust
https://github.com/TheAlgorithms/Rust
fed66cb0c74c4a939ec5163648458a8c2b46fd4c
MIT
src/bit_manipulation/highest_set_bit.rs
file
highest_set_bit.rs
src/bit_manipulation/highest_set_bit.rs
1
52
52
I need a Rust function named `find_highest_set_bit` that accepts a `usize` and returns `Option<usize>`. The function should find the position of the most significant bit set to 1 using 0-based indexing. If the input is 0, it should return `None`. The implementation should use a simple loop that right-shifts the number ...
//! This module provides a function to find the position of the most significant bit (MSB) //! set to 1 in a given positive integer. /// Finds the position of the highest (most significant) set bit in a positive integer. /// /// # Arguments /// /// * `num` - An integer value for which the highest set bit will be deter...
nvidia/nemotron-3.5-lightning-30b-a3b
824ca5bbfbf41e32-0
824ca5bbfbf41e32
TheAlgorithms/Rust
https://github.com/TheAlgorithms/Rust
fed66cb0c74c4a939ec5163648458a8c2b46fd4c
MIT
src/backtracking/parentheses_generator.rs
file
parentheses_generator.rs
src/backtracking/parentheses_generator.rs
1
76
76
I need a Rust implementation that generates every valid combination of well-formed parentheses for a given non-negative integer n using a backtracking approach. The solution should expose a function generate_parentheses(n: usize) -> Vec<String> that returns all possible strings of n pairs of parentheses. I'd also like ...
/// Generates all combinations of well-formed parentheses given a non-negative integer `n`. /// /// This function uses backtracking to generate all possible combinations of well-formed /// parentheses. The resulting combinations are returned as a vector of strings. /// /// # Arguments /// /// * `n` - A non-negative int...
nvidia/nemotron-3.5-lightning-30b-a3b
f866ecdd366ffd1d-0
f866ecdd366ffd1d
TheAlgorithms/Rust
https://github.com/TheAlgorithms/Rust
fed66cb0c74c4a939ec5163648458a8c2b46fd4c
MIT
src/big_integer/poly1305.rs
file
poly1305.rs
src/big_integer/poly1305.rs
1
98
98
Write a Rust function/module for Poly1305 MAC using `num_bigint` and `num_traits`, following RFC8439, with key setup, message processing, and tag output.
use num_bigint::BigUint; use num_traits::Num; use num_traits::Zero; macro_rules! hex_uint { ($a:literal) => { BigUint::from_str_radix($a, 16).unwrap() }; } /** * Poly1305 Message Authentication Code: * This implementation is based on RFC8439. * Note that the Big Integer library we are using may not...
nvidia/nemotron-3.5-lightning-30b-a3b
6ef07d6e3e430990-0
6ef07d6e3e430990
TheAlgorithms/Rust
https://github.com/TheAlgorithms/Rust
fed66cb0c74c4a939ec5163648458a8c2b46fd4c
MIT
src/bit_manipulation/n_bits_gray_code.rs
file
n_bits_gray_code.rs
src/bit_manipulation/n_bits_gray_code.rs
1
75
75
I need a Rust function named `generate_gray_code` that takes a `usize` for the number of bits and returns `Result<Vec<String>, GrayCodeError>`. The function should generate an n-bit Gray code sequence using the direct binary formula, return an error if the bit count is zero, and produce a `Vec<String>` where each strin...
/// Custom error type for Gray code generation. #[derive(Debug, PartialEq)] pub enum GrayCodeError { ZeroBitCount, } /// Generates an n-bit Gray code sequence using the direct Gray code formula. /// /// # Arguments /// /// * `n` - The number of bits for the Gray code. /// /// # Returns /// /// A vector of Gray cod...
nvidia/nemotron-3.5-lightning-30b-a3b
6d634f297152a833-0
6d634f297152a833
TheAlgorithms/Rust
https://github.com/TheAlgorithms/Rust
fed66cb0c74c4a939ec5163648458a8c2b46fd4c
MIT
src/bit_manipulation/sum_of_two_integers.rs
file
sum_of_two_integers.rs
src/bit_manipulation/sum_of_two_integers.rs
1
55
55
I need a Rust function named `add_two_integers` that adds two `isize` integers using only bitwise XOR and AND operations, without using the `+` operator. The function should simulate ripple-carry addition: compute the sum portion with XOR and the carry with AND left-shifted, then repeat with the carry until it becomes ...
//! This module provides a function to add two integers without using the `+` operator. //! It relies on bitwise operations (XOR and AND) to compute the sum, simulating the addition process. /// Adds two integers using bitwise operations. /// /// # Arguments /// /// * `a` - The first integer to be added. /// * `b` - T...
nvidia/nemotron-3.5-lightning-30b-a3b
d6bf5843d57211bb-0
d6bf5843d57211bb
TheAlgorithms/Rust
https://github.com/TheAlgorithms/Rust
fed66cb0c74c4a939ec5163648458a8c2b46fd4c
MIT
src/ciphers/rail_fence.rs
file
rail_fence.rs
src/ciphers/rail_fence.rs
1
41
41
I need a Rust implementation of the rail fence cipher. Please write `rail_fence_encrypt(plain_text: &str, key: usize) -> String` and `rail_fence_decrypt(cipher: &str, key: usize) -> String`, plus a `zigzag` helper iterator. The cipher should write characters in a zigzag pattern across `key` rails and read them off sequ...
// wiki: https://en.wikipedia.org/wiki/Rail_fence_cipher pub fn rail_fence_encrypt(plain_text: &str, key: usize) -> String { let mut cipher = vec![Vec::new(); key]; for (c, i) in plain_text.chars().zip(zigzag(key)) { cipher[i].push(c); } return cipher.iter().flatten().collect::<String>(); } p...
nvidia/nemotron-3.5-lightning-30b-a3b
f045284c2dc0dabf-0
f045284c2dc0dabf
TheAlgorithms/Rust
https://github.com/TheAlgorithms/Rust
fed66cb0c74c4a939ec5163648458a8c2b46fd4c
MIT
src/big_integer/mod.rs
file
mod.rs
src/big_integer/mod.rs
1
9
9
Write a Rust module file for a big_integer module that conditionally compiles only when the `big-math` feature is enabled, declares three submodules (`fast_factorial`, `multiply`, `poly1305`), and re-exports their public `fast_factorial` function, `multiply` function, and `Poly1305` type.
#![cfg(feature = "big-math")] mod fast_factorial; mod multiply; mod poly1305; pub use self::fast_factorial::fast_factorial; pub use self::multiply::multiply; pub use self::poly1305::Poly1305;
nvidia/nemotron-3.5-lightning-30b-a3b
3dac988b6b26a7fc-0
3dac988b6b26a7fc
TheAlgorithms/Rust
https://github.com/TheAlgorithms/Rust
fed66cb0c74c4a939ec5163648458a8c2b46fd4c
MIT
src/ciphers/kernighan.rs
file
kernighan.rs
src/ciphers/kernighan.rs
1
23
23
Write a Rust function named `kernighan` that counts the number of set bits in a `u32` integer using Brian Kernighan's algorithm. The function should accept a `u32` as input and return an `i32` representing the bit count, clearing the lowest set bit iteratively with `n = n & (n - 1)` until the input reaches zero. Ensure...
pub fn kernighan(n: u32) -> i32 { let mut count = 0; let mut n = n; while n > 0 { n = n & (n - 1); count += 1; } count } #[cfg(test)] mod tests { use super::*; #[test] fn count_set_bits() { assert_eq!(kernighan(0b0000_0000_0000_0000_0000_0000_0000_1011), 3); ...
nvidia/nemotron-3.5-lightning-30b-a3b
d7f15ac81adb3c63-0
d7f15ac81adb3c63
TheAlgorithms/Rust
https://github.com/TheAlgorithms/Rust
fed66cb0c74c4a939ec5163648458a8c2b46fd4c
MIT
src/compression/mod.rs
file
mod.rs
src/compression/mod.rs
1
13
13
I need a Rust module file for a compression crate that aggregates several standard algorithms into a single public API. The file should declare six submodules: `burrows_wheeler_transform`, `huffman_encoding`, `lz77`, `move_to_front`, `peak_signal_to_noise_ratio`, and `run_length_encoding`. After the module declarations...
mod burrows_wheeler_transform; mod huffman_encoding; mod lz77; mod move_to_front; mod peak_signal_to_noise_ratio; mod run_length_encoding; pub use self::burrows_wheeler_transform::{all_rotations, bwt_transform, reverse_bwt, BwtResult}; pub use self::huffman_encoding::{huffman_decode, huffman_encode}; pub use self::lz7...
nvidia/nemotron-3.5-lightning-30b-a3b
1c93a2599a24d4c0-0
1c93a2599a24d4c0
TheAlgorithms/Rust
https://github.com/TheAlgorithms/Rust
fed66cb0c74c4a939ec5163648458a8c2b46fd4c
MIT
src/conversions/decimal_to_binary.rs
file
decimal_to_binary.rs
src/conversions/decimal_to_binary.rs
1
26
26
Write a Rust function that converts a u64 decimal number into its binary string representation. The function should use repeated division by 2, collecting the remainder as bits, and then reverse the collected bits to produce the final binary string. The function takes a single u64 argument and returns a String. Include...
pub fn decimal_to_binary(base_num: u64) -> String { let mut num = base_num; let mut binary_num = String::new(); loop { let bit = (num % 2).to_string(); binary_num.push_str(&bit); num /= 2; if num == 0 { break; } } let bits = binary_num.chars(); ...
nvidia/nemotron-3.5-lightning-30b-a3b
3dbb381383b8293b-0
3dbb381383b8293b
TheAlgorithms/Rust
https://github.com/TheAlgorithms/Rust
fed66cb0c74c4a939ec5163648458a8c2b46fd4c
MIT
src/conversions/decimal_to_octal.rs
file
decimal_to_octal.rs
src/conversions/decimal_to_octal.rs
1
37
37
I need a Rust function that converts a decimal unsigned 64-bit integer to its octal string representation using repeated division by 8. The function should explicitly handle zero, collect remainders as digits, reverse them, and return the result as a String. Include unit tests asserting the outputs for decimal 0, 8, 15...
// Author: NithinU2802 // Decimal to Octal Converter: Converts Decimal to Octal // Wikipedia References: // 1. https://en.wikipedia.org/wiki/Decimal // 2. https://en.wikipedia.org/wiki/Octal pub fn decimal_to_octal(decimal_num: u64) -> String { if decimal_num == 0 { return "0".to_string(); } let m...
nvidia/nemotron-3.5-lightning-30b-a3b
eb906653e579b1e7-0
eb906653e579b1e7
TheAlgorithms/Rust
https://github.com/TheAlgorithms/Rust
fed66cb0c74c4a939ec5163648458a8c2b46fd4c
MIT
src/compression/move_to_front.rs
file
move_to_front.rs
src/compression/move_to_front.rs
1
60
60
I need a Rust module that implements the Move-to-Front transform for data compression. It must include an `encode` function taking `&str` and returning `Vec<u8>`, where each byte is the index of the character in a 256-element table that moves the character to the front after recording. Also implement a `decode` functio...
// https://en.wikipedia.org/wiki/Move-to-front_transform fn blank_char_table() -> Vec<char> { (0..=255).map(|ch| ch as u8 as char).collect() } pub fn move_to_front_encode(text: &str) -> Vec<u8> { let mut char_table = blank_char_table(); let mut result = Vec::new(); for ch in text.chars() { if...
nvidia/nemotron-3.5-lightning-30b-a3b
c846c0321779cffe-0
c846c0321779cffe
TheAlgorithms/Rust
https://github.com/TheAlgorithms/Rust
fed66cb0c74c4a939ec5163648458a8c2b46fd4c
MIT
src/conversions/mod.rs
file
mod.rs
src/conversions/mod.rs
1
55
55
I need a Rust module file that organizes and re-exports a comprehensive set of conversion functions and types for a algorithms library. The module should support converting between numeric bases (binary, decimal, hexadecimal, octal) in both directions, converting energy values with their unit types, handling IPv4 addre...
mod binary_to_decimal; mod binary_to_hexadecimal; mod binary_to_octal; mod decimal_to_binary; mod decimal_to_hexadecimal; mod decimal_to_octal; mod energy; mod hexadecimal_to_binary; mod hexadecimal_to_decimal; mod hexadecimal_to_octal; mod ipv4_conversion; mod length_conversion; mod octal_to_binary; mod octal_to_decim...
nvidia/nemotron-3.5-lightning-30b-a3b
98444a461d6fc629-0
98444a461d6fc629
TheAlgorithms/Rust
https://github.com/TheAlgorithms/Rust
fed66cb0c74c4a939ec5163648458a8c2b46fd4c
MIT
src/data_structures/b_tree.rs
file
b_tree.rs
src/data_structures/b_tree.rs
1
209
209
I need a complete Rust module implementing a B-tree data structure. The implementation should include a `Node` struct, a `BTreeProps` struct to store tree properties like degree, max keys, and mid key index, and a `BTree` generic struct parameterized over type `T`. The type `T` must implement `Ord`, `Copy`, `Debug`, an...
use std::convert::TryFrom; use std::fmt::Debug; use std::mem; struct Node<T> { keys: Vec<T>, children: Vec<Node<T>>, } pub struct BTree<T> { root: Node<T>, props: BTreeProps, } // Why to need a different Struct for props... // Check - http://smallcultfollowing.com/babysteps/blog/2018/11/01/after-nll-...
nvidia/nemotron-3.5-lightning-30b-a3b
b367182bd288997f-0
b367182bd288997f
TheAlgorithms/Rust
https://github.com/TheAlgorithms/Rust
fed66cb0c74c4a939ec5163648458a8c2b46fd4c
MIT
src/bit_manipulation/mod.rs
file
mod.rs
src/bit_manipulation/mod.rs
1
35
35
I need a Rust module file that sets up a bit manipulation crate with several submodules, each exporting specific functions at the crate root. The structure should include submodules for binary coded decimal, bit counting, bit shifts, finding missing numbers, power-of-two operations, Hamming distance, highest set bit, G...
mod binary_coded_decimal; mod binary_count_trailing_zeros; mod binary_shifts; mod counting_bits; mod find_missing_number; mod find_previous_power_of_two; mod find_unique_number; mod hamming_distance; mod highest_set_bit; mod is_power_of_two; mod n_bits_gray_code; mod reverse_bits; mod rightmost_set_bit; mod sum_of_two_...
nvidia/nemotron-3.5-lightning-30b-a3b
939fa086d710739b-0
939fa086d710739b
TheAlgorithms/Rust
https://github.com/TheAlgorithms/Rust
fed66cb0c74c4a939ec5163648458a8c2b46fd4c
MIT
src/conversions/rgb_cmyk_conversion.rs
file
rgb_cmyk_conversion.rs
src/conversions/rgb_cmyk_conversion.rs
1
60
60
Write a Rust function `rgb_to_cmyk` that takes a tuple `(u8, u8, u8)` representing red, green, and blue components and returns a tuple `(u8, u8, u8, u8)` of cyan, magenta, yellow, and key (black) values. The conversion should scale the inputs to [0, 1], compute K as `1 - max(r, g, b)`, and derive C, M, Y using `100 * (...
/// Author : https://github.com/ali77gh\ /// References:\ /// RGB: https://en.wikipedia.org/wiki/RGB_color_model\ /// CMYK: https://en.wikipedia.org/wiki/CMYK_color_model\ /// This function Converts RGB to CMYK format /// /// ### Params /// * `r` - red /// * `g` - green /// * `b` - blue /// /// ### Returns /// (C, M,...
nvidia/nemotron-3.5-lightning-30b-a3b
8f9315ace65fea20-0
8f9315ace65fea20
TheAlgorithms/Rust
https://github.com/TheAlgorithms/Rust
fed66cb0c74c4a939ec5163648458a8c2b46fd4c
MIT
src/conversions/rectangular_to_polar.rs
file
rectangular_to_polar.rs
src/conversions/rectangular_to_polar.rs
1
47
47
Write a Rust function `rectangular_to_polar` that converts rectangular (Cartesian) coordinates given as `f64` real and imaginary parts into polar coordinates. It should return a tuple of two `f64` values: the magnitude and the angle in degrees. The angle must be computed using `atan2` and converted to degrees. Both val...
//! Conversions between rectangular (Cartesian) and polar coordinate systems. //! //! This module provides utilities for converting rectangular coordinates //! into polar coordinates with angles expressed in degrees. //! //! More information: <https://en.wikipedia.org/wiki/Polar_coordinate_system> /// Convert rectangu...
nvidia/nemotron-3.5-lightning-30b-a3b
515d3db37c0f5113-0
515d3db37c0f5113
TheAlgorithms/Rust
https://github.com/TheAlgorithms/Rust
fed66cb0c74c4a939ec5163648458a8c2b46fd4c
MIT
src/ciphers/mod.rs
file
mod.rs
src/ciphers/mod.rs
1
57
57
I need a Rust source file that serves as a ciphers module. It should declare multiple submodules for different cipher algorithms, then publicly re-export specific functions and types from each submodule using `pub use self::` statements. The re-exports must include exactly: AES encryption and decryption functions along...
mod aes; mod affine_cipher; mod another_rot13; mod baconian_cipher; mod base16; mod base32; mod base64; mod base85; mod caesar; mod chacha; mod diffie_hellman; mod gronsfeld; mod hill_cipher; mod kernighan; mod morse_code; mod polybius; mod rail_fence; mod rot13; mod rsa_cipher; mod salsa; mod tea; mod theoretical_rot1...
nvidia/nemotron-3.5-lightning-30b-a3b
4eb7e2f37d6e2575-0
4eb7e2f37d6e2575
TheAlgorithms/Rust
https://github.com/TheAlgorithms/Rust
fed66cb0c74c4a939ec5163648458a8c2b46fd4c
MIT
src/ciphers/salsa.rs
file
salsa.rs
src/ciphers/salsa.rs
1
128
128
I want a Rust function `salsa20` that implements the core Salsa20 cipher transformation. It should take `input: &[u32; 16]` and `output: &mut [u32; 16]`, where the 16 words encode the constant `expand 32-byte k` in the first four positions, a 256-bit key in the next eight, and 128 bits each for nonce and counter in the...
macro_rules! quarter_round { ($v1:expr,$v2:expr,$v3:expr,$v4:expr) => { $v2 ^= ($v1.wrapping_add($v4).rotate_left(7)); $v3 ^= ($v2.wrapping_add($v1).rotate_left(9)); $v4 ^= ($v3.wrapping_add($v2).rotate_left(13)); $v1 ^= ($v4.wrapping_add($v3).rotate_left(18)); }; } /// This is ...
nvidia/nemotron-3.5-lightning-30b-a3b
480a13a3b83ab358-0
480a13a3b83ab358
TheAlgorithms/Rust
https://github.com/TheAlgorithms/Rust
fed66cb0c74c4a939ec5163648458a8c2b46fd4c
MIT
src/data_structures/queue.rs
file
queue.rs
src/data_structures/queue.rs
1
91
91
I need a Rust module that implements a generic Queue data structure using std::collections::LinkedList, following FIFO semantics. The queue should support: creating a new empty queue via Queue::new() or Default; enqueuing elements to the back with enqueue(&mut self, value: T); dequeuing the front element and returning ...
//! This module provides a generic `Queue` data structure, implemented using //! Rust's `LinkedList` from the standard library. The queue follows the FIFO //! (First-In-First-Out) principle, where elements are added to the back of //! the queue and removed from the front. use std::collections::LinkedList; #[derive(De...
nvidia/nemotron-3.5-lightning-30b-a3b
b2796ad3d11c6dac-0
b2796ad3d11c6dac
TheAlgorithms/Rust
https://github.com/TheAlgorithms/Rust
fed66cb0c74c4a939ec5163648458a8c2b46fd4c
MIT
src/data_structures/mod.rs
file
mod.rs
src/data_structures/mod.rs
1
47
47
I'm building a Rust data structures and algorithms library and need a module root file that declares and re-exports several core DS and algorithm modules. The file should define submodules for an AVL tree, a B-tree, a binary search tree, a Fenwick tree, Floyd's cycle detection, directed and undirected graphs, a hash ta...
mod avl_tree; mod b_tree; mod binary_search_tree; mod fenwick_tree; mod floyds_algorithm; pub mod graph; mod hash_table; mod heap; mod lazy_segment_tree; mod linked_list; mod probabilistic; mod queue; mod range_minimum_query; mod rb_tree; mod segment_tree; mod segment_tree_recursive; mod skip_list; mod stack_using_sing...
nvidia/nemotron-3.5-lightning-30b-a3b
7aa8d27f448796f8-0
7aa8d27f448796f8
TheAlgorithms/Rust
https://github.com/TheAlgorithms/Rust
fed66cb0c74c4a939ec5163648458a8c2b46fd4c
MIT
src/dynamic_programming/egg_dropping.rs
file
egg_dropping.rs
src/dynamic_programming/egg_dropping.rs
1
84
84
I need a Rust function `egg_drop` that takes `eggs: usize` and `floors: usize` and returns `Option<usize>`, solving the egg dropping puzzle by finding the minimum number of droppings needed to determine the highest floor from which an egg can be dropped without breaking. If `eggs` is 0, return `None`. For 1 egg or when...
//! This module contains the `egg_drop` function, which determines the minimum number of egg droppings //! required to find the highest floor from which an egg can be dropped without breaking. It also includes //! tests for the function using various test cases, including edge cases. /// Returns the least number of eg...
nvidia/nemotron-3.5-lightning-30b-a3b
f2dc3995b00c58db-0
f2dc3995b00c58db
TheAlgorithms/Rust
https://github.com/TheAlgorithms/Rust
fed66cb0c74c4a939ec5163648458a8c2b46fd4c
MIT
src/dynamic_programming/coin_change.rs
file
coin_change.rs
src/dynamic_programming/coin_change.rs
1
94
94
Write a Rust function `coin_change` that takes `coins: &[usize]` and `amount: usize` and returns `Option<usize>`, implementing the coin change problem via dynamic programming. The function should compute the minimum number of coins needed to make the given amount using the provided denominations, returning `None` if im...
//! This module provides a solution to the coin change problem using dynamic programming. //! The `coin_change` function calculates the fewest number of coins required to make up //! a given amount using a specified set of coin denominations. //! //! The implementation leverages dynamic programming to build up solution...
nvidia/nemotron-3.5-lightning-30b-a3b
cd27d531d43ac481-0
cd27d531d43ac481
TheAlgorithms/Rust
https://github.com/TheAlgorithms/Rust
fed66cb0c74c4a939ec5163648458a8c2b46fd4c
MIT
src/data_structures/probabilistic/bloom_filter.rs
file
bloom_filter.rs
src/data_structures/probabilistic/bloom_filter.rs
1
271
271
I need a complete Rust source file implementing a Bloom Filter probabilistic data structure as a module. The code should define a `BloomFilter` trait parameterized over `Item: Hash` with `insert` and `contains` methods, and provide three concrete types: `BasicBloomFilter<const CAPACITY: usize>` using a fixed-size boole...
use std::collections::hash_map::{DefaultHasher, RandomState}; use std::hash::{BuildHasher, Hash, Hasher}; /// A Bloom Filter <https://en.wikipedia.org/wiki/Bloom_filter> is a probabilistic data structure testing whether an element belongs to a set or not /// Therefore, its contract looks very close to the one of a set...
nvidia/nemotron-3.5-lightning-30b-a3b
506a536c80be129d-0
506a536c80be129d
TheAlgorithms/Rust
https://github.com/TheAlgorithms/Rust
fed66cb0c74c4a939ec5163648458a8c2b46fd4c
MIT
src/dynamic_programming/is_subsequence.rs
file
is_subsequence.rs
src/dynamic_programming/is_subsequence.rs
1
71
71
Write a Rust function `is_subsequence(sub: &str, main: &str) -> bool` that determines whether the string `sub` is a subsequence of `main`. The function should use a peekable iterator over the characters of `sub` and iterate through the characters of `main`; when a character in `main` matches the current character of `s...
//! A module for checking if one string is a subsequence of another string. //! //! A subsequence is formed by deleting some (can be none) of the characters //! from the original string without disturbing the relative positions of the //! remaining characters. This module provides a function to determine if //! a given...
nvidia/nemotron-3.5-lightning-30b-a3b
f03a16840cfac9a0-0
f03a16840cfac9a0
TheAlgorithms/Rust
https://github.com/TheAlgorithms/Rust
fed66cb0c74c4a939ec5163648458a8c2b46fd4c
MIT
src/dynamic_programming/longest_common_substring.rs
file
longest_common_substring.rs
src/dynamic_programming/longest_common_substring.rs
1
70
70
I need a Rust function named `longest_common_substring` that finds the length of the longest common substring between two strings using dynamic programming. It should accept two `&str` parameters and return `usize`. The implementation must use a 2D DP table where each cell `dp[i][j]` represents the length of the longes...
//! This module provides a function to find the length of the longest common substring //! between two strings using dynamic programming. /// Finds the length of the longest common substring between two strings using dynamic programming. /// /// The algorithm uses a 2D dynamic programming table where each cell represe...
nvidia/nemotron-3.5-lightning-30b-a3b
8a86f27c7dfb2aeb-0
8a86f27c7dfb2aeb
TheAlgorithms/Rust
https://github.com/TheAlgorithms/Rust
fed66cb0c74c4a939ec5163648458a8c2b46fd4c
MIT
src/dynamic_programming/longest_common_subsequence.rs
file
longest_common_subsequence.rs
src/dynamic_programming/longest_common_subsequence.rs
1
116
116
I want a Rust implementation of the longest common subsequence algorithm. Specifically, I need a function named `longest_common_subsequence` that takes two `&str` arguments and returns a `String`. It should handle Unicode correctly by processing characters via `.chars()`, build a dynamic programming table of lengths, a...
//! This module implements the Longest Common Subsequence (LCS) algorithm. //! The LCS problem is finding the longest subsequence common to two sequences. //! It differs from the problem of finding common substrings: unlike substrings, subsequences //! are not required to occupy consecutive positions within the origina...
nvidia/nemotron-3.5-lightning-30b-a3b
0420043b379c9057-0
0420043b379c9057
TheAlgorithms/Rust
https://github.com/TheAlgorithms/Rust
fed66cb0c74c4a939ec5163648458a8c2b46fd4c
MIT
src/dynamic_programming/maximal_square.rs
file
maximal_square.rs
src/dynamic_programming/maximal_square.rs
1
66
66
I need a Rust function maximal_square that takes &mut [Vec<i32>] representing a binary matrix and returns the area of the largest square of 1's. The solution should use dynamic programming with O(m*n) time and O(1) extra space by updating the matrix in place. For each cell equal to 1, if it is in the first row or colum...
use std::cmp::max; use std::cmp::min; /// Maximal Square /// /// Given an `m` * `n` binary matrix filled with 0's and 1's, find the largest square containing only 1's and return its area.\ /// <https://leetcode.com/problems/maximal-square/> /// /// # Arguments: /// * `matrix` - an array of integer array /// /// # Co...
nvidia/nemotron-3.5-lightning-30b-a3b
fe1eb58045578c4a-0
fe1eb58045578c4a
TheAlgorithms/Rust
https://github.com/TheAlgorithms/Rust
fed66cb0c74c4a939ec5163648458a8c2b46fd4c
MIT
src/dynamic_programming/longest_continuous_increasing_subsequence.rs
file
longest_continuous_increasing_subsequence.rs
src/dynamic_programming/longest_continuous_increasing_subsequence.rs
1
93
93
I need a Rust function `longest_continuous_increasing_subsequence` that takes a slice `&[T]` where `T: Ord` and returns the longest contiguous sub-slice where each element is less than or equal to the next element (a non-decreasing run). If there are multiple subsequences of the same length, return the first one found....
use std::cmp::Ordering; /// Finds the longest continuous increasing subsequence in a slice. /// /// Given a slice of elements, this function returns a slice representing /// the longest continuous subsequence where each element is strictly /// less than the following element. /// /// # Arguments /// /// * `arr` - A re...
nvidia/nemotron-3.5-lightning-30b-a3b
acc4d5d97b173548-0
acc4d5d97b173548
TheAlgorithms/Rust
https://github.com/TheAlgorithms/Rust
fed66cb0c74c4a939ec5163648458a8c2b46fd4c
MIT
src/data_structures/fenwick_tree.rs
file
fenwick_tree.rs
src/data_structures/fenwick_tree.rs
1
264
264
Implement a Rust struct `FenwickTree` that acts as a Fenwick Tree (Binary Indexed Tree) with 1-based internal indexing and a 0-based public API. The generic type `T` must satisfy `Add<Output = T> + AddAssign + Sub<Output = T> + SubAssign + Copy + Default`. The struct should store a `Vec<T>` where the first element is u...
use std::ops::{Add, AddAssign, Sub, SubAssign}; /// A Fenwick Tree (also known as a Binary Indexed Tree) that supports efficient /// prefix sum, range sum and point queries, as well as point updates. /// /// The Fenwick Tree uses **1-based** indexing internally but presents a **0-based** interface to the user. /// Thi...
nvidia/nemotron-3.5-lightning-30b-a3b
End of preview. Expand in Data Studio

Rust code instruction dataset

410 pairs of (question, real Rust code) built from 6 open-source GitHub repositories.

Each answer is original Rust source. Each question was written by nvidia/nemotron-3.5-lightning-30b-a3b from the code context; the model does not generate the answer.

Source repositories

repository commit license files chunks rows
TheAlgorithms/Rust fed66cb0c7 MIT 421 174 163
reyamira/models 73997bf31e MIT 78 29 23
AreevAI/flowcat 9eb2999c33 Apache-2.0 192 88 66
cortex/ripasso 25f855dfc3 GPL-3.0-only 22 21 18
brentongunning/rust-sv f2c9e939b3 MIT 54 22 21
lightningdevkit/rust-lightning 48e8d4745e Apache-2.0 OR MIT 257 138 119

Rows by kind

kind rows
file 410

Example

Question

I need a Rust module that declares several backtracking algorithm submodules and re-exports their public functions. The module should define submodules named all_combination_of_size_k, graph_coloring, hamiltonian_cycle, knight_tour, n_queens, parentheses_generator, permutations, rat_in_maze, subset_sum, and sudoku. It must re-export exactly these functions with these exact names: generate_all_combinations, generate_colorings, find_hamiltonian_cycle, find_knight_tour, n_queens_solver, generate_parentheses, permute, find_path_in_maze, has_subset_with_sum, and sudoku_solver. Please generate the module declarations and pub use statements that match this structure.

Answer (TheAlgorithms/Rust - src/backtracking/mod.rs)

mod all_combination_of_size_k;
mod graph_coloring;
mod hamiltonian_cycle;
mod knight_tour;
mod n_queens;
mod parentheses_generator;
mod permutations;
mod rat_in_maze;
mod subset_sum;
mod sudoku;

pub use all_combination_of_size_k::generate_all_combinations;
pub use graph_coloring::generate_colorings;
pub use hamiltonian_cycle::find_hamiltonian_cycle;
pub use knight_tour::find_knight_tour;
pub use n_queens::n_queens_solver;
pub use parentheses_generator::generate_parentheses;
pub use permutations::permute;
pub use rat_in_maze::find_path_in_maze;
pub use subset_sum::has_subset_with_sum;
pub use sudoku::sudoku_solver;

Usage

from datasets import load_dataset

dataset = load_dataset("Shadow0482/rust", split="train")
print(dataset[0]["question"])
print(dataset[0]["answer"])

License and attribution

Code in answer remains under the license of the source repository shown in the license and repo_url columns. Follow that license when redistributing or training on the data. The questions are synthetic; follow the terms of the model provider used to create them.

Downloads last month
29