mirror of
https://github.com/rzmk/ladderz.git
synced 2025-12-19 06:59:25 +00:00
deploy: 3673f6df8e
This commit is contained in:
parent
48e3274c71
commit
a925f41d50
4 changed files with 246 additions and 8 deletions
|
|
@ -2,7 +2,183 @@
|
|||
<a href="#2" id="2">2</a>
|
||||
<a href="#3" id="3">3</a>
|
||||
<a href="#4" id="4">4</a>
|
||||
</pre></div><pre class="rust"><code><span class="doccomment">//! Implementations of mathematical and technical concepts in Rust.
|
||||
<a href="#5" id="5">5</a>
|
||||
<a href="#6" id="6">6</a>
|
||||
<a href="#7" id="7">7</a>
|
||||
<a href="#8" id="8">8</a>
|
||||
<a href="#9" id="9">9</a>
|
||||
<a href="#10" id="10">10</a>
|
||||
<a href="#11" id="11">11</a>
|
||||
<a href="#12" id="12">12</a>
|
||||
<a href="#13" id="13">13</a>
|
||||
<a href="#14" id="14">14</a>
|
||||
<a href="#15" id="15">15</a>
|
||||
<a href="#16" id="16">16</a>
|
||||
<a href="#17" id="17">17</a>
|
||||
<a href="#18" id="18">18</a>
|
||||
<a href="#19" id="19">19</a>
|
||||
<a href="#20" id="20">20</a>
|
||||
<a href="#21" id="21">21</a>
|
||||
<a href="#22" id="22">22</a>
|
||||
<a href="#23" id="23">23</a>
|
||||
<a href="#24" id="24">24</a>
|
||||
<a href="#25" id="25">25</a>
|
||||
<a href="#26" id="26">26</a>
|
||||
<a href="#27" id="27">27</a>
|
||||
<a href="#28" id="28">28</a>
|
||||
<a href="#29" id="29">29</a>
|
||||
<a href="#30" id="30">30</a>
|
||||
<a href="#31" id="31">31</a>
|
||||
<a href="#32" id="32">32</a>
|
||||
<a href="#33" id="33">33</a>
|
||||
<a href="#34" id="34">34</a>
|
||||
<a href="#35" id="35">35</a>
|
||||
<a href="#36" id="36">36</a>
|
||||
<a href="#37" id="37">37</a>
|
||||
<a href="#38" id="38">38</a>
|
||||
<a href="#39" id="39">39</a>
|
||||
<a href="#40" id="40">40</a>
|
||||
<a href="#41" id="41">41</a>
|
||||
<a href="#42" id="42">42</a>
|
||||
<a href="#43" id="43">43</a>
|
||||
<a href="#44" id="44">44</a>
|
||||
<a href="#45" id="45">45</a>
|
||||
<a href="#46" id="46">46</a>
|
||||
<a href="#47" id="47">47</a>
|
||||
<a href="#48" id="48">48</a>
|
||||
<a href="#49" id="49">49</a>
|
||||
<a href="#50" id="50">50</a>
|
||||
<a href="#51" id="51">51</a>
|
||||
<a href="#52" id="52">52</a>
|
||||
<a href="#53" id="53">53</a>
|
||||
<a href="#54" id="54">54</a>
|
||||
<a href="#55" id="55">55</a>
|
||||
<a href="#56" id="56">56</a>
|
||||
<a href="#57" id="57">57</a>
|
||||
<a href="#58" id="58">58</a>
|
||||
<a href="#59" id="59">59</a>
|
||||
<a href="#60" id="60">60</a>
|
||||
<a href="#61" id="61">61</a>
|
||||
<a href="#62" id="62">62</a>
|
||||
<a href="#63" id="63">63</a>
|
||||
<a href="#64" id="64">64</a>
|
||||
<a href="#65" id="65">65</a>
|
||||
<a href="#66" id="66">66</a>
|
||||
<a href="#67" id="67">67</a>
|
||||
<a href="#68" id="68">68</a>
|
||||
<a href="#69" id="69">69</a>
|
||||
<a href="#70" id="70">70</a>
|
||||
<a href="#71" id="71">71</a>
|
||||
<a href="#72" id="72">72</a>
|
||||
<a href="#73" id="73">73</a>
|
||||
<a href="#74" id="74">74</a>
|
||||
<a href="#75" id="75">75</a>
|
||||
<a href="#76" id="76">76</a>
|
||||
<a href="#77" id="77">77</a>
|
||||
<a href="#78" id="78">78</a>
|
||||
<a href="#79" id="79">79</a>
|
||||
<a href="#80" id="80">80</a>
|
||||
<a href="#81" id="81">81</a>
|
||||
<a href="#82" id="82">82</a>
|
||||
<a href="#83" id="83">83</a>
|
||||
<a href="#84" id="84">84</a>
|
||||
<a href="#85" id="85">85</a>
|
||||
<a href="#86" id="86">86</a>
|
||||
<a href="#87" id="87">87</a>
|
||||
<a href="#88" id="88">88</a>
|
||||
<a href="#89" id="89">89</a>
|
||||
<a href="#90" id="90">90</a>
|
||||
<a href="#91" id="91">91</a>
|
||||
<a href="#92" id="92">92</a>
|
||||
</pre></div><pre class="rust"><code><span class="doccomment">//! # 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.
|
||||
</span><span class="kw">pub mod </span>pre_algebra;
|
||||
|
|
|
|||
|
|
@ -441,13 +441,13 @@
|
|||
</span>}
|
||||
|
||||
<span class="doccomment">/// 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 @@
|
|||
</span><span class="kw">pub fn </span>get_multiples_in_range(n: u32, end: u32) -> HashSet<u32> {
|
||||
<span class="kw">let </span><span class="kw-2">mut </span>multiples: HashSet<u32> = HashSet::new();
|
||||
|
||||
<span class="kw">for </span>num <span class="kw">in </span>n..end+<span class="number">1 </span>{
|
||||
<span class="kw">for </span>num <span class="kw">in </span>n..end + <span class="number">1 </span>{
|
||||
<span class="kw">if </span>num % n == <span class="number">0 </span>{
|
||||
multiples.insert(num);
|
||||
}
|
||||
|
|
@ -556,7 +556,7 @@
|
|||
<span class="macro">assert_eq!</span>(result, expected);
|
||||
|
||||
<span class="kw">let </span>result_2: bool = <span class="bool-val">false</span>;
|
||||
<span class="kw">let </span>expected_2: bool = is_factor(<span class="number">3</span>, <span class="number">10</span>);
|
||||
<span class="kw">let </span>expected_2: bool = is_factor(<span class="number">3</span>, <span class="number">10</span>);
|
||||
<span class="macro">assert_eq!</span>(result_2, expected_2);
|
||||
}
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue