diff --git a/README.md b/README.md index 88b30d4..a9a93d8 100644 --- a/README.md +++ b/README.md @@ -31,7 +31,7 @@ ladderz = { git = "https://github.com/rzmk/ladderz", branch = "main" } Now in `src/main.rs` let's replace the contents with the following code: ```rust -use ladderz::pre_algebra::unit1::{get_factor_pairs, get_factors}; +use ladderz::pre_algebra::{get_factors, get_factor_pairs}; use std::env; fn main() { diff --git a/ladderz/src/lib.rs b/ladderz/src/lib.rs index 7624a5d..23c6af0 100644 --- a/ladderz/src/lib.rs +++ b/ladderz/src/lib.rs @@ -25,7 +25,7 @@ //! Now in `src/main.rs` let's replace the contents with the following code: //! //! ```rust -//! use ladderz::pre_algebra::unit1::{get_factor_pairs, get_factors}; +//! use ladderz::pre_algebra::{get_factors, get_factor_pairs}; //! use std::env; //! //! fn main() { @@ -81,7 +81,7 @@ //! //! The printed output should be: //! -//! ``` +//! ```console //! List of factors of 12: [1, 2, 3, 4, 6, 12] //! List of factor pairs of 12: [(1, 12), (2, 6), (3, 4)] //! ``` diff --git a/ladderz/src/pre_algebra.rs b/ladderz/src/pre_algebra.rs deleted file mode 100644 index 759857f..0000000 --- a/ladderz/src/pre_algebra.rs +++ /dev/null @@ -1,2 +0,0 @@ -/// Factors and multiples -pub mod unit1; diff --git a/ladderz/src/pre_algebra/mod.rs b/ladderz/src/pre_algebra/mod.rs new file mode 100644 index 0000000..c042765 --- /dev/null +++ b/ladderz/src/pre_algebra/mod.rs @@ -0,0 +1,5 @@ +/// Factors and multiples +mod unit1; + +#[doc(inline)] +pub use unit1::*; diff --git a/ladderz/src/pre_algebra/unit1.rs b/ladderz/src/pre_algebra/unit1.rs index cae3e6c..1036c99 100644 --- a/ladderz/src/pre_algebra/unit1.rs +++ b/ladderz/src/pre_algebra/unit1.rs @@ -2,31 +2,15 @@ use std::collections::HashSet; /// Finds all factor pairs for a positive integer `n`. /// -/// # Challenge -/// -/// Write a program that finds all the factor pairs for a number `n`. -/// -/// # Description -/// -/// Generates a `HashSet` of factor pairs for a positive integer `n`. -/// -/// This function calculates and returns a `HashSet` containing all unique factor pairs +/// This function calculates and returns a `HashSet<(u32, u32)>` containing all unique factor pairs /// of the input positive integer `n`. A factor pair is a pair of positive integers /// `(a, b)` where `a` and `b` are both factors of `n` (i.e., `a * b == n`). /// -/// # Arguments -/// -/// * `n` - The positive integer for which factor pairs are to be calculated. -/// -/// # Returns -/// -/// A `HashSet` containing all unique factor pairs of the input integer `n`. -/// /// # Examples /// /// ```rust /// use std::collections::HashSet; -/// use ladderz::pre_algebra::unit1::get_factor_pairs; +/// use ladderz::pre_algebra::get_factor_pairs; /// /// fn main() { /// let result_pairs = get_factor_pairs(12); @@ -59,31 +43,15 @@ pub fn get_factor_pairs(n: u32) -> HashSet<(u32, u32)> { /// Finds all factors of a positive integer `n`. /// -/// # Challenge -/// -/// Write a program that finds all the factors of a number. Assume that `n` is a positive integer greater than or equal to 1. -/// -/// # Description -/// -/// Generates a `HashSet` of factors for a positive integer `n`. -/// -/// This function calculates and returns a `HashSet` containing all unique factors +/// This function calculates and returns a `HashSet` containing all unique factors /// of the input positive integer `n`. A factor of `n` is a positive integer `a` where /// `n` is evenly divisible by `a` (i.e., `n % a == 0`). /// -/// # Arguments -/// -/// * `n` - The positive integer for which factors are to be calculated. -/// -/// # Returns -/// -/// A `HashSet` containing all unique factors of the input integer `n`. -/// /// # Examples /// /// ```rust /// use std::collections::HashSet; -/// use ladderz::pre_algebra::unit1::get_factors; +/// use ladderz::pre_algebra::get_factors; /// /// fn main() { /// let result_factors = get_factors(16); @@ -108,31 +76,14 @@ pub fn get_factors(n: u32) -> HashSet { factors } -/// Checks if a positive integer `x` is a factor of another positive integer `y`. -/// -/// # Challenge -/// -/// Write a program that determines whether one positive integer is a factor of another. -/// -/// # Description -/// /// Checks if a positive integer `x` is a factor of another positive integer `y`. /// /// A factor of `y` is a positive integer `x` where `y` is evenly divisible by `x` (i.e., `y % x == 0`). /// -/// # Arguments -/// -/// * `x` - The positive integer to determine whether it is a factor of `y` or not. -/// * `y` - The positive integer for which the factor check of `x` is performed. -/// -/// # Returns -/// -/// `true` if `x` is a factor of `y`, `false` otherwise. -/// /// # Examples /// /// ```rust -/// use ladderz::pre_algebra::unit1::is_factor; +/// use ladderz::pre_algebra::is_factor; /// /// fn main() { /// assert!(is_factor(2, 16)); // 2 is a factor of 16 @@ -148,31 +99,14 @@ pub fn is_factor(x: u32, y: u32) -> bool { y % x == 0 } -/// Checks if a positive integer `x` is a multiple of another positive integer `y`. -/// -/// # Challenge -/// -/// Write a program that determines whether one positive integer is a multiple of another. -/// -/// # Description -/// /// Checks if a positive integer `x` is a multiple of another positive integer `y`. /// /// A multiple of `y` is a positive integer `x` where `x` is evenly divisible by `y` (i.e., `x % y == 0`). /// -/// # Arguments -/// -/// * `x` - The positive integer to determine whether it is a multiple of `y` or not. -/// * `y` - The positive integer for which the multiple check of `x` is performed. -/// -/// # Returns -/// -/// `true` if `x` is a multiple of `y`, `false` otherwise. -/// /// # Examples /// /// ```rust -/// use ladderz::pre_algebra::unit1::is_multiple; +/// use ladderz::pre_algebra::is_multiple; /// /// fn main() { /// assert!(is_multiple(16, 2)); // 16 is a multiple of 2 @@ -185,29 +119,14 @@ pub fn is_multiple(x: u32, y: u32) -> bool { /// Finds all the multiples of a positive integer `n` up to and including `end` (in the range [n, end]). /// -/// # Challenge -/// -/// Write a program that finds all the multiples of a positive integer `n` in a given range. -/// -/// # Description -/// -/// Returns a HashSet containing all the multiples of a positive integer `n` in the range [n, end]. +/// Returns a `HashSet` containing all the multiples of a positive integer `n` in the range [n, end]. /// /// A multiple of `n` is a positive integer `num` where `num` is evenly divisible by `n` (i.e., `num % n == 0`). /// -/// # Arguments -/// -/// * `n` - The positive integer for which multiples are to be found. -/// * `end` - The upper limit of the range for finding multiples. -/// -/// # Returns -/// -/// A HashSet containing all the multiples of `n` in the range [n, end]. -/// /// # Examples /// /// ```rust -/// use ladderz::pre_algebra::unit1::get_multiples_in_range; +/// use ladderz::pre_algebra::get_multiples_in_range; /// use std::collections::HashSet; /// /// fn main() {