mirror of
https://github.com/rzmk/ladderz.git
synced 2025-12-19 06:59:25 +00:00
fix: use end variable instead of n for get_primes_in_range
This commit is contained in:
parent
2ec77987ef
commit
065c233986
2 changed files with 8 additions and 8 deletions
|
|
@ -192,7 +192,7 @@ pub fn is_composite(n: u32) -> bool {
|
|||
false
|
||||
}
|
||||
|
||||
/// Write a program that finds all prime numbers of a positive integer `n` in the range [start, n].
|
||||
/// Write a program that finds all prime numbers in the range [start, end] within the natural numbers.
|
||||
///
|
||||
/// A prime number is a positive integer greater than 1 that is
|
||||
/// not evenly divisible by any positive integer other than 1 and itself.
|
||||
|
|
@ -207,10 +207,10 @@ pub fn is_composite(n: u32) -> bool {
|
|||
/// let expected: HashSet<u32> = [2, 3, 5, 7].into();
|
||||
/// assert_eq!(result, expected);
|
||||
/// ```
|
||||
pub fn get_primes_in_range(start: u32, n: u32) -> HashSet<u32> {
|
||||
pub fn get_primes_in_range(start: u32, end: u32) -> HashSet<u32> {
|
||||
let mut primes: HashSet<u32> = HashSet::new();
|
||||
|
||||
for num in start..n + 1 {
|
||||
for num in start..end + 1 {
|
||||
if is_prime(num) {
|
||||
primes.insert(num);
|
||||
}
|
||||
|
|
|
|||
|
|
@ -284,11 +284,11 @@
|
|||
"cell_type": "markdown",
|
||||
"metadata": {},
|
||||
"source": [
|
||||
"**Write a program that finds all prime numbers of a positive integer `n` in the range `[start, n]`.**\n",
|
||||
"**Write a program that finds all prime numbers in the range `[start, end]` within the natural numbers.**\n",
|
||||
"\n",
|
||||
"- Assume that `start` and `n` are positive integers greater than or equal to 1.\n",
|
||||
"- Assume that `start` and `end` are positive integers greater than or equal to 1.\n",
|
||||
"\n",
|
||||
"For example for `start = 1` and `n = 20`, the output of `get_primes_in_range(1, 20)` may be:\n",
|
||||
"For example for `start = 1` and `end = 20`, the output of `get_primes_in_range(1, 20)` may be:\n",
|
||||
"\n",
|
||||
"```\n",
|
||||
"{2, 3, 5, 7, 11, 13, 17, 19}\n",
|
||||
|
|
@ -301,9 +301,9 @@
|
|||
"metadata": {},
|
||||
"outputs": [],
|
||||
"source": [
|
||||
"def get_primes_in_range(start: int, n: int) -> set:\n",
|
||||
"def get_primes_in_range(start: int, end: int) -> set:\n",
|
||||
" primes: set = set()\n",
|
||||
" for num in range(start, n + 1):\n",
|
||||
" for num in range(start, end + 1):\n",
|
||||
" if is_prime(num):\n",
|
||||
" primes.add(num)\n",
|
||||
" return primes\n",
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue