This commit is contained in:
rzmk 2023-10-11 20:12:41 +00:00
parent 7dba531bf7
commit ce80fd62b7
9 changed files with 259 additions and 5 deletions

View file

@ -1 +1 @@
<!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="List of all items in this crate"><title>List of all items in this crate</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-cb6f1f67f1bcd037.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.73.0 (cc66ad468 2023-10-03)" data-channel="1.73.0" data-search-js="search-6dfdfced5eff6596.js" data-settings-js="settings-de11bff964e9d4e5.js" data-settings-css="settings-8c76f75bfb6bd192.css" data-theme-light-css="light-1596385f77d47ef2.css" data-theme-dark-css="dark-0a43001d3fc2282c.css" data-theme-ayu-css="ayu-fd19013d6ce078bf.css" ><script src="../static.files/storage-db41da1a38ea3cb8.js"></script><script defer src="../static.files/main-0795b7d26be81095.js"></script><noscript><link rel="stylesheet" media="(prefers-color-scheme:light)" href="../static.files/light-1596385f77d47ef2.css"><link rel="stylesheet" media="(prefers-color-scheme:dark)" href="../static.files/dark-0a43001d3fc2282c.css"><link rel="stylesheet" href="../static.files/noscript-cffde32267a19fd6.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"><!--[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">&#9776;</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"><section><ul class="block"><li><a href="#functions">Functions</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"><h1>List of all items</h1><h3 id="functions">Functions</h3><ul class="all-items"><li><a href="pre_algebra/fn.get_factor_pairs.html">pre_algebra::get_factor_pairs</a></li><li><a href="pre_algebra/fn.get_factors.html">pre_algebra::get_factors</a></li><li><a href="pre_algebra/fn.get_multiples_in_range.html">pre_algebra::get_multiples_in_range</a></li><li><a href="pre_algebra/fn.is_composite.html">pre_algebra::is_composite</a></li><li><a href="pre_algebra/fn.is_factor.html">pre_algebra::is_factor</a></li><li><a href="pre_algebra/fn.is_multiple.html">pre_algebra::is_multiple</a></li><li><a href="pre_algebra/fn.is_prime.html">pre_algebra::is_prime</a></li></ul></section></div></main></body></html>
<!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="List of all items in this crate"><title>List of all items in this crate</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-cb6f1f67f1bcd037.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.73.0 (cc66ad468 2023-10-03)" data-channel="1.73.0" data-search-js="search-6dfdfced5eff6596.js" data-settings-js="settings-de11bff964e9d4e5.js" data-settings-css="settings-8c76f75bfb6bd192.css" data-theme-light-css="light-1596385f77d47ef2.css" data-theme-dark-css="dark-0a43001d3fc2282c.css" data-theme-ayu-css="ayu-fd19013d6ce078bf.css" ><script src="../static.files/storage-db41da1a38ea3cb8.js"></script><script defer src="../static.files/main-0795b7d26be81095.js"></script><noscript><link rel="stylesheet" media="(prefers-color-scheme:light)" href="../static.files/light-1596385f77d47ef2.css"><link rel="stylesheet" media="(prefers-color-scheme:dark)" href="../static.files/dark-0a43001d3fc2282c.css"><link rel="stylesheet" href="../static.files/noscript-cffde32267a19fd6.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"><!--[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">&#9776;</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"><section><ul class="block"><li><a href="#functions">Functions</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"><h1>List of all items</h1><h3 id="functions">Functions</h3><ul class="all-items"><li><a href="pre_algebra/fn.get_factor_pairs.html">pre_algebra::get_factor_pairs</a></li><li><a href="pre_algebra/fn.get_factors.html">pre_algebra::get_factors</a></li><li><a href="pre_algebra/fn.get_multiples_in_range.html">pre_algebra::get_multiples_in_range</a></li><li><a href="pre_algebra/fn.get_prime_factorization.html">pre_algebra::get_prime_factorization</a></li><li><a href="pre_algebra/fn.get_primes_in_range.html">pre_algebra::get_primes_in_range</a></li><li><a href="pre_algebra/fn.is_composite.html">pre_algebra::is_composite</a></li><li><a href="pre_algebra/fn.is_factor.html">pre_algebra::is_factor</a></li><li><a href="pre_algebra/fn.is_multiple.html">pre_algebra::is_multiple</a></li><li><a href="pre_algebra/fn.is_prime.html">pre_algebra::is_prime</a></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

View file

@ -5,4 +5,4 @@
<span class="kw">let </span>x: u32 = <span class="number">10</span>;
<span class="macro">println!</span>(<span class="string">&quot;The factors of {x} are {:?}.&quot;</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_composite.html" title="fn ladderz::pre_algebra::is_composite">is_composite</a></div><div class="desc docblock-short">Checks if a positive integer <code>n</code> is a composite number.</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><li><div class="item-name"><a class="fn" href="fn.is_prime.html" title="fn ladderz::pre_algebra::is_prime">is_prime</a></div><div class="desc docblock-short">Checks if a positive integer <code>n</code> is a prime number.</div></li></ul></section></div></main></body></html>
</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.get_prime_factorization.html" title="fn ladderz::pre_algebra::get_prime_factorization">get_prime_factorization</a></div><div class="desc docblock-short">Write a program that determines the prime factorization of a positive integer <code>n</code>.</div></li><li><div class="item-name"><a class="fn" href="fn.get_primes_in_range.html" title="fn ladderz::pre_algebra::get_primes_in_range">get_primes_in_range</a></div><div class="desc docblock-short">Write a program that finds all prime numbers of a positive integer <code>n</code> in the range [start, n].</div></li><li><div class="item-name"><a class="fn" href="fn.is_composite.html" title="fn ladderz::pre_algebra::is_composite">is_composite</a></div><div class="desc docblock-short">Checks if a positive integer <code>n</code> is a composite number.</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><li><div class="item-name"><a class="fn" href="fn.is_prime.html" title="fn ladderz::pre_algebra::is_prime">is_prime</a></div><div class="desc docblock-short">Checks if a positive integer <code>n</code> is a prime number.</div></li></ul></section></div></main></body></html>

View file

@ -1 +1 @@
window.SIDEBAR_ITEMS = {"fn":["get_factor_pairs","get_factors","get_multiples_in_range","is_composite","is_factor","is_multiple","is_prime"]};
window.SIDEBAR_ITEMS = {"fn":["get_factor_pairs","get_factors","get_multiples_in_range","get_prime_factorization","get_primes_in_range","is_composite","is_factor","is_multiple","is_prime"]};

View file

@ -0,0 +1,11 @@
<!DOCTYPE html>
<html lang="en">
<head>
<meta http-equiv="refresh" content="0;URL=../../../ladderz/pre_algebra/fn.get_prime_factorization.html">
<title>Redirection</title>
</head>
<body>
<p>Redirecting to <a href="../../../ladderz/pre_algebra/fn.get_prime_factorization.html">../../../ladderz/pre_algebra/fn.get_prime_factorization.html</a>...</p>
<script>location.replace("../../../ladderz/pre_algebra/fn.get_prime_factorization.html" + location.search + location.hash);</script>
</body>
</html>

View file

@ -0,0 +1,11 @@
<!DOCTYPE html>
<html lang="en">
<head>
<meta http-equiv="refresh" content="0;URL=../../../ladderz/pre_algebra/fn.get_primes_in_range.html">
<title>Redirection</title>
</head>
<body>
<p>Redirecting to <a href="../../../ladderz/pre_algebra/fn.get_primes_in_range.html">../../../ladderz/pre_algebra/fn.get_primes_in_range.html</a>...</p>
<script>location.replace("../../../ladderz/pre_algebra/fn.get_primes_in_range.html" + location.search + location.hash);</script>
</body>
</html>

View file

@ -1,5 +1,5 @@
var searchIndex = JSON.parse('{\
"ladderz":{"doc":"ladderz","t":"AFFFFFFF","n":["pre_algebra","get_factor_pairs","get_factors","get_multiples_in_range","is_composite","is_factor","is_multiple","is_prime"],"q":[[0,"ladderz"],[1,"ladderz::pre_algebra"]],"d":["Various pre-algebra implementations including factor …","Finds all factor pairs for a positive integer <code>n</code>.","Finds all factors of a positive integer <code>n</code>.","Finds all the multiples of a positive integer <code>n</code> up to and …","Checks if a positive integer <code>n</code> is a composite number.","Checks if a positive integer <code>x</code> is a factor of another …","Checks if a positive integer <code>x</code> is a multiple of another …","Checks if a positive integer <code>n</code> is a prime number."],"i":[0,0,0,0,0,0,0,0],"f":[0,[1,2],[1,[[2,[1]]]],[[1,1],[[2,[1]]]],[1,3],[[1,1],3],[[1,1],3],[1,3]],"c":[],"p":[[15,"u32"],[3,"HashSet"],[15,"bool"]]}\
"ladderz":{"doc":"ladderz","t":"AFFFFFFFFF","n":["pre_algebra","get_factor_pairs","get_factors","get_multiples_in_range","get_prime_factorization","get_primes_in_range","is_composite","is_factor","is_multiple","is_prime"],"q":[[0,"ladderz"],[1,"ladderz::pre_algebra"]],"d":["Various pre-algebra implementations including factor …","Finds all factor pairs for a positive integer <code>n</code>.","Finds all factors of a positive integer <code>n</code>.","Finds all the multiples of a positive integer <code>n</code> up to and …","Write a program that determines the prime factorization of …","Write a program that finds all prime numbers of a positive …","Checks if a positive integer <code>n</code> is a composite number.","Checks if a positive integer <code>x</code> is a factor of another …","Checks if a positive integer <code>x</code> is a multiple of another …","Checks if a positive integer <code>n</code> is a prime number."],"i":[0,0,0,0,0,0,0,0,0,0],"f":[0,[1,2],[1,[[2,[1]]]],[[1,1],[[2,[1]]]],[1,[[3,[1,1]]]],[[1,1],[[2,[1]]]],[1,4],[[1,1],4],[[1,1],4],[1,4]],"c":[],"p":[[15,"u32"],[3,"HashSet"],[3,"HashMap"],[15,"bool"]]}\
}');
if (typeof window !== 'undefined' && window.initSearch) {window.initSearch(searchIndex)};
if (typeof exports !== 'undefined') {exports.searchIndex = searchIndex};

View file

@ -276,7 +276,112 @@
<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;
<a href="#279" id="279">279</a>
<a href="#280" id="280">280</a>
<a href="#281" id="281">281</a>
<a href="#282" id="282">282</a>
<a href="#283" id="283">283</a>
<a href="#284" id="284">284</a>
<a href="#285" id="285">285</a>
<a href="#286" id="286">286</a>
<a href="#287" id="287">287</a>
<a href="#288" id="288">288</a>
<a href="#289" id="289">289</a>
<a href="#290" id="290">290</a>
<a href="#291" id="291">291</a>
<a href="#292" id="292">292</a>
<a href="#293" id="293">293</a>
<a href="#294" id="294">294</a>
<a href="#295" id="295">295</a>
<a href="#296" id="296">296</a>
<a href="#297" id="297">297</a>
<a href="#298" id="298">298</a>
<a href="#299" id="299">299</a>
<a href="#300" id="300">300</a>
<a href="#301" id="301">301</a>
<a href="#302" id="302">302</a>
<a href="#303" id="303">303</a>
<a href="#304" id="304">304</a>
<a href="#305" id="305">305</a>
<a href="#306" id="306">306</a>
<a href="#307" id="307">307</a>
<a href="#308" id="308">308</a>
<a href="#309" id="309">309</a>
<a href="#310" id="310">310</a>
<a href="#311" id="311">311</a>
<a href="#312" id="312">312</a>
<a href="#313" id="313">313</a>
<a href="#314" id="314">314</a>
<a href="#315" id="315">315</a>
<a href="#316" id="316">316</a>
<a href="#317" id="317">317</a>
<a href="#318" id="318">318</a>
<a href="#319" id="319">319</a>
<a href="#320" id="320">320</a>
<a href="#321" id="321">321</a>
<a href="#322" id="322">322</a>
<a href="#323" id="323">323</a>
<a href="#324" id="324">324</a>
<a href="#325" id="325">325</a>
<a href="#326" id="326">326</a>
<a href="#327" id="327">327</a>
<a href="#328" id="328">328</a>
<a href="#329" id="329">329</a>
<a href="#330" id="330">330</a>
<a href="#331" id="331">331</a>
<a href="#332" id="332">332</a>
<a href="#333" id="333">333</a>
<a href="#334" id="334">334</a>
<a href="#335" id="335">335</a>
<a href="#336" id="336">336</a>
<a href="#337" id="337">337</a>
<a href="#338" id="338">338</a>
<a href="#339" id="339">339</a>
<a href="#340" id="340">340</a>
<a href="#341" id="341">341</a>
<a href="#342" id="342">342</a>
<a href="#343" id="343">343</a>
<a href="#344" id="344">344</a>
<a href="#345" id="345">345</a>
<a href="#346" id="346">346</a>
<a href="#347" id="347">347</a>
<a href="#348" id="348">348</a>
<a href="#349" id="349">349</a>
<a href="#350" id="350">350</a>
<a href="#351" id="351">351</a>
<a href="#352" id="352">352</a>
<a href="#353" id="353">353</a>
<a href="#354" id="354">354</a>
<a href="#355" id="355">355</a>
<a href="#356" id="356">356</a>
<a href="#357" id="357">357</a>
<a href="#358" id="358">358</a>
<a href="#359" id="359">359</a>
<a href="#360" id="360">360</a>
<a href="#361" id="361">361</a>
<a href="#362" id="362">362</a>
<a href="#363" id="363">363</a>
<a href="#364" id="364">364</a>
<a href="#365" id="365">365</a>
<a href="#366" id="366">366</a>
<a href="#367" id="367">367</a>
<a href="#368" id="368">368</a>
<a href="#369" id="369">369</a>
<a href="#370" id="370">370</a>
<a href="#371" id="371">371</a>
<a href="#372" id="372">372</a>
<a href="#373" id="373">373</a>
<a href="#374" id="374">374</a>
<a href="#375" id="375">375</a>
<a href="#376" id="376">376</a>
<a href="#377" id="377">377</a>
<a href="#378" id="378">378</a>
<a href="#379" id="379">379</a>
<a href="#380" id="380">380</a>
<a href="#381" id="381">381</a>
<a href="#382" id="382">382</a>
<a href="#383" id="383">383</a>
</pre></div><pre class="rust"><code><span class="kw">use </span>std::collections::{HashMap, HashSet};
<span class="doccomment">/// Finds all factor pairs for a positive integer `n`.
///
@ -470,6 +575,68 @@
<span class="bool-val">false
</span>}
<span class="doccomment">/// Write a program that finds all prime numbers of a positive integer `n` in the range [start, n].
///
/// 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
///
/// ```rust
/// use ladderz::pre_algebra::get_primes_in_range;
/// use std::collections::HashSet;
///
/// let result: HashSet&lt;u32&gt; = get_primes_in_range(2, 10);
/// let expected: HashSet&lt;u32&gt; = [2, 3, 5, 7].into();
/// assert_eq!(result, expected);
/// ```
</span><span class="kw">pub fn </span>get_primes_in_range(start: u32, n: u32) -&gt; HashSet&lt;u32&gt; {
<span class="kw">let </span><span class="kw-2">mut </span>primes: HashSet&lt;u32&gt; = HashSet::new();
<span class="kw">for </span>num <span class="kw">in </span>start..n + <span class="number">1 </span>{
<span class="kw">if </span>is_prime(num) {
primes.insert(num);
}
}
primes
}
<span class="doccomment">/// Write a program that determines the prime factorization of a positive integer `n`.
///
/// For example the prime factorization of 12 is 2&lt;sup&gt;2&lt;/sup&gt; * 3&lt;sup&gt;1&lt;/sup&gt;, and the output is a HashMap of the form
/// `[(2, 2), (3, 1)]` where the first element of each tuple is the prime factor and the second element is the exponent.
///
/// # Examples
///
/// ```rust
/// use ladderz::pre_algebra::get_prime_factorization;
/// use std::collections::HashMap;
///
/// let result: HashMap&lt;u32, u32&gt; = get_prime_factorization(12);
/// let expected: HashMap&lt;u32, u32&gt; = [(2, 2), (3, 1)].into();
/// assert_eq!(result, expected);
/// ```
</span><span class="kw">pub fn </span>get_prime_factorization(n: u32) -&gt; HashMap&lt;u32, u32&gt; {
<span class="kw">if </span>n == <span class="number">1 </span>{
<span class="kw">return </span>HashMap::new();
}
<span class="kw">let </span><span class="kw-2">mut </span>prime_factors: HashMap&lt;u32, u32&gt; = HashMap::new();
<span class="kw">let </span><span class="kw-2">mut </span>current_num: u32 = n;
<span class="kw">let </span>primes_of_n: HashSet&lt;u32&gt; = get_primes_in_range(<span class="number">2</span>, n);
<span class="kw">for </span>prime <span class="kw">in </span>primes_of_n {
<span class="kw">while </span>current_num % prime == <span class="number">0 </span>{
prime_factors
.entry(prime)
.and_modify(|e| <span class="kw-2">*</span>e += <span class="number">1</span>)
.or_insert(<span class="number">1</span>);
current_num /= prime;
}
}
prime_factors
}
<span class="attr">#[cfg(test)]
</span><span class="kw">mod </span>tests {
<span class="kw">use super</span>::<span class="kw-2">*</span>;
@ -553,5 +720,48 @@
<span class="macro">assert!</span>(is_composite(<span class="number">27</span>));
<span class="macro">assert!</span>(is_composite(<span class="number">51</span>));
}
<span class="attr">#[test]
</span><span class="kw">fn </span>test_get_primes_in_range() {
<span class="kw">let </span>result: HashSet&lt;u32&gt; = get_primes_in_range(<span class="number">2</span>, <span class="number">10</span>);
<span class="kw">let </span>expected: HashSet&lt;u32&gt; = [<span class="number">2</span>, <span class="number">3</span>, <span class="number">5</span>, <span class="number">7</span>].into();
<span class="macro">assert_eq!</span>(result, expected);
<span class="kw">let </span>result_2: HashSet&lt;u32&gt; = get_primes_in_range(<span class="number">1</span>, <span class="number">10</span>);
<span class="kw">let </span>expected_2: HashSet&lt;u32&gt; = [<span class="number">2</span>, <span class="number">3</span>, <span class="number">5</span>, <span class="number">7</span>].into();
<span class="macro">assert_eq!</span>(result_2, expected_2);
<span class="kw">let </span>result_3: HashSet&lt;u32&gt; = get_primes_in_range(<span class="number">1</span>, <span class="number">1</span>);
<span class="kw">let </span>expected_3: HashSet&lt;u32&gt; = [].into();
<span class="macro">assert_eq!</span>(result_3, expected_3);
<span class="kw">let </span>result_4: HashSet&lt;u32&gt; = get_primes_in_range(<span class="number">1</span>, <span class="number">50</span>);
<span class="kw">let </span>expected_4: HashSet&lt;u32&gt; =
[<span class="number">2</span>, <span class="number">3</span>, <span class="number">5</span>, <span class="number">7</span>, <span class="number">11</span>, <span class="number">13</span>, <span class="number">17</span>, <span class="number">19</span>, <span class="number">23</span>, <span class="number">29</span>, <span class="number">31</span>, <span class="number">37</span>, <span class="number">41</span>, <span class="number">43</span>, <span class="number">47</span>].into();
<span class="macro">assert_eq!</span>(result_4, expected_4);
}
<span class="attr">#[test]
</span><span class="kw">fn </span>test_get_prime_factorization() {
<span class="kw">let </span>result: HashMap&lt;u32, u32&gt; = get_prime_factorization(<span class="number">1</span>);
<span class="kw">let </span>expected: HashMap&lt;u32, u32&gt; = HashMap::new();
<span class="macro">assert_eq!</span>(result, expected);
<span class="kw">let </span>result_2: HashMap&lt;u32, u32&gt; = get_prime_factorization(<span class="number">12</span>);
<span class="kw">let </span>expected_2: HashMap&lt;u32, u32&gt; = [(<span class="number">2</span>, <span class="number">2</span>), (<span class="number">3</span>, <span class="number">1</span>)].into();
<span class="macro">assert_eq!</span>(result_2, expected_2);
<span class="kw">let </span>result_3: HashMap&lt;u32, u32&gt; = get_prime_factorization(<span class="number">16</span>);
<span class="kw">let </span>expected_3: HashMap&lt;u32, u32&gt; = [(<span class="number">2</span>, <span class="number">4</span>)].into();
<span class="macro">assert_eq!</span>(result_3, expected_3);
<span class="kw">let </span>result_4: HashMap&lt;u32, u32&gt; = get_prime_factorization(<span class="number">27</span>);
<span class="kw">let </span>expected_4: HashMap&lt;u32, u32&gt; = [(<span class="number">3</span>, <span class="number">3</span>)].into();
<span class="macro">assert_eq!</span>(result_4, expected_4);
<span class="kw">let </span>result_5: HashMap&lt;u32, u32&gt; = get_prime_factorization(<span class="number">51</span>);
<span class="kw">let </span>expected_5: HashMap&lt;u32, u32&gt; = [(<span class="number">3</span>, <span class="number">1</span>), (<span class="number">17</span>, <span class="number">1</span>)].into();
<span class="macro">assert_eq!</span>(result_5, expected_5);
}
}
</code></pre></div></section></main></body></html>