From 5c3f77b9544334a07d6e2e522269368892268c06 Mon Sep 17 00:00:00 2001 From: rzmk Date: Wed, 20 Sep 2023 00:05:34 +0000 Subject: [PATCH] deploy: 31040d78072e7f99ee23b0ce2a326e8dac13e7f1 --- help.html | 2 +- ladderz/all.html | 2 +- ladderz/index.html | 2 +- ladderz/pre_algebra/index.html | 2 +- .../unit1/fn.get_factor_pairs.html | 6 +- ladderz/pre_algebra/unit1/fn.get_factors.html | 28 ++++ ladderz/pre_algebra/unit1/index.html | 4 +- ladderz/pre_algebra/unit1/sidebar-items.js | 2 +- search-index.js | 2 +- settings.html | 2 +- src/ladderz/lib.rs.html | 4 +- src/ladderz/pre_algebra.rs.html | 2 +- src/ladderz/pre_algebra/unit1.rs.html | 154 +++++++++++++++++- 13 files changed, 195 insertions(+), 17 deletions(-) create mode 100644 ladderz/pre_algebra/unit1/fn.get_factors.html diff --git a/help.html b/help.html index a0c7e70..7a2b8e9 100644 --- a/help.html +++ b/help.html @@ -1 +1 @@ -Rustdoc help

Rustdoc help

Back
\ No newline at end of file +Rustdoc help

Rustdoc help

Back
\ No newline at end of file diff --git a/ladderz/all.html b/ladderz/all.html index bc16194..19c61f4 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
\ No newline at end of file diff --git a/ladderz/index.html b/ladderz/index.html index e5921f5..7fa1cd6 100644 --- a/ladderz/index.html +++ b/ladderz/index.html @@ -1,2 +1,2 @@ -ladderz - Rust

Crate ladderz

source ·
Expand description

Non-production implementations of mathematical and technical concepts in Rust.

+ladderz - Rust

Crate ladderz

source ·
Expand description

Implementations of mathematical and technical concepts in Rust.

Modules

  • Various pre-algebra implementations including multiples (planned), factor pairs, etc.
\ No newline at end of file diff --git a/ladderz/pre_algebra/index.html b/ladderz/pre_algebra/index.html index 8540bed..a29b7f0 100644 --- a/ladderz/pre_algebra/index.html +++ b/ladderz/pre_algebra/index.html @@ -1,2 +1,2 @@ -ladderz::pre_algebra - Rust

Module ladderz::pre_algebra

source ·
Expand description

Various pre-algebra implementations including multiples (planned), factor pairs, etc.

+ladderz::pre_algebra - Rust

Module ladderz::pre_algebra

source ·
Expand description

Various pre-algebra implementations including multiples (planned), factor pairs, etc.

Modules

  • Factors and multiples
\ No newline at end of file diff --git a/ladderz/pre_algebra/unit1/fn.get_factor_pairs.html b/ladderz/pre_algebra/unit1/fn.get_factor_pairs.html index ae48abd..71c17b7 100644 --- a/ladderz/pre_algebra/unit1/fn.get_factor_pairs.html +++ b/ladderz/pre_algebra/unit1/fn.get_factor_pairs.html @@ -1,4 +1,8 @@ -get_factor_pairs in ladderz::pre_algebra::unit1 - Rust
pub fn get_factor_pairs(n: u32) -> HashSet<(u32, u32)>
Expand description

Generates a HashSet of factor pairs for a given positive integer n.

+get_factor_pairs in ladderz::pre_algebra::unit1 - Rust
pub fn get_factor_pairs(n: u32) -> HashSet<(u32, u32)>
Expand description

Finds all factor pairs for a given positive integer.

+

Challenge

+

Write a program that finds all the factor pairs for a given number n.

+

Description

+

Generates a HashSet of factor pairs for a given positive integer n.

This function calculates and returns a HashSet 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).

diff --git a/ladderz/pre_algebra/unit1/fn.get_factors.html b/ladderz/pre_algebra/unit1/fn.get_factors.html new file mode 100644 index 0000000..97f2e8a --- /dev/null +++ b/ladderz/pre_algebra/unit1/fn.get_factors.html @@ -0,0 +1,28 @@ +get_factors in ladderz::pre_algebra::unit1 - Rust
pub fn get_factors(n: u32) -> HashSet<u32>
Expand description

Finds all factors of a given positive integer.

+

Challenge

+

Write a program that finds all the factors of a given number. Assume that n is a positive integer greater than or equal to 1.

+

Description

+

Generates a HashSet of factors for a given positive integer n.

+

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

+
use std::collections::HashSet;
+use ladderz::pre_algebra::unit1::get_factors;
+
+fn main() {
+    let result_factors = get_factors(16);
+    let expected_factors: HashSet<u32> = [1, 2, 4, 8, 16].into();
+    assert_eq!(result_factors, expected_factors);
+}
+

Note

+

This function calculates factors by iterating through positive integers from 1 to n +(inclusive) and checking if they divide n evenly. If they do, the factor is added to +the HashSet. The function ensures that factors are unique, so duplicates are not added.

+
\ No newline at end of file diff --git a/ladderz/pre_algebra/unit1/index.html b/ladderz/pre_algebra/unit1/index.html index 3847c92..8c3bdc6 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

  • Generates a HashSet of factor pairs for a given positive integer n.
\ No newline at end of file +ladderz::pre_algebra::unit1 - Rust

Module ladderz::pre_algebra::unit1

source ·
Expand description

Factors and multiples

+

Functions

\ 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 30cd19f..7cf5ff3 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"]}; \ No newline at end of file +window.SIDEBAR_ITEMS = {"fn":["get_factor_pairs","get_factors"]}; \ No newline at end of file diff --git a/search-index.js b/search-index.js index 5812c2a..de6c98e 100644 --- a/search-index.js +++ b/search-index.js @@ -1,5 +1,5 @@ var searchIndex = JSON.parse('{\ -"ladderz":{"doc":"Non-production implementations of mathematical and …","t":"AAF","n":["pre_algebra","unit1","get_factor_pairs"],"q":[[0,"ladderz"],[1,"ladderz::pre_algebra"],[2,"ladderz::pre_algebra::unit1"]],"d":["Various pre-algebra implementations including multiples …","Factors and multiples","Generates a HashSet of factor pairs for a given positive …"],"i":[0,0,0],"f":[0,0,[1,2]],"c":[],"p":[[15,"u32"],[3,"HashSet"]]}\ +"ladderz":{"doc":"Implementations of mathematical and technical concepts in …","t":"AAFF","n":["pre_algebra","unit1","get_factor_pairs","get_factors"],"q":[[0,"ladderz"],[1,"ladderz::pre_algebra"],[2,"ladderz::pre_algebra::unit1"]],"d":["Various pre-algebra implementations including multiples …","Factors and multiples","Finds all factor pairs for a given positive integer.","Finds all factors of a given positive integer."],"i":[0,0,0,0],"f":[0,0,[1,2],[1,[[2,[1]]]]],"c":[],"p":[[15,"u32"],[3,"HashSet"]]}\ }'); if (typeof window !== 'undefined' && window.initSearch) {window.initSearch(searchIndex)}; if (typeof exports !== 'undefined') {exports.searchIndex = searchIndex}; diff --git a/settings.html b/settings.html index 14dd325..85e7a4d 100644 --- a/settings.html +++ b/settings.html @@ -1 +1 @@ -Rustdoc settings

Rustdoc settings

Back
\ No newline at end of file +Rustdoc settings

Rustdoc settings

Back
\ No newline at end of file diff --git a/src/ladderz/lib.rs.html b/src/ladderz/lib.rs.html index 5261cf9..46282ac 100644 --- a/src/ladderz/lib.rs.html +++ b/src/ladderz/lib.rs.html @@ -1,8 +1,8 @@ -lib.rs - source
1
+lib.rs - source
1
 2
 3
 4
-
//! Non-production implementations of mathematical and technical concepts in Rust.
+
//! Implementations of mathematical and technical concepts in Rust.
 
 /// Various pre-algebra implementations including multiples (planned), factor pairs, etc.
 pub mod pre_algebra;
diff --git a/src/ladderz/pre_algebra.rs.html b/src/ladderz/pre_algebra.rs.html
index 78748c8..3c783cf 100644
--- a/src/ladderz/pre_algebra.rs.html
+++ b/src/ladderz/pre_algebra.rs.html
@@ -1,4 +1,4 @@
-pre_algebra.rs - source
1
+pre_algebra.rs - source
1
 2
 
/// Factors and multiples
 pub mod unit1;
diff --git a/src/ladderz/pre_algebra/unit1.rs.html b/src/ladderz/pre_algebra/unit1.rs.html
index d7fdb4e..b8ba17c 100644
--- a/src/ladderz/pre_algebra/unit1.rs.html
+++ b/src/ladderz/pre_algebra/unit1.rs.html
@@ -1,4 +1,4 @@
-unit1.rs - source
1
+unit1.rs - source
1
 2
 3
 4
@@ -61,10 +61,90 @@
 61
 62
 63
+64
+65
+66
+67
+68
+69
+70
+71
+72
+73
+74
+75
+76
+77
+78
+79
+80
+81
+82
+83
+84
+85
+86
+87
+88
+89
+90
+91
+92
+93
+94
+95
+96
+97
+98
+99
+100
+101
+102
+103
+104
+105
+106
+107
+108
+109
+110
+111
+112
+113
+114
+115
+116
+117
+118
+119
+120
+121
+122
+123
+124
+125
+126
+127
+128
+129
+130
+131
+132
+133
+134
+135
+136
 
use std::collections::HashSet;
 
-// TODO: Implement negative integers
-/// Generates a `HashSet` of factor pairs for a given positive integer `n`.
+/// Finds all factor pairs for a given positive integer.
+/// 
+/// # Challenge
+/// 
+/// Write a program that finds all the factor pairs for a given number `n`.
+/// 
+/// # Description
+/// 
+/// Generates a `HashSet` of factor pairs for a given positive integer `n`.
 ///
 /// This function calculates and returns a `HashSet` containing all unique factor pairs
 /// of the input positive integer `n`. A factor pair is a pair of positive integers
@@ -113,15 +193,81 @@
     factor_pairs
 }
 
+/// Finds all factors of a given positive integer.
+/// 
+/// # Challenge
+/// 
+/// Write a program that finds all the factors of a given number. Assume that `n` is a positive integer greater than or equal to 1.
+///
+/// # Description
+/// 
+/// Generates a `HashSet` of factors for a given positive integer `n`.
+///
+/// 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;
+///
+/// fn main() {
+///     let result_factors = get_factors(16);
+///     let expected_factors: HashSet<u32> = [1, 2, 4, 8, 16].into();
+///     assert_eq!(result_factors, expected_factors);
+/// }
+/// ```
+///
+/// # Note
+///
+/// This function calculates factors by iterating through positive integers from 1 to `n`
+/// (inclusive) and checking if they divide `n` evenly. If they do, the factor is added to
+/// the `HashSet`. The function ensures that factors are unique, so duplicates are not added.
+pub fn get_factors(n: u32) -> HashSet<u32> {
+    let mut factors: HashSet<u32> = HashSet::new();
+
+    for num in 1..n+1 {
+        if n % num == 0 {
+            factors.insert(num);
+        }
+    }
+    factors
+}
+
 #[cfg(test)]
 mod tests {
     use super::*;
 
     #[test]
-    fn test_get_factor_pairs_1() {
+    fn test_get_factor_pairs() {
         let result: HashSet<(u32, u32)> = get_factor_pairs(1);
         let expected: HashSet<(u32, u32)> = [(1, 1)].into();
         assert_eq!(result, expected);
+
+        let result_2: HashSet<(u32, u32)> = get_factor_pairs(16);
+        let expected_2: HashSet<(u32, u32)> = [(1, 16), (2, 8), (4, 4)].into();
+        assert_eq!(result_2, expected_2);
+    }
+
+    #[test]
+    fn test_get_factors() {
+        let result: HashSet<u32> = get_factors(1);
+        let expected: HashSet<u32> = [1].into();
+        assert_eq!(result, expected);
+
+        let result_2: HashSet<u32> = get_factors(16);
+        let expected_2: HashSet<u32> = [1, 2, 4, 8, 16].into();
+        assert_eq!(result_2, expected_2);
     }
 }
 
\ No newline at end of file