Skip to content

Fully refactored the rod cutting module. #1169

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

Merged
merged 4 commits into from
Sep 5, 2019

Conversation

maxwell-aladago
Copy link
Contributor

No description provided.


def rod_cutting(prices: List[int],length: int) -> int:
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

A List[int] is more strict than a list of anything.

Copy link
Contributor Author

@maxwell-aladago maxwell-aladago Sep 4, 2019

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Making a list[int] is too restrictive since the prices can be floats as well.
You can also have mixed prices like [1, 1.2, 3].

If values which do not work well with addition are provided, then a ValueError will be thrown. That's something a user should handle, I think.

Edit: Also, the return type can be float or int depending on the prices.

@cclauss

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Making a list[int] is too restrictive since the prices can be floats as well.
You can also have mixed prices like [1, 1.2, 3].

If values which do not work well with addition are provided, then a ValueError will be thrown. That's something a user should handle, I think.

Edit: Also, the return type can be float or int depending on the prices.

@cclauss

@cclauss, do you insist that I enforced the values of the prices to be integers?

Copy link
Member

@cclauss cclauss Sep 5, 2019

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nope. I am fine with supporting both int and float

@cclauss cclauss merged commit 2dfe01e into TheAlgorithms:master Sep 5, 2019
neelu065 added a commit to neelu065/Python that referenced this pull request May 23, 2020
stokhos pushed a commit to stokhos/Python that referenced this pull request Jan 3, 2021
* changing typo

* fully refactored the rod-cutting module

* more documentations

* rewording
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants