mirror of
https://github.com/rzmk/ladderz.git
synced 2025-12-19 06:59:25 +00:00
deploy: 1ad53495e8
This commit is contained in:
parent
4907e4232e
commit
1e5eef1394
8 changed files with 100 additions and 8 deletions
|
|
@ -241,6 +241,41 @@
|
|||
<a href="#241" id="241">241</a>
|
||||
<a href="#242" id="242">242</a>
|
||||
<a href="#243" id="243">243</a>
|
||||
<a href="#244" id="244">244</a>
|
||||
<a href="#245" id="245">245</a>
|
||||
<a href="#246" id="246">246</a>
|
||||
<a href="#247" id="247">247</a>
|
||||
<a href="#248" id="248">248</a>
|
||||
<a href="#249" id="249">249</a>
|
||||
<a href="#250" id="250">250</a>
|
||||
<a href="#251" id="251">251</a>
|
||||
<a href="#252" id="252">252</a>
|
||||
<a href="#253" id="253">253</a>
|
||||
<a href="#254" id="254">254</a>
|
||||
<a href="#255" id="255">255</a>
|
||||
<a href="#256" id="256">256</a>
|
||||
<a href="#257" id="257">257</a>
|
||||
<a href="#258" id="258">258</a>
|
||||
<a href="#259" id="259">259</a>
|
||||
<a href="#260" id="260">260</a>
|
||||
<a href="#261" id="261">261</a>
|
||||
<a href="#262" id="262">262</a>
|
||||
<a href="#263" id="263">263</a>
|
||||
<a href="#264" id="264">264</a>
|
||||
<a href="#265" id="265">265</a>
|
||||
<a href="#266" id="266">266</a>
|
||||
<a href="#267" id="267">267</a>
|
||||
<a href="#268" id="268">268</a>
|
||||
<a href="#269" id="269">269</a>
|
||||
<a href="#270" id="270">270</a>
|
||||
<a href="#271" id="271">271</a>
|
||||
<a href="#272" id="272">272</a>
|
||||
<a href="#273" id="273">273</a>
|
||||
<a href="#274" id="274">274</a>
|
||||
<a href="#275" id="275">275</a>
|
||||
<a href="#276" id="276">276</a>
|
||||
<a href="#277" id="277">277</a>
|
||||
<a href="#278" id="278">278</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`.
|
||||
|
|
@ -381,8 +416,8 @@
|
|||
|
||||
<span class="doccomment">/// Checks if a positive integer `n` is a prime number.
|
||||
///
|
||||
/// A prime number is a positive integer greater than 1 that cannot
|
||||
/// be evenly divisible by any positive integers other than 1 and itself.
|
||||
/// A prime number is a positive integer greater than 1 that is
|
||||
/// not evenly divisible by any positive integer other than 1 and itself.
|
||||
///
|
||||
/// # Examples
|
||||
///
|
||||
|
|
@ -411,6 +446,30 @@
|
|||
<span class="bool-val">true
|
||||
</span>}
|
||||
|
||||
<span class="doccomment">/// Checks if a positive integer `n` is a composite number.
|
||||
///
|
||||
/// A composite number is a positive integer that is evenly divisible
|
||||
/// by a positive integer other than 1 and itself.
|
||||
///
|
||||
/// # Examples
|
||||
///
|
||||
/// ```rust
|
||||
/// use ladderz::pre_algebra::is_composite;
|
||||
///
|
||||
/// assert!(!is_composite(1)); // 1 is not a composite number
|
||||
/// assert!(!is_composite(2)); // 2 is not a composite number
|
||||
/// assert!(is_composite(4)); // 4 is a composite number
|
||||
/// assert!(!is_composite(7)); // 7 is not a composite number
|
||||
/// ```
|
||||
</span><span class="kw">pub fn </span>is_composite(n: u32) -> bool {
|
||||
<span class="kw">for </span>num <span class="kw">in </span><span class="number">1</span>..n {
|
||||
<span class="kw">if </span>n % num == <span class="number">0 </span>&& num != <span class="number">1 </span>&& num != n {
|
||||
<span class="kw">return </span><span class="bool-val">true</span>;
|
||||
}
|
||||
}
|
||||
<span class="bool-val">false
|
||||
</span>}
|
||||
|
||||
<span class="attr">#[cfg(test)]
|
||||
</span><span class="kw">mod </span>tests {
|
||||
<span class="kw">use super</span>::<span class="kw-2">*</span>;
|
||||
|
|
@ -483,5 +542,16 @@
|
|||
<span class="macro">assert!</span>(is_prime(<span class="number">23</span>));
|
||||
<span class="macro">assert!</span>(!is_prime(<span class="number">9514</span>));
|
||||
}
|
||||
|
||||
<span class="attr">#[test]
|
||||
</span><span class="kw">fn </span>test_is_composite() {
|
||||
<span class="macro">assert!</span>(!is_composite(<span class="number">1</span>));
|
||||
<span class="macro">assert!</span>(!is_composite(<span class="number">2</span>));
|
||||
<span class="macro">assert!</span>(!is_composite(<span class="number">3</span>));
|
||||
<span class="macro">assert!</span>(is_composite(<span class="number">4</span>));
|
||||
<span class="macro">assert!</span>(is_composite(<span class="number">8</span>));
|
||||
<span class="macro">assert!</span>(is_composite(<span class="number">27</span>));
|
||||
<span class="macro">assert!</span>(is_composite(<span class="number">51</span>));
|
||||
}
|
||||
}
|
||||
</code></pre></div></section></main></body></html>
|
||||
Loading…
Add table
Add a link
Reference in a new issue