mirror of
https://github.com/rzmk/ladderz.git
synced 2025-12-19 06:59:25 +00:00
feat(pre-algebra): refactor to get_multiples_in_range & add to rust lib
This commit is contained in:
parent
8ed5716a83
commit
a8261965a6
2 changed files with 66 additions and 7 deletions
|
|
@ -173,11 +173,11 @@
|
|||
"cell_type": "markdown",
|
||||
"metadata": {},
|
||||
"source": [
|
||||
"**Write a program that finds all multiples of a given number $n$ up to a given limit $l$.**\n",
|
||||
"**Write a program that finds all multiples of a positive integer `n` in the range `[n, end]`.**\n",
|
||||
"\n",
|
||||
"- Assume that $n$ and $l$ are positive integers greater than or equal to 1 ($n, l \\in \\mathbb{Z}^+$).\n",
|
||||
"- Assume that `n` and `end` are positive integers greater than or equal to 1.\n",
|
||||
"\n",
|
||||
"For example for $n = 3$ and $l = 20$, the output of `get_multiples(3, 20)` may be:\n",
|
||||
"For example for `n = 3` and `end = 20`, the output of `get_multiples_in_range(3, 20)` may be:\n",
|
||||
"\n",
|
||||
"```\n",
|
||||
"{3, 6, 9, 12, 15, 18}\n",
|
||||
|
|
@ -190,15 +190,15 @@
|
|||
"metadata": {},
|
||||
"outputs": [],
|
||||
"source": [
|
||||
"def get_multiples(n: int, l: int) -> set:\n",
|
||||
"def get_multiples_in_range(n: int, end: int) -> set:\n",
|
||||
" multiples = set()\n",
|
||||
" for num in range(n, l + 1):\n",
|
||||
" for num in range(n, end + 1):\n",
|
||||
" if num % n == 0:\n",
|
||||
" multiples.add(num)\n",
|
||||
" return multiples\n",
|
||||
"\n",
|
||||
"assert get_multiples(3, 20) == {3, 6, 9, 12, 15, 18}\n",
|
||||
"assert get_multiples(5, 50) == {5, 10, 15, 20, 25, 30, 35, 40, 45, 50}"
|
||||
"assert get_multiples_in_range(3, 20) == {3, 6, 9, 12, 15, 18}\n",
|
||||
"assert get_multiples_in_range(5, 50) == {5, 10, 15, 20, 25, 30, 35, 40, 45, 50}"
|
||||
]
|
||||
}
|
||||
],
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue