diff --git a/ladderz/all.html b/ladderz/all.html index cd04d4b..b0b0017 100644 --- a/ladderz/all.html +++ b/ladderz/all.html @@ -1 +1 @@ -List of all items in this crate

List of all items

Functions

\ No newline at end of file +List of all items in this crate

List of all items

Functions

\ No newline at end of file diff --git a/ladderz/pre_algebra/unit1/fn.get_multiples_in_range.html b/ladderz/pre_algebra/unit1/fn.get_multiples_in_range.html new file mode 100644 index 0000000..fa87791 --- /dev/null +++ b/ladderz/pre_algebra/unit1/fn.get_multiples_in_range.html @@ -0,0 +1,27 @@ +get_multiples_in_range in ladderz::pre_algebra::unit1 - Rust
pub fn get_multiples_in_range(n: u32, end: u32) -> HashSet<u32>
Expand description

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].

+

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

+
use ladderz::pre_algebra::unit1::get_multiples_in_range;
+use std::collections::HashSet;
+
+fn main() {
+    let result: HashSet<u32> = get_multiples_in_range(2, 10);
+    let expected: HashSet<u32> = [2, 4, 6, 8, 10].into();
+    assert_eq!(result, expected);
+
+    let result: HashSet<u32> = get_multiples_in_range(3, 15);
+    let expected: HashSet<u32> = [3, 6, 9, 12, 15].into();
+    assert_eq!(result, expected);
+}
+
\ No newline at end of file diff --git a/ladderz/pre_algebra/unit1/index.html b/ladderz/pre_algebra/unit1/index.html index 887ad80..8e18790 100644 --- a/ladderz/pre_algebra/unit1/index.html +++ b/ladderz/pre_algebra/unit1/index.html @@ -1,2 +1,2 @@ -ladderz::pre_algebra::unit1 - Rust

Module ladderz::pre_algebra::unit1

source ·
Expand description

Factors and multiples

-

Functions

  • Finds all factor pairs for a positive integer n.
  • Finds all factors of a positive integer n.
  • Checks if a positive integer x is a factor of another positive integer y.
  • Checks if a positive integer x is a multiple of another positive integer y.
\ No newline at end of file +ladderz::pre_algebra::unit1 - Rust

Module ladderz::pre_algebra::unit1

source ·
Expand description

Factors and multiples

+

Functions

  • Finds all factor pairs for a positive integer n.
  • Finds all factors of a positive integer n.
  • Finds all the multiples of a positive integer n up to and including end (in the range [n, end]).
  • Checks if a positive integer x is a factor of another positive integer y.
  • Checks if a positive integer x is a multiple of another positive integer y.
\ No newline at end of file diff --git a/ladderz/pre_algebra/unit1/sidebar-items.js b/ladderz/pre_algebra/unit1/sidebar-items.js index 9e7010f..a5fdfbb 100644 --- a/ladderz/pre_algebra/unit1/sidebar-items.js +++ b/ladderz/pre_algebra/unit1/sidebar-items.js @@ -1 +1 @@ -window.SIDEBAR_ITEMS = {"fn":["get_factor_pairs","get_factors","is_factor","is_multiple"]}; \ No newline at end of file +window.SIDEBAR_ITEMS = {"fn":["get_factor_pairs","get_factors","get_multiples_in_range","is_factor","is_multiple"]}; \ No newline at end of file diff --git a/search-index.js b/search-index.js index 7ad9bb7..c12a4dd 100644 --- a/search-index.js +++ b/search-index.js @@ -1,5 +1,5 @@ var searchIndex = JSON.parse('{\ -"ladderz":{"doc":"Implementations of mathematical and technical concepts in …","t":"AAFFFF","n":["pre_algebra","unit1","get_factor_pairs","get_factors","is_factor","is_multiple"],"q":[[0,"ladderz"],[1,"ladderz::pre_algebra"],[2,"ladderz::pre_algebra::unit1"]],"d":["Various pre-algebra implementations including factor …","Factors and multiples","Finds all factor pairs for a positive integer n.","Finds all factors of a positive integer n.","Checks if a positive integer x is a factor of another …","Checks if a positive integer x is a multiple of another …"],"i":[0,0,0,0,0,0],"f":[0,0,[1,2],[1,[[2,[1]]]],[[1,1],3],[[1,1],3]],"c":[],"p":[[15,"u32"],[3,"HashSet"],[15,"bool"]]}\ +"ladderz":{"doc":"Implementations of mathematical and technical concepts in …","t":"AAFFFFF","n":["pre_algebra","unit1","get_factor_pairs","get_factors","get_multiples_in_range","is_factor","is_multiple"],"q":[[0,"ladderz"],[1,"ladderz::pre_algebra"],[2,"ladderz::pre_algebra::unit1"]],"d":["Various pre-algebra implementations including factor …","Factors and multiples","Finds all factor pairs for a positive integer n.","Finds all factors of a positive integer n.","Finds all the multiples of a positive integer n up to and …","Checks if a positive integer x is a factor of another …","Checks if a positive integer x is a multiple of another …"],"i":[0,0,0,0,0,0,0],"f":[0,0,[1,2],[1,[[2,[1]]]],[[1,1],[[2,[1]]]],[[1,1],3],[[1,1],3]],"c":[],"p":[[15,"u32"],[3,"HashSet"],[15,"bool"]]}\ }'); if (typeof window !== 'undefined' && window.initSearch) {window.initSearch(searchIndex)}; if (typeof exports !== 'undefined') {exports.searchIndex = searchIndex}; diff --git a/src/ladderz/pre_algebra/unit1.rs.html b/src/ladderz/pre_algebra/unit1.rs.html index 9ae985b..d7899e9 100644 --- a/src/ladderz/pre_algebra/unit1.rs.html +++ b/src/ladderz/pre_algebra/unit1.rs.html @@ -231,6 +231,65 @@ 231 232 233 +234 +235 +236 +237 +238 +239 +240 +241 +242 +243 +244 +245 +246 +247 +248 +249 +250 +251 +252 +253 +254 +255 +256 +257 +258 +259 +260 +261 +262 +263 +264 +265 +266 +267 +268 +269 +270 +271 +272 +273 +274 +275 +276 +277 +278 +279 +280 +281 +282 +283 +284 +285 +286 +287 +288 +289 +290 +291 +292
use std::collections::HashSet;
 
 /// Finds all factor pairs for a positive integer `n`.
@@ -416,6 +475,54 @@
     x % y == 0
 }
 
+/// 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].
+///
+/// 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 std::collections::HashSet;
+///
+/// fn main() {
+///     let result: HashSet<u32> = get_multiples_in_range(2, 10);
+///     let expected: HashSet<u32> = [2, 4, 6, 8, 10].into();
+///     assert_eq!(result, expected);
+///
+///     let result: HashSet<u32> = get_multiples_in_range(3, 15);
+///     let expected: HashSet<u32> = [3, 6, 9, 12, 15].into();
+///     assert_eq!(result, expected);
+/// }
+/// ```
+pub fn get_multiples_in_range(n: u32, end: u32) -> HashSet<u32> {
+    let mut multiples: HashSet<u32> = HashSet::new();
+
+    for num in n..end+1 {
+        if num % n == 0 {
+            multiples.insert(num);
+        }
+    }
+    multiples
+}
+
 #[cfg(test)]
 mod tests {
     use super::*;
@@ -463,5 +570,16 @@
         let expected_2: bool = is_multiple(11, 2);
         assert_eq!(result_2, expected_2);
     }
+
+    #[test]
+    fn test_get_multiples_in_range() {
+        let result: HashSet<u32> = get_multiples_in_range(2, 20);
+        let expected: HashSet<u32> = [2, 4, 6, 8, 10, 12, 14, 16, 18, 20].into();
+        assert_eq!(result, expected);
+
+        let result_2: HashSet<u32> = get_multiples_in_range(5, 34);
+        let expected_2: HashSet<u32> = [5, 10, 15, 20, 25, 30].into();
+        assert_eq!(result_2, expected_2);
+    }
 }
 
\ No newline at end of file