Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add Placing Parentheses and update README #2222

Open
wants to merge 11 commits into
base: master
from

Conversation

@srivastavaayu
Copy link

srivastavaayu commented Jul 21, 2020

Added Placing Parenthesis (the question is to maximize an expression by rearranging operands and operators) in the Dynamic Programming subdirectory.
Add repo license details with a link to the license file in the directory.

  • Add an algorithm?
  • Fix a bug or typo in an existing algorithm?
  • Documentation change?

Checklist:

  • I have read CONTRIBUTING.md.
  • This pull request is all my own work -- I have not plagiarized.
  • I know that pull requests will not be merged if they fail the automated tests.
  • This PR only changes one algorithm file. To ease review, please open separate PRs for separate algorithms.
  • All new Python files are placed inside an existing directory.
  • All filenames are in all lowercase characters with no spaces or dashes.
  • All functions and variable names follow Python naming conventions.
  • All function parameters and return values are annotated with Python type hints.
  • All functions have doctests that pass the automated testing.
  • All new algorithms have a URL in its comments that points to Wikipedia or other similar explanation.
  • If this pull request resolves one or more open issues then the commit message contains Fixes: #{$ISSUE_NO}.
Added Placing Parenthesis (the question is to maximize an expression by rearranging operands and operators) in Dynamic Programming subdirectory.
Add repo license details with a link to the license file in the directory.
@TravisBuddy
Copy link

TravisBuddy commented Jul 21, 2020

Hey @srivastavaayu,
Something went wrong with the build.

TravisCI finished with status errored, which means the build failed because of something unrelated to the tests, such as a problem with a dependency or the build process itself.

View build log

TravisBuddy Request Identifier: d9303e30-cb93-11ea-96be-d1d226963d5e
Copy link
Contributor

ruppysuppy left a comment

Read the CONTRIBUTING.md and add type hints, doctests and proper flake8 formatting

Copy link
Contributor

ruppysuppy left a comment

@cclauss, please review this one

@cclauss
Copy link
Member

cclauss commented Jul 22, 2020

Codespell says:

./dynamic_programming/parentheses.py:24: parantheses ==> parentheses
./dynamic_programming/parentheses.py:43: parantheses ==> parentheses
Updated parentheses.py with type hints, checked code formatting using black and flake8
@TravisBuddy
Copy link

TravisBuddy commented Jul 22, 2020

Travis tests have failed

Hey @srivastavaayu,
Please read the following log in order to understand the failure reason.
It'll be awesome if you fix what's wrong and commit the changes.

TravisBuddy Request Identifier: 4ac548a0-cc4e-11ea-acda-6fc69b852bf0
Updated parentheses.py with type hints, checked code formatting using black and flake8
@TravisBuddy
Copy link

TravisBuddy commented Jul 22, 2020

Travis tests have failed

Hey @srivastavaayu,
Please read the following log in order to understand the failure reason.
It'll be awesome if you fix what's wrong and commit the changes.

TravisBuddy Request Identifier: 93fbd1c0-cc52-11ea-acda-6fc69b852bf0
@cclauss
Copy link
Member

cclauss commented Jul 22, 2020

https://docs.python.org/3/library/operator.html

from operator import add, sub, mul, floordiv

operators = {
    "+": add,
    "-": sub,
    "*": mul,
    "/": floordiv,  # or truediv,
}


def calculate(a: int, b: int, op: str) -> int:
    return operators[op](a, b)
Update parentheses.py and now using built-in addition, subtraction, and multiplication operators and also renamed variables to reflect their purpose.
@TravisBuddy
Copy link

TravisBuddy commented Jul 22, 2020

Hey @srivastavaayu,
Something went wrong with the build.

TravisCI finished with status errored, which means the build failed because of something unrelated to the tests, such as a problem with a dependency or the build process itself.

View build log

TravisBuddy Request Identifier: 27f19b50-cc65-11ea-acda-6fc69b852bf0
parentheses.py Outdated Show resolved Hide resolved
srivastavaayu and others added 3 commits Jul 22, 2020
Update parentheses.py and now using built-in addition, subtraction, and multiplication operators and also renamed variables to reflect their purpose.
Co-authored-by: Christian Clauss <cclauss@me.com>
parentheses.py Outdated Show resolved Hide resolved
@TravisBuddy
Copy link

TravisBuddy commented Jul 22, 2020

Hey @srivastavaayu,
Something went wrong with the build.

TravisCI finished with status errored, which means the build failed because of something unrelated to the tests, such as a problem with a dependency or the build process itself.

View build log

TravisBuddy Request Identifier: 333e1aa0-cc66-11ea-acda-6fc69b852bf0
parentheses.py Outdated Show resolved Hide resolved
parentheses.py Outdated Show resolved Hide resolved
parentheses.py Outdated Show resolved Hide resolved
@TravisBuddy
Copy link

TravisBuddy commented Jul 22, 2020

Travis tests have failed

Hey @srivastavaayu,
Please read the following log in order to understand the failure reason.
It'll be awesome if you fix what's wrong and commit the changes.

TravisBuddy Request Identifier: 357ca380-cc67-11ea-acda-6fc69b852bf0
@srivastavaayu
Copy link
Author

srivastavaayu commented Jul 22, 2020

@cclauss I don't understand. I've possibly done every change suggested by you. Let me try and incorporate changes suggested by you once again. But is there any specific reason the build is failing?

Copy link
Member

cclauss left a comment

The main code with an input() statement must be indented under if __name__ == "__main__": to avoid hanging pytest. This is discussed in CONTRIBUTING.md.

README.md Outdated Show resolved Hide resolved
dynamic_programming/parentheses.py Show resolved Hide resolved

def calculate(first_operand, second_operand, operator) -> int:
"""
Return the value after evaluating the expression

This comment has been minimized.

@cclauss

cclauss Jul 23, 2020

Member

Type hints on function parameters needed and doc tests needed.

Please add the following doctest...

Suggested change
Return the value after evaluating the expression
Evaluate the expression and return the result.
>>> calculate("2+2") # add()
4
>>> calculate("2-2") # sub()
0
>>> calculate("2*2") # mul
4

Once this is done, on you local machine, do python3 -m doctest -v paraentheses.py

doctests are how we ensure that our function works the way that we think it should and how we document to others how it should be called.

return operators[operator](first_operand, second_operand)


def MinandMax(maximum_numbers, minimum_numbers, i, j, operator) -> int:

This comment has been minimized.

@cclauss

cclauss Jul 23, 2020

Member

Type hints on function parameters needed and doc tests needed.

dynamic_programming/parentheses.py Outdated Show resolved Hide resolved
dynamic_programming/parentheses.py Outdated Show resolved Hide resolved
dynamic_programming/parentheses.py Outdated Show resolved Hide resolved
srivastavaayu and others added 3 commits Jul 23, 2020
Co-authored-by: Christian Clauss <cclauss@me.com>
Co-authored-by: Christian Clauss <cclauss@me.com>
@srivastavaayu
Copy link
Author

srivastavaayu commented Jul 24, 2020

@cclauss All the tests have passed successfully. Please review this PR. And suggest changes, if any.

@poyea poyea self-assigned this Aug 2, 2020
Copy link
Member

poyea left a comment

@srivastavaayu Thanks for the contribution! Could you add a few doctests & type hints and comment (what's the expected input and output) in the code to demonstrate the function? We need these to have this landed. If you're in doubt, you can see our CONTRIBUTING.md that will give you a clearer idea.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Linked issues

Successfully merging this pull request may close these issues.

None yet

6 participants
You can’t perform that action at this time.