Skip to content

Update spiral_print.py #7674

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 15 commits into from
Oct 26, 2022

Conversation

kondekarshubham123
Copy link
Contributor

Describe your change:

Added another neat approach for same question with explaination

  • 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 Uncyclopedia or other similar explanation.
  • If this pull request resolves one or more open issues then the commit message contains Fixes: #{$ISSUE_NO}.

@algorithms-keeper algorithms-keeper bot added enhancement This PR modified some existing files awaiting reviews This PR is ready to be reviewed labels Oct 26, 2022
@algorithms-keeper algorithms-keeper bot added the tests are failing Do not merge until tests pass label Oct 26, 2022
Copy link
Contributor

@CaedenPH CaedenPH left a comment

Choose a reason for hiding this comment

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

It seems Stage 3. and Stage 4. are the same. Is this intentional?

# Other Easy to undersatnd Approach


def spiral_traversal(matrix: List[List[int]]) -> List[int]:
Copy link
Contributor

Choose a reason for hiding this comment

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

Suggested change
def spiral_traversal(matrix: List[List[int]]) -> List[int]:
def spiral_traversal(matrix: list[list[int]]) -> list[int]:

kondekarshubham123 and others added 4 commits October 26, 2022 19:55
Co-authored-by: Caeden Perelli-Harris <[email protected]>
Co-authored-by: Caeden Perelli-Harris <[email protected]>
Co-authored-by: Caeden Perelli-Harris <[email protected]>
Co-authored-by: Caeden Perelli-Harris <[email protected]>
@algorithms-keeper algorithms-keeper bot removed the tests are failing Do not merge until tests pass label Oct 26, 2022
@algorithms-keeper algorithms-keeper bot added tests are failing Do not merge until tests pass and removed tests are failing Do not merge until tests pass labels Oct 26, 2022
@kondekarshubham123
Copy link
Contributor Author

Changes did as per mentioned, please review again @cclauss , @CaedenPH

Regards,
Shubham

@cclauss
Copy link
Member

cclauss commented Oct 26, 2022

Please do not ask for reviews when tests are failing (❌ ) because we have ~200 pull requests and this is a volunteer activity.

@kondekarshubham123
Copy link
Contributor Author

Okay I do understand.

@algorithms-keeper algorithms-keeper bot added the tests are failing Do not merge until tests pass label Oct 26, 2022
@cclauss
Copy link
Member

cclauss commented Oct 26, 2022

You can run the tests on your machine with python3 -m doctest -v matrix/spiral_print.py

=================================== FAILURES ===================================
________________ [doctest] matrix.spiral_print.spiral_traversal ________________
083 
084     >>> spiral_traversal([[1, 2, 3, 4], [5, 6, 7, 8], [9, 10, 11, 12]])
UNEXPECTED EXCEPTION: RecursionError('maximum recursion depth exceeded while calling a Python object')
Traceback (most recent call last):
  File "/opt/hostedtoolcache/Python/3.10.8/x64/lib/python3.10/doctest.py", line 1350, in __run
    exec(compile(example.source, filename, "single",
  File "<doctest matrix.spiral_print.spiral_traversal[0]>", line 1, in <module>
  File "/home/runner/work/Python/Python/matrix/spiral_print.py", line 127, in spiral_traversal
    return list(matrix.pop(0)) + spiral_traversal(list(zip(*matrix))[::-1])
  File "/home/runner/work/Python/Python/matrix/spiral_print.py", line 127, in spiral_traversal
    return list(matrix.pop(0)) + spiral_traversal(list(zip(*matrix))[::-1])
  File "/home/runner/work/Python/Python/matrix/spiral_print.py", line 127, in spiral_traversal
    return list(matrix.pop(0)) + spiral_traversal(list(zip(*matrix))[::-1])
  [Previous line repeated 961 more times]
RecursionError: maximum recursion depth exceeded while calling a Python object
/home/runner/work/Python/Python/matrix/spiral_print.py:84: UnexpectedException

@kondekarshubham123
Copy link
Contributor Author

kondekarshubham123 commented Oct 26, 2022

yes, will see and resolve, messed in base condition

@kondekarshubham123
Copy link
Contributor Author

kondekarshubham123 commented Oct 26, 2022

After above update on running
python3 -m doctest -v matrix/spiral_print.py
I'm getting this as op

2 items had no tests:
    spiral_print
    spiral_print.check_matrix
2 items passed all tests:
   1 tests in spiral_print.spiral_print_clockwise
   1 tests in spiral_print.spiral_traversal
2 tests in 4 items.
2 passed and 0 failed.
Test passed.

@algorithms-keeper algorithms-keeper bot removed the tests are failing Do not merge until tests pass label Oct 26, 2022
@algorithms-keeper algorithms-keeper bot removed the awaiting reviews This PR is ready to be reviewed label Oct 26, 2022
@cclauss cclauss merged commit 614274a into TheAlgorithms:master Oct 26, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement This PR modified some existing files
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants