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

Added ✅ : josephus problem #2623

Merged
merged 5 commits into from
Dec 29, 2022
Merged

Conversation

srini047
Copy link
Contributor

Congrats on taking the first step to contributing to the Sample Programs repository maintained by The Renegade Coder!
For simplicity, please make sure that your pull request includes one and only one contribution.

Please fill one of the sections below as applicable.
Please also add any other relevant information to the Notes section at the bottom.
You may delete or just ignore any other sections.
For more information please refer to our contributing documentation

I Am Adding a New Code Snippet in an Existing Language

I Am Adding a New Code Snippet in a New Language

  • I fixed #your-issue-number-here
  • I named the pull request using Add {PROJECT} in {LANGUAGE} format
  • I added a testinfo.yml files (see [contributing documentation][contributing-new-language])
    • I used an officially supported docker image or one that I personally trust

I Am Adding New Tests for a Project

  • I fixed #your-issue-number-here
  • I named the pull request using Add {PROJECT} tests format
  • I verified the project exists on the Sample Programs Project List
  • I added tests for every test case in the Testing table of the project description for the given project. (See contributing documentation)

I Am Adding New Tests for a Language

  • I fixed #your-issue-number-here
  • I named the pull request using Add {LANGUAGE} tests format\
  • I added a testinfo.yml files (see [contributing documentation][contributing-new-language])
    • I used an officially supported docker image or one that I personally trust
  • I verified all tests are passing

I Am Modifying an Existing Code Snippet or Existing Tests

  • I fixed #your-issue-number-here
  • I have read about modifying existing code snippets or tests in the contributing documentation
  • I have explained why this modification is necessary either in the issue linked above or in the notes below
  • I named the pull request using Modify {PROJECT} {tests} in {LANGUAGE} format

Other Notes

Add notes here...

Copy link
Contributor

@github-actions github-actions bot left a comment

Choose a reason for hiding this comment

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

Hey @srini047! Thanks for contributing to this project! We are a rather small team, so it may take some time to process this request. In the meantime, there are several ways you can make yourself a part of The Renegade Coder community. For instance, you can:

Thanks for your help!

@jrg94 jrg94 self-assigned this Dec 19, 2022
@jrg94 jrg94 added enhancement Any code that improves the repo josephus problem See: https://sampleprograms.io/projects/josephus-problem/ labels Dec 19, 2022
@jrg94 jrg94 added this to the 1,000 Code Snippets milestone Dec 19, 2022
Copy link
Member

@jrg94 jrg94 left a comment

Choose a reason for hiding this comment

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

Really great start! I would take a peek at the docs: https://sampleprograms.io/projects/josephus-problem/

n and k should come from the command line (i.e., sys.argv).

@srini047 srini047 requested a review from jrg94 December 19, 2022 07:49
@srini047
Copy link
Contributor Author

Done with the necessary changes @jrg94

Copy link
Member

@jrg94 jrg94 left a comment

Choose a reason for hiding this comment

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

Looks awesome! The last print might be incorrect, but otherwise this looks good. Going to let the tests run once more before I officially merge.

@srini047
Copy link
Contributor Author

@jrg94 any updates on the test.

@jrg94
Copy link
Member

jrg94 commented Dec 28, 2022

Yes, sorry! I've been on vacation. Here are the test results (seems like a quick fix):

=================================== FAILURES ===================================
______ test_josephus_problem_valid[josephus_problem.py-sample input 5, 2] ______

description = 'sample input 5, 2', in_params = '5 2', expected = '3'
josephus_problem = Source(name: josephus_problem, path: /home/runner/work/sample-programs/sample-programs/archive/p/python)

    @project_test(ProjectType.JosephusProblem.key)
    @pytest.mark.parametrize(valid_permutations[0], valid_permutations[1],
                             ids=[p[0] for p in valid_permutations[1]])
    def test_josephus_problem_valid(description, in_params, expected, josephus_problem):
        actual = josephus_problem.run(params=in_params)
>       assert actual.replace('[', '').replace(']', '').strip() == expected
E       AssertionError: assert 'Safe place:  3' == '3'
E         - Safe place:  3
E         + 3

test/projects/test_josephus_problem.py:59: AssertionError
______ test_josephus_problem_valid[josephus_problem.py-sample input 7 3] _______

description = 'sample input 7 3', in_params = '7 3', expected = '4'
josephus_problem = Source(name: josephus_problem, path: /home/runner/work/sample-programs/sample-programs/archive/p/python)

    @project_test(ProjectType.JosephusProblem.key)
    @pytest.mark.parametrize(valid_permutations[0], valid_permutations[1],
                             ids=[p[0] for p in valid_permutations[1]])
    def test_josephus_problem_valid(description, in_params, expected, josephus_problem):
        actual = josephus_problem.run(params=in_params)
>       assert actual.replace('[', '').replace(']', '').strip() == expected
E       AssertionError: assert 'Safe place:  4' == '4'
E         - Safe place:  4
E         + 4

test/projects/test_josephus_problem.py:59: AssertionError
_____ test_josephus_problem_valid[josephus_problem.py-sample input 41, 4] ______

description = 'sample input 41, 4', in_params = '41 4', expected = '11'
josephus_problem = Source(name: josephus_problem, path: /home/runner/work/sample-programs/sample-programs/archive/p/python)

    @project_test(ProjectType.JosephusProblem.key)
    @pytest.mark.parametrize(valid_permutations[0], valid_permutations[1],
                             ids=[p[0] for p in valid_permutations[1]])
    def test_josephus_problem_valid(description, in_params, expected, josephus_problem):
        actual = josephus_problem.run(params=in_params)
>       assert actual.replace('[', '').replace(']', '').strip() == expected
E       AssertionError: assert 'Safe place:  11' == '11'
E         - Safe place:  11
E         + 11

test/projects/test_josephus_problem.py:59: AssertionError
================== 3 failed, 2201 passed in 750.15s (0:12:30) ==================

print("Usage: please input the total number of people and number of people to skip.")
exit(1)

print("Safe place: ", josephus(n, k))
Copy link
Member

Choose a reason for hiding this comment

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

Suggested change
print("Safe place: ", josephus(n, k))
print(josephus(n, k))

Copy link
Contributor Author

Choose a reason for hiding this comment

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

@jrg94 Changes addressed.

@jrg94 jrg94 merged commit 9fa03e7 into TheRenegadeCoder:main Dec 29, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement Any code that improves the repo josephus problem See: https://sampleprograms.io/projects/josephus-problem/
Projects
Status: Done
Development

Successfully merging this pull request may close these issues.

Add Josephus Problem in python
2 participants