feat: initial commit

This is the initial commit for the project.
Began work on pre-algebra unit 1.
This commit is contained in:
rzmk 2023-09-18 23:47:49 -04:00
commit 7b17b94c14
No known key found for this signature in database
10 changed files with 249 additions and 0 deletions

View file

@ -0,0 +1,119 @@
{
"cells": [
{
"cell_type": "markdown",
"metadata": {},
"source": [
"# Unit 1: Factors and multiples"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"## Understanding Factor Pairs\n",
"\n",
"> [Link to lesson](https://www.khanacademy.org/math/pre-algebra/pre-algebra-factors-multiples/pre-algebra-factors-mult/v/understanding-factor-pairs).\n",
"\n",
"**Write a program that finds all the factor pairs for a given number $n$.**\n",
"\n",
"- Do not repeat any pairs (e.g., consider `(2, 8)` and `(8, 2)` as the same).\n",
"- Assume that $n$ is a positive integer greater than or equal to 1 ($n \\in \\mathbb{Z}^+$).\n",
"\n",
"For example for $n = 16$, the output of `get_factor_pairs(16)` may be:\n",
"\n",
"```\n",
"{(1, 16), (2, 8), (4, 4)}\n",
"```\n"
]
},
{
"cell_type": "code",
"execution_count": 25,
"metadata": {},
"outputs": [],
"source": [
"def get_factor_pairs(n: int) -> set:\n",
" factor_pairs: set = set()\n",
" for i in range(1, n + 1):\n",
" dividend: int = n\n",
" divisor: int = i\n",
" quotient: int = int(dividend / divisor)\n",
" remainder: int = dividend % divisor\n",
" if remainder == 0 and (quotient, divisor) not in factor_pairs:\n",
" factor_pairs.add((divisor, quotient))\n",
" return factor_pairs\n",
"\n",
"assert get_factor_pairs(1) == {(1, 1)}\n",
"assert get_factor_pairs(15) == {(1, 15), (3, 5)}\n",
"assert get_factor_pairs(16) == {(1, 16), (2, 8), (4, 4)}\n",
"assert get_factor_pairs(21) == {(1, 21), (3, 7)}\n",
"assert get_factor_pairs(26) == {(1, 26), (2, 13)}\n",
"assert get_factor_pairs(30) == {(1, 30), (2, 15), (3, 10), (5, 6)}\n",
"assert get_factor_pairs(40) == {(1, 40), (2, 20), (4, 10), (5, 8)}\n",
"assert get_factor_pairs(42) == {(1, 42), (2, 21), (3, 14), (6, 7)}\n",
"assert get_factor_pairs(66) == {(1, 66), (2, 33), (3, 22), (6, 11)}"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"## Finding factors of a number\n",
"\n",
"> [Link to lesson](https://www.khanacademy.org/math/pre-algebra/pre-algebra-factors-multiples/pre-algebra-factors-mult/v/finding-factors-of-a-number).\n",
"\n",
"**Write a program that finds all the factors of a given number $n$.** Assume that $n$ is a positive integer greater than or equal to 1 ($n \\in \\mathbb{Z}^+$).\n",
"\n",
"For example for $n = 16$, the output of `get_factors(16)` may be:\n",
"\n",
"```\n",
"{1, 2, 4, 8, 16}\n",
"```"
]
},
{
"cell_type": "code",
"execution_count": 27,
"metadata": {},
"outputs": [],
"source": [
"def get_factors(n: int) -> set:\n",
" factors: set = set()\n",
" for i in range(1, n + 1):\n",
" dividend: int = n\n",
" divisor: int = i\n",
" quotient: int = int(n / i)\n",
" remainder: int = n % i\n",
" if remainder == 0:\n",
" factors.add(quotient)\n",
" return factors\n",
"\n",
"assert get_factors(16) == {1, 2, 4, 8, 16}\n",
"assert get_factors(120) == {1, 2, 3, 4, 5, 6, 8, 10, 12, 15, 20, 24, 30, 40, 60, 120}"
]
}
],
"metadata": {
"kernelspec": {
"display_name": "venv",
"language": "python",
"name": "python3"
},
"language_info": {
"codemirror_mode": {
"name": "ipython",
"version": 3
},
"file_extension": ".py",
"mimetype": "text/x-python",
"name": "python",
"nbconvert_exporter": "python",
"pygments_lexer": "ipython3",
"version": "3.10.6"
},
"orig_nbformat": 4
},
"nbformat": 4,
"nbformat_minor": 2
}

View file

@ -0,0 +1,2 @@
ipykernel
jupyterlab