Skip to content

Add solution to project euler problem 104 #3404

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

Closed
wants to merge 1 commit into from
Closed

Add solution to project euler problem 104 #3404

wants to merge 1 commit into from

Conversation

ayoubc
Copy link
Contributor

@ayoubc ayoubc commented Oct 17, 2020

Describe your change:

  • 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}.

@ayoubc
Copy link
Contributor Author

ayoubc commented Oct 29, 2020

Kind reminder: @dhruvmanila can you please review this PR.

"""
from typing import List

base = [[1, 1], [1, 0]]
Copy link
Member

Choose a reason for hiding this comment

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

If this is a constant please convert the name to all uppercase: BASE

base = [[1, 1], [1, 0]]


def matrix_product(a: List[list], b: List[list], mod: int = None) -> List[list]:
Copy link
Member

Choose a reason for hiding this comment

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

Descriptive names would look even better :)

Make an alias for the type hint of matrix and then use it everywhere:
Matrix = List[List[int]]

Also, the type hint for mod is incorrect, as it has a default value of None, it basically means the argument is optional. Use: Optional[int]. You will have to import it using from typing import Optional

return tmp


def fib(k: int, mod: int = None) -> int:
Copy link
Member

Choose a reason for hiding this comment

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

Descriptive variable names, please. Again, use Optional[int]

>>> is_pandigital('839725641')
True
"""
occ = [0] * 10
Copy link
Member

Choose a reason for hiding this comment

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

Descriptive variable names, please.
occ and maybe use letter instead of i?

return all(map(lambda x: x == 1, occ[1:]))


def solution() -> int:
Copy link
Member

Choose a reason for hiding this comment

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

Please look at point 4 and 5 of project_euler/README.md in the Coding style part: https://github.com/TheAlgorithms/Python/tree/master/project_euler#coding-style

@dhruvmanila dhruvmanila added require descriptive names This PR needs descriptive function and/or variable names require type hints https://docs.python.org/3/library/typing.html awaiting changes A maintainer has requested changes to this PR labels Nov 6, 2020
@stale
Copy link

stale bot commented Dec 6, 2020

This pull request has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs. Thank you for your contributions.

@stale stale bot added the stale Used to mark an issue or pull request stale. label Dec 6, 2020
@ayoubc ayoubc closed this Dec 9, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
awaiting changes A maintainer has requested changes to this PR require descriptive names This PR needs descriptive function and/or variable names require type hints https://docs.python.org/3/library/typing.html stale Used to mark an issue or pull request stale.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants