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

1
.gitignore vendored Normal file
View file

@ -0,0 +1 @@
venv

7
LICENSE Normal file
View file

@ -0,0 +1,7 @@
Copyright (c) 2023 Mueez Khan
Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the “Software”), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED “AS IS”, WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.

21
README.md Normal file
View file

@ -0,0 +1,21 @@
# ladderz
> This is a non-production repository and is for learning to implement concepts in code.
The `ladderz` project is based on content from courses, primarily mathematical/technical concepts.
You may find the following primary resources:
- **[notebooks](notebooks)** - Jupyter notebooks with exercises and solutions in Python
- [**pre-algebra**](notebooks/pre-algebra) - Pre-algebra concepts
- **[ladderz](ladderz)** - A crate with implementations of concepts in a Rust library
> The repository is not required to have the most efficient implementations, but rather learning to implement the concepts in code is a main endeavor. You may prefer other repositories for more efficient code & use cases.
## Ideas
Not currently implemented, but ideas that may be useful:
- **py-ladderz** - A package for running implementations of mathematical concepts in Python
- **ladderz CLI** - A CLI tool for ladderz in Rust
- **ladderz App** - An interactive multi-platform (web, desktop, mobile) app potentially including visualizations, practice problems, & a course-like structure (potentially in Flutter or Tauri with Next.js & Rust)

14
ladderz/.gitignore vendored Normal file
View file

@ -0,0 +1,14 @@
# Generated by Cargo
# will have compiled files and executables
debug/
target/
# Remove Cargo.lock from gitignore if creating an executable, leave it for libraries
# More information here https://doc.rust-lang.org/cargo/guide/cargo-toml-vs-cargo-lock.html
Cargo.lock
# These are backup files generated by rustfmt
**/*.rs.bk
# MSVC Windows builds of rustc generate these, which store debugging information
*.pdb

16
ladderz/Cargo.toml Normal file
View file

@ -0,0 +1,16 @@
[package]
name = "ladderz"
version = "0.1.0"
edition = "2021"
# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html
[[bin]]
name = "ladderz"
src = "src/main.rs"
[lib]
name = "ladderz"
path = "src/lib.rs"
[dependencies]

4
ladderz/src/lib.rs Normal file
View file

@ -0,0 +1,4 @@
//! Non-production implementations of mathematical and technical concepts in Rust.
/// Various pre-algebra implementations including multiples (planned), factor pairs, etc.
pub mod pre_algebra;

View file

@ -0,0 +1,2 @@
/// Factors and multiples
pub mod unit1;

View file

@ -0,0 +1,63 @@
use std::collections::HashSet;
// TODO: Implement negative integers
/// Generates a `HashSet` of factor pairs for a given positive integer `n`.
///
/// This function calculates and returns a `HashSet` containing all unique factor pairs
/// of the input positive integer `n`. A factor pair is a pair of positive integers
/// `(a, b)` where `a` and `b` are both factors of `n` (i.e., `a * b == n`).
///
/// # Arguments
///
/// * `n` - The positive integer for which factor pairs are to be calculated.
///
/// # Returns
///
/// A `HashSet` containing all unique factor pairs of the input integer `n`.
///
/// # Examples
///
/// ```rust
/// use std::collections::HashSet;
/// use ladderz::pre_algebra::unit1::get_factor_pairs;
///
/// fn main() {
/// let result_pairs = get_factor_pairs(12);
/// let expected_pairs: HashSet<(u32, u32)> = [(1, 12), (2, 6), (3, 4)].into();
/// assert_eq!(result_pairs, expected_pairs);
/// }
/// ```
///
/// # Note
///
/// This function calculates factor pairs by iterating through positive integers from 1 to `n`
/// (inclusive) and checking if they divide `n` evenly. If they do, a factor pair `(a, b)` is
/// added to the `HashSet`. The function ensures that factor pairs are unique, so `(a, b)` and
/// `(b, a)` will not both appear in the set.
pub fn get_factor_pairs(n: u32) -> HashSet<(u32, u32)> {
let mut factor_pairs: HashSet<(u32, u32)> = HashSet::new();
for num in 1..n + 1 {
let dividend: u32 = n;
let divisor: u32 = num;
let quotient: u32 = dividend / num;
let remainder: u32 = dividend % num;
if remainder == 0 && !factor_pairs.contains(&(quotient, divisor)) {
factor_pairs.insert((divisor, quotient));
}
}
factor_pairs
}
#[cfg(test)]
mod tests {
use super::*;
#[test]
fn test_get_factor_pairs_1() {
let result: HashSet<(u32, u32)> = get_factor_pairs(1);
let expected: HashSet<(u32, u32)> = [(1, 1)].into();
assert_eq!(result, expected);
}
}

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