mirror of
https://github.com/rzmk/ladderz.git
synced 2025-12-19 06:59:25 +00:00
deploy: 6bbf891052
This commit is contained in:
parent
4eed7e25fa
commit
c202923651
9 changed files with 62 additions and 287 deletions
|
|
@ -1,68 +1,15 @@
|
|||
<!DOCTYPE html><html lang="en"><head><meta charset="utf-8"><meta name="viewport" content="width=device-width, initial-scale=1.0"><meta name="generator" content="rustdoc"><meta name="description" content="ladderz"><title>ladderz - Rust</title><link rel="preload" as="font" type="font/woff2" crossorigin href="../static.files/SourceSerif4-Regular-46f98efaafac5295.ttf.woff2"><link rel="preload" as="font" type="font/woff2" crossorigin href="../static.files/FiraSans-Regular-018c141bf0843ffd.woff2"><link rel="preload" as="font" type="font/woff2" crossorigin href="../static.files/FiraSans-Medium-8f9a781e4970d388.woff2"><link rel="preload" as="font" type="font/woff2" crossorigin href="../static.files/SourceCodePro-Regular-562dcc5011b6de7d.ttf.woff2"><link rel="preload" as="font" type="font/woff2" crossorigin href="../static.files/SourceSerif4-Bold-a2c9cd1067f8b328.ttf.woff2"><link rel="preload" as="font" type="font/woff2" crossorigin href="../static.files/SourceCodePro-Semibold-d899c5a5c4aeb14a.ttf.woff2"><link rel="stylesheet" href="../static.files/normalize-76eba96aa4d2e634.css"><link rel="stylesheet" href="../static.files/rustdoc-9bb858ba049f1f21.css" id="mainThemeStyle"><meta name="rustdoc-vars" data-root-path="../" data-static-root-path="../static.files/" data-current-crate="ladderz" data-themes="" data-resource-suffix="" data-rustdoc-version="1.72.1 (d5c2e9c34 2023-09-13)" data-channel="1.72.1" data-search-js="search-f6292fe389d70017.js" data-settings-js="settings-de11bff964e9d4e5.js" data-settings-css="settings-8c76f75bfb6bd192.css" data-theme-light-css="light-0f8c037637f9eb3e.css" data-theme-dark-css="dark-1097f8e92a01e3cf.css" data-theme-ayu-css="ayu-614652228113ac93.css" ><script src="../static.files/storage-59fd9b8ccb335783.js"></script><script defer src="../crates.js"></script><script defer src="../static.files/main-0795b7d26be81095.js"></script><noscript><link rel="stylesheet" media="(prefers-color-scheme:light)" href="../static.files/light-0f8c037637f9eb3e.css"><link rel="stylesheet" media="(prefers-color-scheme:dark)" href="../static.files/dark-1097f8e92a01e3cf.css"><link rel="stylesheet" href="../static.files/noscript-13285aec31fa243e.css"></noscript><link rel="alternate icon" type="image/png" href="../static.files/favicon-16x16-8b506e7a72182f1c.png"><link rel="alternate icon" type="image/png" href="../static.files/favicon-32x32-422f7d1d52889060.png"><link rel="icon" type="image/svg+xml" href="../static.files/favicon-2c020d218678b618.svg"></head><body class="rustdoc mod crate"><!--[if lte IE 11]><div class="warning">This old browser is unsupported and will most likely display funky things.</div><![endif]--><nav class="mobile-topbar"><button class="sidebar-menu-toggle">☰</button><a class="logo-container" href="../ladderz/index.html"><img class="rust-logo" src="../static.files/rust-logo-151179464ae7ed46.svg" alt="logo"></a><h2></h2></nav><nav class="sidebar"><a class="logo-container" href="../ladderz/index.html"><img class="rust-logo" src="../static.files/rust-logo-151179464ae7ed46.svg" alt="logo"></a><h2 class="location"><a href="#">Crate ladderz</a></h2><div class="sidebar-elems"><ul class="block"><li class="version">Version 0.1.0</li><li><a id="all-types" href="all.html">All Items</a></li></ul><section><ul class="block"><li><a href="#modules">Modules</a></li></ul></section></div></nav><main><div class="width-limiter"><nav class="sub"><form class="search-form"><span></span><input class="search-input" name="search" aria-label="Run search in the documentation" autocomplete="off" spellcheck="false" placeholder="Click or press ‘S’ to search, ‘?’ for more options…" type="search"><div id="help-button" title="help" tabindex="-1"><a href="../help.html">?</a></div><div id="settings-menu" tabindex="-1"><a href="../settings.html" title="settings"><img width="22" height="22" alt="Change settings" src="../static.files/wheel-7b819b6101059cd0.svg"></a></div></form></nav><section id="main-content" class="content"><div class="main-heading"><h1>Crate <a class="mod" href="#">ladderz</a><button id="copy-path" title="Copy item path to clipboard"><img src="../static.files/clipboard-7571035ce49a181d.svg" width="19" height="18" alt="Copy item path"></button></h1><span class="out-of-band"><a class="srclink" href="../src/ladderz/lib.rs.html#1-112">source</a> · <button id="toggle-all-docs" title="collapse all docs">[<span>−</span>]</button></span></div><details class="toggle top-doc" open><summary class="hideme"><span>Expand description</span></summary><div class="docblock"><h2 id="ladderz"><a href="#ladderz">ladderz</a></h2>
|
||||
<!DOCTYPE html><html lang="en"><head><meta charset="utf-8"><meta name="viewport" content="width=device-width, initial-scale=1.0"><meta name="generator" content="rustdoc"><meta name="description" content="ladderz"><title>ladderz - Rust</title><link rel="preload" as="font" type="font/woff2" crossorigin href="../static.files/SourceSerif4-Regular-46f98efaafac5295.ttf.woff2"><link rel="preload" as="font" type="font/woff2" crossorigin href="../static.files/FiraSans-Regular-018c141bf0843ffd.woff2"><link rel="preload" as="font" type="font/woff2" crossorigin href="../static.files/FiraSans-Medium-8f9a781e4970d388.woff2"><link rel="preload" as="font" type="font/woff2" crossorigin href="../static.files/SourceCodePro-Regular-562dcc5011b6de7d.ttf.woff2"><link rel="preload" as="font" type="font/woff2" crossorigin href="../static.files/SourceSerif4-Bold-a2c9cd1067f8b328.ttf.woff2"><link rel="preload" as="font" type="font/woff2" crossorigin href="../static.files/SourceCodePro-Semibold-d899c5a5c4aeb14a.ttf.woff2"><link rel="stylesheet" href="../static.files/normalize-76eba96aa4d2e634.css"><link rel="stylesheet" href="../static.files/rustdoc-9bb858ba049f1f21.css" id="mainThemeStyle"><meta name="rustdoc-vars" data-root-path="../" data-static-root-path="../static.files/" data-current-crate="ladderz" data-themes="" data-resource-suffix="" data-rustdoc-version="1.72.1 (d5c2e9c34 2023-09-13)" data-channel="1.72.1" data-search-js="search-f6292fe389d70017.js" data-settings-js="settings-de11bff964e9d4e5.js" data-settings-css="settings-8c76f75bfb6bd192.css" data-theme-light-css="light-0f8c037637f9eb3e.css" data-theme-dark-css="dark-1097f8e92a01e3cf.css" data-theme-ayu-css="ayu-614652228113ac93.css" ><script src="../static.files/storage-59fd9b8ccb335783.js"></script><script defer src="../crates.js"></script><script defer src="../static.files/main-0795b7d26be81095.js"></script><noscript><link rel="stylesheet" media="(prefers-color-scheme:light)" href="../static.files/light-0f8c037637f9eb3e.css"><link rel="stylesheet" media="(prefers-color-scheme:dark)" href="../static.files/dark-1097f8e92a01e3cf.css"><link rel="stylesheet" href="../static.files/noscript-13285aec31fa243e.css"></noscript><link rel="alternate icon" type="image/png" href="../static.files/favicon-16x16-8b506e7a72182f1c.png"><link rel="alternate icon" type="image/png" href="../static.files/favicon-32x32-422f7d1d52889060.png"><link rel="icon" type="image/svg+xml" href="../static.files/favicon-2c020d218678b618.svg"></head><body class="rustdoc mod crate"><!--[if lte IE 11]><div class="warning">This old browser is unsupported and will most likely display funky things.</div><![endif]--><nav class="mobile-topbar"><button class="sidebar-menu-toggle">☰</button><a class="logo-container" href="../ladderz/index.html"><img class="rust-logo" src="../static.files/rust-logo-151179464ae7ed46.svg" alt="logo"></a><h2></h2></nav><nav class="sidebar"><a class="logo-container" href="../ladderz/index.html"><img class="rust-logo" src="../static.files/rust-logo-151179464ae7ed46.svg" alt="logo"></a><h2 class="location"><a href="#">Crate ladderz</a></h2><div class="sidebar-elems"><ul class="block"><li class="version">Version 0.1.0</li><li><a id="all-types" href="all.html">All Items</a></li></ul><section><ul class="block"><li><a href="#modules">Modules</a></li></ul></section></div></nav><main><div class="width-limiter"><nav class="sub"><form class="search-form"><span></span><input class="search-input" name="search" aria-label="Run search in the documentation" autocomplete="off" spellcheck="false" placeholder="Click or press ‘S’ to search, ‘?’ for more options…" type="search"><div id="help-button" title="help" tabindex="-1"><a href="../help.html">?</a></div><div id="settings-menu" tabindex="-1"><a href="../settings.html" title="settings"><img width="22" height="22" alt="Change settings" src="../static.files/wheel-7b819b6101059cd0.svg"></a></div></form></nav><section id="main-content" class="content"><div class="main-heading"><h1>Crate <a class="mod" href="#">ladderz</a><button id="copy-path" title="Copy item path to clipboard"><img src="../static.files/clipboard-7571035ce49a181d.svg" width="19" height="18" alt="Copy item path"></button></h1><span class="out-of-band"><a class="srclink" href="../src/ladderz/lib.rs.html#1-45">source</a> · <button id="toggle-all-docs" title="collapse all docs">[<span>−</span>]</button></span></div><details class="toggle top-doc" open><summary class="hideme"><span>Expand description</span></summary><div class="docblock"><h2 id="ladderz"><a href="#ladderz">ladderz</a></h2>
|
||||
<p>Implementations of mathematical and technical concepts in Rust.</p>
|
||||
<h2 id="subjects"><a href="#subjects">Subjects</a></h2>
|
||||
<p>The modules for currently supported subjects are:</p>
|
||||
<ul>
|
||||
<li><a href="pre_algebra/index.html" title="mod ladderz::pre_algebra">pre_algebra</a> - Various pre-algebra implementations including factor pairs, factors, multiples, and more.</li>
|
||||
</ul>
|
||||
<h2 id="example"><a href="#example">Example</a></h2>
|
||||
<p>Here’s an example of using the <code>ladderz</code> crate to get the factors and factor pairs of a positive integer in sorted order.
|
||||
We’ll assume you’re using Bash as your terminal.</p>
|
||||
<p>First let’s create a new Rust project and change into the project directory:</p>
|
||||
<div class="example-wrap"><pre class="language-bash"><code>cargo new my_ladderz_project
|
||||
cd my_ladderz_project
|
||||
</code></pre></div>
|
||||
<p>Then let’s add the following to <code>Cargo.toml</code> under the <code>[dependencies]</code> section:</p>
|
||||
<h2 id="installing-the-crate"><a href="#installing-the-crate">Installing the crate</a></h2>
|
||||
<p>To add the crate to your project, add the following dependency under your <code>[dependencies]</code> section in your <code>Cargo.toml</code>:</p>
|
||||
<div class="example-wrap"><pre class="language-toml"><code>ladderz = { git = "https://github.com/rzmk/ladderz", branch = "main" }
|
||||
</code></pre></div>
|
||||
<p>Now in <code>src/main.rs</code> let’s replace the contents with the following code:</p>
|
||||
</code></pre></div><h2 id="example"><a href="#example">Example</a></h2>
|
||||
<div class="example-wrap"><pre class="rust rust-example-rendered"><code><span class="kw">use </span>ladderz::pre_algebra::get_factors;
|
||||
|
||||
<div class="example-wrap"><pre class="rust rust-example-rendered"><code><span class="kw">use </span>ladderz::pre_algebra::{get_factors, get_factor_pairs};
|
||||
<span class="kw">use </span>std::env;
|
||||
|
||||
<span class="kw">fn </span>main() {
|
||||
<span class="comment">// Get user input as a Vec
|
||||
</span><span class="kw">let </span>args: Vec<String> = env::args().collect();
|
||||
|
||||
<span class="comment">// Check if input was provided
|
||||
</span><span class="kw">match </span>args.get(<span class="number">1</span>) {
|
||||
<span class="prelude-val">Some</span>(<span class="kw">_</span>) => {
|
||||
<span class="kw">match </span>args[<span class="number">1</span>].parse::<u32>() {
|
||||
<span class="comment">// Handle input that can be parsed as a u32
|
||||
</span><span class="prelude-val">Ok</span>(x) => {
|
||||
<span class="comment">// Convert the HashSet of factors of input x to a sorted Vec
|
||||
</span><span class="kw">let </span><span class="kw-2">mut </span>factors: Vec<u32> = get_factors(x).into_iter().collect::<Vec<u32>>();
|
||||
factors.sort();
|
||||
|
||||
<span class="comment">// Convert the HashSet of factor pairs of input x to a sorted Vec
|
||||
</span><span class="kw">let </span><span class="kw-2">mut </span>factor_pairs: Vec<(u32, u32)> =
|
||||
get_factor_pairs(x).into_iter().collect::<Vec<(u32, u32)>>();
|
||||
factor_pairs.sort();
|
||||
|
||||
<span class="comment">// Print the results
|
||||
</span><span class="macro">println!</span>(<span class="string">"List of factors of {:?}: {:?}"</span>, x, factors);
|
||||
<span class="macro">println!</span>(<span class="string">"List of factor pairs of {:?}: {:?}"</span>, x, factor_pairs);
|
||||
}
|
||||
<span class="comment">// Handle input that can't be parsed as a u32
|
||||
</span><span class="prelude-val">Err</span>(e) => <span class="macro">println!</span>(<span class="string">"Error parsing input: {e}"</span>),
|
||||
}
|
||||
}
|
||||
<span class="prelude-val">None </span>=> <span class="macro">println!</span>(<span class="string">"No input provided."</span>),
|
||||
}
|
||||
}
|
||||
<span class="kw">let </span>x: u32 = <span class="number">10</span>;
|
||||
<span class="macro">println!</span>(<span class="string">"The factors of {x} are {:?}."</span>, get_factors(x));</code></pre></div>
|
||||
<div class="example-wrap"><pre class="language-console"><code>The factors of 10 are {1, 5, 2, 10}.
|
||||
</code></pre></div>
|
||||
<p>Now let’s build the project’s binary file so we can run it from the command line:</p>
|
||||
<div class="example-wrap"><pre class="language-bash"><code>cargo build --release
|
||||
</code></pre></div>
|
||||
<p>Our runnable binary file should be located at the local path <code>./target/release/my_ladders_project</code> (or <code>./target/release/my_ladders_project.exe</code> for Windows). Let’s run it with the positive integer <code>12</code> as input:</p>
|
||||
<div class="example-wrap"><pre class="language-bash"><code>./target/release/my_ladderz_project 12
|
||||
</code></pre></div>
|
||||
<p>If you have a <code>.exe</code> file instead, you can run it with:</p>
|
||||
<div class="example-wrap"><pre class="language-bash"><code>./target/release/my_ladderz_project.exe 12
|
||||
</code></pre></div>
|
||||
<p>The printed output should be:</p>
|
||||
<div class="example-wrap"><pre class="language-console"><code>List of factors of 12: [1, 2, 3, 4, 6, 12]
|
||||
List of factor pairs of 12: [(1, 12), (2, 6), (3, 4)]
|
||||
</code></pre></div>
|
||||
<p>Great! We’ve successfully used the <code>ladderz</code> crate to get the factors and factor pairs of a positive integer in sorted order.</p>
|
||||
<p>For a more detailed example of how to use the <code>ladderz</code> crate, please see the <a href="https://github.com/rzmk/ladderz#example">example on GitHub</a>.</p>
|
||||
<p>Choose a module to view its available functions.</p>
|
||||
</div></details><h2 id="modules" class="small-section-header"><a href="#modules">Modules</a></h2><ul class="item-table"><li><div class="item-name"><a class="mod" href="pre_algebra/index.html" title="mod ladderz::pre_algebra">pre_algebra</a></div><div class="desc docblock-short">Various pre-algebra implementations including factor pairs, factors, multiples, and more.</div></li></ul></section></div></main></body></html>
|
||||
File diff suppressed because one or more lines are too long
File diff suppressed because one or more lines are too long
File diff suppressed because one or more lines are too long
File diff suppressed because one or more lines are too long
File diff suppressed because one or more lines are too long
|
|
@ -2,9 +2,7 @@
|
|||
<h2 id="example"><a href="#example">Example</a></h2>
|
||||
<div class="example-wrap"><pre class="rust rust-example-rendered"><code><span class="kw">use </span>ladderz::pre_algebra::get_factors;
|
||||
|
||||
<span class="kw">fn </span>main() {
|
||||
<span class="kw">let </span>x: u32 = <span class="number">10</span>;
|
||||
<span class="macro">println!</span>(<span class="string">"The factors of {x} are {:?}."</span>, get_factors(x));
|
||||
}</code></pre></div>
|
||||
<span class="kw">let </span>x: u32 = <span class="number">10</span>;
|
||||
<span class="macro">println!</span>(<span class="string">"The factors of {x} are {:?}."</span>, get_factors(x));</code></pre></div>
|
||||
<div class="example-wrap"><pre class="language-console"><code>The factors of 10 are {1, 5, 2, 10}.
|
||||
</code></pre></div></div></details><h2 id="functions" class="small-section-header"><a href="#functions">Functions</a></h2><ul class="item-table"><li><div class="item-name"><a class="fn" href="fn.get_factor_pairs.html" title="fn ladderz::pre_algebra::get_factor_pairs">get_factor_pairs</a></div><div class="desc docblock-short">Finds all factor pairs for a positive integer <code>n</code>.</div></li><li><div class="item-name"><a class="fn" href="fn.get_factors.html" title="fn ladderz::pre_algebra::get_factors">get_factors</a></div><div class="desc docblock-short">Finds all factors of a positive integer <code>n</code>.</div></li><li><div class="item-name"><a class="fn" href="fn.get_multiples_in_range.html" title="fn ladderz::pre_algebra::get_multiples_in_range">get_multiples_in_range</a></div><div class="desc docblock-short">Finds all the multiples of a positive integer <code>n</code> up to and including <code>end</code> (in the range [n, end]).</div></li><li><div class="item-name"><a class="fn" href="fn.is_factor.html" title="fn ladderz::pre_algebra::is_factor">is_factor</a></div><div class="desc docblock-short">Checks if a positive integer <code>x</code> is a factor of another positive integer <code>y</code>.</div></li><li><div class="item-name"><a class="fn" href="fn.is_multiple.html" title="fn ladderz::pre_algebra::is_multiple">is_multiple</a></div><div class="desc docblock-short">Checks if a positive integer <code>x</code> is a multiple of another positive integer <code>y</code>.</div></li></ul></section></div></main></body></html>
|
||||
|
|
@ -43,166 +43,34 @@
|
|||
<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>
|
||||
<a href="#93" id="93">93</a>
|
||||
<a href="#94" id="94">94</a>
|
||||
<a href="#95" id="95">95</a>
|
||||
<a href="#96" id="96">96</a>
|
||||
<a href="#97" id="97">97</a>
|
||||
<a href="#98" id="98">98</a>
|
||||
<a href="#99" id="99">99</a>
|
||||
<a href="#100" id="100">100</a>
|
||||
<a href="#101" id="101">101</a>
|
||||
<a href="#102" id="102">102</a>
|
||||
<a href="#103" id="103">103</a>
|
||||
<a href="#104" id="104">104</a>
|
||||
<a href="#105" id="105">105</a>
|
||||
<a href="#106" id="106">106</a>
|
||||
<a href="#107" id="107">107</a>
|
||||
<a href="#108" id="108">108</a>
|
||||
<a href="#109" id="109">109</a>
|
||||
<a href="#110" id="110">110</a>
|
||||
<a href="#111" id="111">111</a>
|
||||
<a href="#112" id="112">112</a>
|
||||
</pre></div><pre class="rust"><code><span class="doccomment">//! # ladderz
|
||||
//!
|
||||
//! Implementations of mathematical and technical concepts in Rust.
|
||||
//!
|
||||
//! # Subjects
|
||||
//! # Installing the crate
|
||||
//!
|
||||
//! The modules for currently supported subjects are:
|
||||
//!
|
||||
//! - [pre_algebra] - Various pre-algebra implementations including factor pairs, factors, multiples, and more.
|
||||
//!
|
||||
//! # Example
|
||||
//!
|
||||
//! Here's an example of using the `ladderz` crate to get the factors and factor pairs of a positive integer 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:
|
||||
//! To add the crate to your project, add the following dependency under your `[dependencies]` section in your `Cargo.toml`:
|
||||
//!
|
||||
//! ```toml
|
||||
//! ladderz = { git = "https://github.com/rzmk/ladderz", branch = "main" }
|
||||
//! ```
|
||||
//!
|
||||
//! Now in `src/main.rs` let's replace the contents with the following code:
|
||||
//! # Example
|
||||
//!
|
||||
//! ```rust
|
||||
//! use ladderz::pre_algebra::{get_factors, get_factor_pairs};
|
||||
//! 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."),
|
||||
//! }
|
||||
//! }
|
||||
//!use ladderz::pre_algebra::get_factors;
|
||||
//!
|
||||
//!let x: u32 = 10;
|
||||
//!println!("The factors of {x} are {:?}.", get_factors(x));
|
||||
//! ```
|
||||
//!
|
||||
//! 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 positive integer `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:
|
||||
//!
|
||||
//! ```console
|
||||
//! List of factors of 12: [1, 2, 3, 4, 6, 12]
|
||||
//! List of factor pairs of 12: [(1, 12), (2, 6), (3, 4)]
|
||||
//! The factors of 10 are {1, 5, 2, 10}.
|
||||
//! ```
|
||||
//!
|
||||
//! Great! We've successfully used the `ladderz` crate to get the factors and factor pairs of a positive integer in sorted order.
|
||||
//! For a more detailed example of how to use the `ladderz` crate, please see the [example on GitHub](https://github.com/rzmk/ladderz#example).
|
||||
//!
|
||||
//! Choose a module to view its available functions.
|
||||
|
||||
/// Various pre-algebra implementations including factor pairs, factors, multiples, and more.
|
||||
///
|
||||
|
|
@ -211,10 +79,8 @@
|
|||
/// ```rust
|
||||
/// use ladderz::pre_algebra::get_factors;
|
||||
///
|
||||
/// fn main() {
|
||||
/// let x: u32 = 10;
|
||||
/// println!("The factors of {x} are {:?}.", get_factors(x));
|
||||
/// }
|
||||
/// ```
|
||||
///
|
||||
/// ```console
|
||||
|
|
|
|||
|
|
@ -200,17 +200,6 @@
|
|||
<a href="#200" id="200">200</a>
|
||||
<a href="#201" id="201">201</a>
|
||||
<a href="#202" id="202">202</a>
|
||||
<a href="#203" id="203">203</a>
|
||||
<a href="#204" id="204">204</a>
|
||||
<a href="#205" id="205">205</a>
|
||||
<a href="#206" id="206">206</a>
|
||||
<a href="#207" id="207">207</a>
|
||||
<a href="#208" id="208">208</a>
|
||||
<a href="#209" id="209">209</a>
|
||||
<a href="#210" id="210">210</a>
|
||||
<a href="#211" id="211">211</a>
|
||||
<a href="#212" id="212">212</a>
|
||||
<a href="#213" id="213">213</a>
|
||||
</pre></div><pre class="rust"><code><span class="kw">use </span>std::collections::HashSet;
|
||||
|
||||
<span class="doccomment">/// Finds all factor pairs for a positive integer `n`.
|
||||
|
|
@ -227,11 +216,9 @@
|
|||
/// use std::collections::HashSet;
|
||||
/// use ladderz::pre_algebra::get_factor_pairs;
|
||||
///
|
||||
/// fn main() {
|
||||
/// let result_pairs = get_factor_pairs(12);
|
||||
/// let expected_pairs: HashSet<(u32, u32)> = [(1, 12), (2, 6), (3, 4)].into();
|
||||
/// assert_eq!(result_pairs, expected_pairs);
|
||||
/// }
|
||||
/// ```
|
||||
///
|
||||
/// # Note
|
||||
|
|
@ -270,11 +257,9 @@
|
|||
/// use std::collections::HashSet;
|
||||
/// use ladderz::pre_algebra::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
|
||||
|
|
@ -302,10 +287,8 @@
|
|||
/// ```rust
|
||||
/// use ladderz::pre_algebra::is_factor;
|
||||
///
|
||||
/// fn main() {
|
||||
/// assert!(is_factor(2, 16)); // 2 is a factor of 16
|
||||
/// assert!(!is_factor(3, 16)); // 3 is not a factor of 16
|
||||
/// }
|
||||
/// ```
|
||||
///
|
||||
/// # Note
|
||||
|
|
@ -325,10 +308,8 @@
|
|||
/// ```rust
|
||||
/// use ladderz::pre_algebra::is_multiple;
|
||||
///
|
||||
/// fn main() {
|
||||
/// assert!(is_multiple(16, 2)); // 16 is a multiple of 2
|
||||
/// assert!(!is_multiple(16, 3)); // 16 is not a multiple of 3
|
||||
/// }
|
||||
/// ```
|
||||
</span><span class="kw">pub fn </span>is_multiple(x: u32, y: u32) -> bool {
|
||||
x % y == <span class="number">0
|
||||
|
|
@ -344,24 +325,16 @@
|
|||
/// use ladderz::pre_algebra::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);
|
||||
/// }
|
||||
/// ```
|
||||
</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">if </span>num % n == <span class="number">0 </span>{
|
||||
<span class="kw">for </span>num <span class="kw">in </span>(n..end + <span class="number">1</span>).step_by(n <span class="kw">as </span>usize) {
|
||||
multiples.insert(num);
|
||||
}
|
||||
}
|
||||
multiples
|
||||
}
|
||||
|
||||
|
|
@ -422,6 +395,11 @@
|
|||
<span class="kw">let </span>result_2: HashSet<u32> = get_multiples_in_range(<span class="number">5</span>, <span class="number">34</span>);
|
||||
<span class="kw">let </span>expected_2: HashSet<u32> = [<span class="number">5</span>, <span class="number">10</span>, <span class="number">15</span>, <span class="number">20</span>, <span class="number">25</span>, <span class="number">30</span>].into();
|
||||
<span class="macro">assert_eq!</span>(result_2, expected_2);
|
||||
|
||||
<span class="comment">// Test when the range has no multiples
|
||||
</span><span class="kw">let </span>result_3: HashSet<u32> = get_multiples_in_range(<span class="number">7</span>, <span class="number">11</span>);
|
||||
<span class="kw">let </span>expected_3: HashSet<u32> = [<span class="number">7</span>].into();
|
||||
<span class="macro">assert_eq!</span>(expected_3, result_3);
|
||||
}
|
||||
}
|
||||
</code></pre></div></section></main></body></html>
|
||||
Loading…
Add table
Add a link
Reference in a new issue