From a925f41d50aa0681d8d2bcb4e4f81c3e926768da Mon Sep 17 00:00:00 2001 From: rzmk Date: Thu, 21 Sep 2023 12:03:28 +0000 Subject: [PATCH] deploy: 3673f6df8e0accb8fef55e5ed5b00d9e56aa7a12 --- ladderz/index.html | 64 ++++++++- search-index.js | 2 +- src/ladderz/lib.rs.html | 178 +++++++++++++++++++++++++- src/ladderz/pre_algebra/unit1.rs.html | 10 +- 4 files changed, 246 insertions(+), 8 deletions(-) diff --git a/ladderz/index.html b/ladderz/index.html index 0596e62..9f25711 100644 --- a/ladderz/index.html +++ b/ladderz/index.html @@ -1,2 +1,64 @@ -ladderz - Rust

Crate ladderz

source ·
Expand description

Implementations of mathematical and technical concepts in Rust.

+ladderz - Rust

Crate ladderz

source ·
Expand description

ladderz

+

Implementations of mathematical and technical concepts in Rust.

+

View the modules section for the various implementations based on the subject.

+

Example

+

Here’s an example of using the ladderz crate to get the factors and factor pairs of a number in sorted order. +We’ll assume you’re using Bash as your terminal.

+

First let’s create a new Rust project and change into the project directory:

+
cargo new my_ladderz_project
+cd my_ladderz_project
+
+

Then let’s add the following to Cargo.toml under the [dependencies] section:

+
ladderz = { git = "https://github.com/rzmk/ladderz", branch = "main" }
+
+

Now in src/main.rs let’s replace the contents with the following code:

+ +
use ladderz::pre_algebra::unit1::{get_factor_pairs, get_factors};
+use std::env;
+
+fn main() {
+    // Get user input as a Vec
+    let args: Vec<String> = env::args().collect();
+
+    // Check if input was provided
+    match args.get(1) {
+        Some(_) => {
+            match args[1].parse::<u32>() {
+                // Handle input that can be parsed as a u32
+                Ok(x) => {
+                    // Convert the HashSet of factors of input x to a sorted Vec
+                    let mut factors: Vec<u32> = get_factors(x).into_iter().collect::<Vec<u32>>();
+                    factors.sort();
+
+                    // Convert the HashSet of factor pairs of input x to a sorted Vec
+                    let mut factor_pairs: Vec<(u32, u32)> =
+                        get_factor_pairs(x).into_iter().collect::<Vec<(u32, u32)>>();
+                    factor_pairs.sort();
+
+                    // Print the results
+                    println!("List of factors of {:?}: {:?}", x, factors);
+                    println!("List of factor pairs of {:?}: {:?}", x, factor_pairs);
+                }
+                // Handle input that can't be parsed as a u32
+                Err(e) => println!("Error parsing input: {e}"),
+            }
+        }
+        None => println!("No input provided."),
+    }
+}
+
+

Now let’s build the project’s binary file so we can run it from the command line:

+
cargo build --release
+
+

Our runnable binary file should be located at the local path ./target/release/my_ladders_project (or ./target/release/my_ladders_project.exe for Windows). Let’s run it with the number 12 as input:

+
./target/release/my_ladderz_project 12
+
+

If you have a .exe file instead, you can run it with:

+
./target/release/my_ladderz_project.exe 12
+
+

The printed output should be:

+ +
List of factors of 12: [1, 2, 3, 4, 6, 12]
+List of factor pairs of 12: [(1, 12), (2, 6), (3, 4)]
+

Great! We’ve successfully used the ladderz crate to get the factors and factor pairs of a number in sorted order.

Modules

  • Various pre-algebra implementations including factor pairs, factors, multiples, and more.
\ No newline at end of file diff --git a/search-index.js b/search-index.js index c12a4dd..b40150d 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":"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"]]}\ +"ladderz":{"doc":"ladderz","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/lib.rs.html b/src/ladderz/lib.rs.html index 48b1b0c..ef19940 100644 --- a/src/ladderz/lib.rs.html +++ b/src/ladderz/lib.rs.html @@ -2,7 +2,183 @@ 2 3 4 -
//! Implementations of mathematical and technical concepts in Rust.
+5
+6
+7
+8
+9
+10
+11
+12
+13
+14
+15
+16
+17
+18
+19
+20
+21
+22
+23
+24
+25
+26
+27
+28
+29
+30
+31
+32
+33
+34
+35
+36
+37
+38
+39
+40
+41
+42
+43
+44
+45
+46
+47
+48
+49
+50
+51
+52
+53
+54
+55
+56
+57
+58
+59
+60
+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
+
//! # ladderz
+//!
+//! Implementations of mathematical and technical concepts in Rust.
+//!
+//! View [the modules section](#modules) for the various implementations based on the subject.
+//!
+//! # Example
+//!
+//! Here's an example of using the `ladderz` crate to get the factors and factor pairs of a number in sorted order.
+//! We'll assume you're using Bash as your terminal.
+//!
+//! First let's create a new Rust project and change into the project directory:
+//!
+//! ```bash
+//! cargo new my_ladderz_project
+//! cd my_ladderz_project
+//! ```
+//!
+//! Then let's add the following to `Cargo.toml` under the `[dependencies]` section:
+//!
+//! ```toml
+//! 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 std::env;
+//!
+//! fn main() {
+//!     // Get user input as a Vec
+//!     let args: Vec<String> = env::args().collect();
+//!
+//!     // Check if input was provided
+//!     match args.get(1) {
+//!         Some(_) => {
+//!             match args[1].parse::<u32>() {
+//!                 // Handle input that can be parsed as a u32
+//!                 Ok(x) => {
+//!                     // Convert the HashSet of factors of input x to a sorted Vec
+//!                     let mut factors: Vec<u32> = get_factors(x).into_iter().collect::<Vec<u32>>();
+//!                     factors.sort();
+//!
+//!                     // Convert the HashSet of factor pairs of input x to a sorted Vec
+//!                     let mut factor_pairs: Vec<(u32, u32)> =
+//!                         get_factor_pairs(x).into_iter().collect::<Vec<(u32, u32)>>();
+//!                     factor_pairs.sort();
+//!
+//!                     // Print the results
+//!                     println!("List of factors of {:?}: {:?}", x, factors);
+//!                     println!("List of factor pairs of {:?}: {:?}", x, factor_pairs);
+//!                 }
+//!                 // Handle input that can't be parsed as a u32
+//!                 Err(e) => println!("Error parsing input: {e}"),
+//!             }
+//!         }
+//!         None => println!("No input provided."),
+//!     }
+//! }
+//!
+//! ```
+//!
+//! Now let's build the project's binary file so we can run it from the command line:
+//!
+//! ```bash
+//! cargo build --release
+//! ```
+//!
+//! Our runnable binary file should be located at the local path `./target/release/my_ladders_project` (or `./target/release/my_ladders_project.exe` for Windows). Let's run it with the number `12` as input:
+//!
+//! ```bash
+//! ./target/release/my_ladderz_project 12
+//! ```
+//!
+//! If you have a `.exe` file instead, you can run it with:
+//!
+//! ```bash
+//! ./target/release/my_ladderz_project.exe 12
+//! ```
+//!
+//! The printed output should be:
+//!
+//! ```
+//! List of factors of 12: [1, 2, 3, 4, 6, 12]
+//! List of factor pairs of 12: [(1, 12), (2, 6), (3, 4)]
+//! ```
+//!
+//! Great! We've successfully used the `ladderz` crate to get the factors and factor pairs of a number in sorted order.
 
 /// Various pre-algebra implementations including factor pairs, factors, multiples, and more.
 pub mod pre_algebra;
diff --git a/src/ladderz/pre_algebra/unit1.rs.html b/src/ladderz/pre_algebra/unit1.rs.html
index d7899e9..24ad1d6 100644
--- a/src/ladderz/pre_algebra/unit1.rs.html
+++ b/src/ladderz/pre_algebra/unit1.rs.html
@@ -441,13 +441,13 @@
 }
 
 /// 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`).
@@ -515,7 +515,7 @@
 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 {
+    for num in n..end + 1 {
         if num % n == 0 {
             multiples.insert(num);
         }
@@ -556,7 +556,7 @@
         assert_eq!(result, expected);
 
         let result_2: bool = false;
-        let expected_2: bool =  is_factor(3, 10);
+        let expected_2: bool = is_factor(3, 10);
         assert_eq!(result_2, expected_2);
     }