Merge pull request #1 from Todarith/master

sync fork to parent
This commit is contained in:
Luke Weiler
2020-10-14 14:17:59 -04:00
committed by GitHub
7 changed files with 207 additions and 1 deletions

31
.github/workflows/python-publish.yml vendored Normal file
View File

@@ -0,0 +1,31 @@
# This workflows will upload a Python Package using Twine when a release is created
# For more information see: https://help.github.com/en/actions/language-and-framework-guides/using-python-with-github-actions#publishing-to-package-registries
name: Upload Python Package
on:
release:
types: [created]
jobs:
deploy:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v2
- name: Set up Python
uses: actions/setup-python@v2
with:
python-version: '3.x'
- name: Install dependencies
run: |
python -m pip install --upgrade pip
pip install setuptools wheel twine
- name: Build and publish
env:
TWINE_USERNAME: ${{ secrets.PYPI_USERNAME }}
TWINE_PASSWORD: ${{ secrets.PYPI_PASSWORD }}
run: |
python setup.py sdist bdist_wheel
twine upload dist/*

41
CONTRIBUTING.md Normal file
View File

@@ -0,0 +1,41 @@
# Contributing
This project was created with contributions at it's core. We need your help to expand the reach of this project and open-source the generation of math problems.
## How You Can Help
### Coding Generators
As of right now, all of our generators are being coded in python. Your generator will be an object of the Generator class and will have a function created seperately.
Your object instantiation should follow this format:
```
#<title> = Generator("<Title>", <id>, <generalized problem>, <generalized solution>, <function name>)
```
and look something like this:
```
addition = Generator("Addition", 2, "a+b=", "c", additionFunc)
```
Your function should look something like the following:
```
def additionFunc(maxSum, maxAddend):
a = random.randint(0, maxAddend)
b = random.randint(0, min((maxSum-a), maxAddend)) #The highest value of b will be no higher than the maxsum minus the first number and no higher than the maxAddend as well
c = a+b
problem = str(a) + "+" + str(b) + "="
solution = str(c)
return problem, solution
```
Before coding, please check README.md to see if someone has already created the generator you plan to make.
Skillid is determined by the next available id as can be determined in the table.
### Provide Ideas
If you have an idea for a generator but don't have the time or know-how to create it, you can add it as an issue. If you have a lot of ideas, I would suggest adding them to the table in README.md so that they are easier for our team to manage.
## First Time Contributors
If you have never contributed to open source before here is a quick explanation of how to contribute.
* Fork this repository on Github. This creates a copy of the current code that you can edit and make changes to.
* Navigate to your fork and make your changes. This could be done by cloning and making changes locally on your computer. You can find many tutorials on this online. You could also edit directly on github if you don't have access to a text editor but doing this, you will not be able to test your function.
* Create a pull request. Navigate to (the math generator repository pull request tab)[https://github.com/Todarith/mathGenerator/pulls] and click New Pull Request. Then click compare accross forks. Select your fork and branch as the head branch and leave a description. Then click Create Pull Request.
* If all goes well, your request will be approved and your generator added. Congratulations!

View File

@@ -1,2 +1,29 @@
# mathGenerator # mathgenerator
A math problem generator, created for the purpose of giving self-studying students and teaching organizations the means to easily get access to random math problems to suit their needs. A math problem generator, created for the purpose of giving self-studying students and teaching organizations the means to easily get access to random math problems to suit their needs.
To try out generators, go to https://todarith.ml/generate/
If you have an idea for a generator, please add it as an issue and tag it with the "New Generator" label.
## Usage
The project can be install via pip
```
pip install mathgenerator
```
Here is an example of how you would generate an addition problem:
```
from mathgenerator import mathgen
#generate an addition problem
problem, solution = mathgen.addition()
```
## List of Generators
| Id | Skill | Example problem | Example Solution | Function Name | Status |
|------|----------------------------|-----------------|-------------------|----------------|-------------|
| 2 | Addition | 1+5= | 6 | addition | Complete |
| 3 | Subtraction | 9-4= | 5 | subtraction | Complete |
| 4 | Multiplication | 4*6= | 24 | | Not Started |
| 5 | Division | 4/2= | 2 | | Not Started |
| - | Factoring | x^2+x-6 | (x-2)(x+3) | | Not Started |
| - | Power Rule Differentiation | x^5 | 5x^4 | | Not Started |

View File

84
mathgenerator/mathgen.py Normal file
View File

@@ -0,0 +1,84 @@
import random
# || Generator class
class Generator:
def __init__(self, title, id, generalProb, generalSol, func):
self.title = title
self.id = id
self.generalProb = generalProb
self.generalSol = generalSol
self.func = func
def __str__(self):
return str(self.id) + " " + self.title + " " + self.generalProb + " " + self.generalSol
def __call__(self):
return self.func()
# || Functions
def additionFunc(maxSum = 99, maxAddend = 50):
a = random.randint(0, maxAddend)
b = random.randint(0, min((maxSum-a), maxAddend)) #The highest value of b will be no higher than the maxsum minus the first number and no higher than the maxAddend as well
c = a+b
problem = str(a) + "+" + str(b) + "="
solution = str(c)
return problem, solution
def subtractionFunc(maxMinuend = 99, maxDiff = 99):
a = random.randint(0, maxMinuend)
b = random.randint(max(0, (a-maxDiff)), a)
c = a-b
problem = str(a) + "-" + str(b) + "="
solution = str(c)
return problem, solution
def multiplicationFunc(maxRes = 99, maxMulti = 99):
a = random.randint(0, maxMulti)
b = random.randint(0, min(maxRes, maxMulti))
c = a*b
problem = str(a) + "*" + str(b) + "="
solution = str(c)
return problem, solution
def divisionFunc(maxRes = 99, maxDivid = 99):
a = random.randint(0, maxDivid)
b = random.randint(0, min(maxRes, maxDivid))
c = a/b
problem = str(a) + "/" + str(b) + "="
solution = str(c)
return problem, solution
def binaryComplement1sFunc(maxDigits = 10):
question = ''
answer = ''
for i in range(random.randint(1,maxDigits)):
temp = str(random.randint(0, 1))
question += temp
answer += "0" if temp == "1" else "1"
problem = question
solution = answer
return problem, solution
def moduloFunc(maxRes = 99, maxModulo= 99):
a = random.randint(0, maxModulo)
b = random.randint(0, min(maxRes, maxModulo))
c = a%b
problem = str(a) + "%" + str(b) + "="
solution = str(c)
return problem, solution
# || Class Instances
#Format is:
#<title> = Generator("<Title>", <id>, <generalized problem>, <generalized solution>, <function name>)
addition = Generator("Addition", 2, "a+b=", "c", additionFunc)
subtraction = Generator("Subtraction", 3, "a-b=", "c", subtractionFunc)
multiplication = Generator("Multiplication", 4, "a*b=", "c", multiplicationFunc)
division = Generator("Division", 5, "a/b=", "c", divisionFunc)
binaryComplement1s = Generator("binary_complement_1s", 6, "(1010)=", "0101", binaryComplement1sFunc)
modulo division = Generator("Modulo Division", 6, "a%b=", "c", moduloFunc)

3
setup.cfg Normal file
View File

@@ -0,0 +1,3 @@
# Inside of setup.cfg
[metadata]
description-file = README.md

20
setup.py Normal file
View File

@@ -0,0 +1,20 @@
from setuptools import setup, find_packages
setup(
name='mathgenerator',
version='1.0.2',
description='An open source solution for generating math problems',
url='https://github.com/todarith/mathgenerator',
author='Luke Weiler',
author_email='lukew25073@gmail.com',
license='MIT',
packages=find_packages(),
install_requires=[
],
entry_points={
'console_scripts': [
'mathgenerator=mathgenerator.generator:main'
],
},
)