-
Notifications
You must be signed in to change notification settings - Fork 20k
Fixes(#2884) #2955
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
Fixes(#2884) #2955
Changes from 1 commit
Commits
Show all changes
40 commits
Select commit
Hold shift + click to select a range
38daad8
Fixes: #{2391}
siddhant2002 a417229
Fixes #(2391)
siddhant2002 4cd2497
Merge branch 'TheAlgorithms:master' into master
siddhant2002 e3c28dc
Delete String_Comparision.java
siriak 0e97ad8
Merge branch 'master' into master
siriak f27eff4
Fixes: #{2820}
siddhant2002 bdc2a8a
Merge branch 'TheAlgorithms:master' into master
siddhant2002 9e77af5
Fixes #{2820}
siddhant2002 3cacb76
Merge branch 'master' of https://github.com/siddhant2002/Java
siddhant2002 a192de6
Fixes(#2450)
siddhant2002 516c7b9
Merge branch 'TheAlgorithms:master' into master
siddhant2002 10e58e3
string Codes removed
siddhant2002 c62aea7
Merge branch 'master' into master
siddhant2002 d24fdf2
fixes(#2882)
siddhant2002 30615b3
Merge branch 'master' of https://github.com/siddhant2002/Java
siddhant2002 20261bf
Merge branch 'TheAlgorithms:master' into master
siddhant2002 f9fc81e
Fixes(2882)
siddhant2002 86b0102
Merge branch 'master' of https://github.com/siddhant2002/Java
siddhant2002 f5a0937
Merge branch 'TheAlgorithms:master' into master
siddhant2002 a214d7f
Merge branch 'TheAlgorithms:master' into master
siddhant2002 e136a3b
Fixes(#2877)
siddhant2002 e5541ed
Merge branch 'master' of https://github.com/siddhant2002/Java
siddhant2002 6220cee
Fixes(#2877)
siddhant2002 ab73827
Fixes(#2877)
siddhant2002 17009fc
Merge branch 'TheAlgorithms:master' into master
siddhant2002 f903458
Fixes(#2877)
siddhant2002 2467c8c
Merge branch 'master' of https://github.com/siddhant2002/Java
siddhant2002 ababfa4
Fixes(#2877)
siddhant2002 255e4df
Fixes(#2877)
siddhant2002 a404bdc
Fixes(#2873)
siddhant2002 fd6dd28
Merge branch 'TheAlgorithms:master' into master
siddhant2002 ddad2bd
Merge branch 'master' into master
siriak 6902ee7
Merge branch 'TheAlgorithms:master' into master
siddhant2002 3b541ff
Merge branch 'TheAlgorithms:master' into master
siddhant2002 484d122
Fixes(#2884)
siddhant2002 08819aa
Merge branch 'master' of https://github.com/siddhant2002/Java
siddhant2002 26ac95e
Fixes(#2884)
siddhant2002 5ceffa0
Fixes(#2884)
siddhant2002 e0c8cc9
Fixes(#2884)
siddhant2002 31826c0
Fixes(#2884)
siddhant2002 File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
26 changes: 26 additions & 0 deletions
26
src/main/java/com/thealgorithms/dynamicprogramming/NewManShanksPrime.java
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
/** Author : Siddhant Swarup Mallick | ||
* Github : https://github.com/siddhant2002 | ||
*/ | ||
|
||
|
||
/** Program description - To find the New Man Shanks Prime. */ | ||
/** Wikipedia Link - https://en.wikipedia.org/wiki/Newman%E2%80%93Shanks%E2%80%93Williams_prime */ | ||
|
||
package com.thealgorithms.dynamicprogramming; | ||
|
||
public class NewManShanksPrime { | ||
public static boolean newManShanksPrime(int n , int answer) | ||
{ | ||
int a[] = new int[n+1]; | ||
// array of n+1 size is initialized | ||
a[0] = a[1] = 1; | ||
// The 0th and 1st index position values are fixed. They are initialized as 1 | ||
for(int i=2;i<=n;i++) | ||
{ | ||
a[i]=2*a[i-1]+a[i-2]; | ||
} | ||
// The loop is continued till n | ||
return a[n]==answer; | ||
// Calculated sum is checked with the expected answer | ||
} | ||
} |
54 changes: 54 additions & 0 deletions
54
src/test/java/com/thealgorithms/others/NewManShanksPrimeTest.java
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,54 @@ | ||
package com.thealgorithms.others; | ||
import org.junit.jupiter.api.Test; | ||
import static org.junit.jupiter.api.Assertions.*; | ||
|
||
import com.thealgorithms.dynamicprogramming.NewManShanksPrime; | ||
public class NewManShanksPrimeTest { | ||
@Test | ||
void testForOneElement() | ||
{ | ||
assertTrue(NewManShanksPrime.newManShanksPrime(1,1)); | ||
} | ||
|
||
@Test | ||
void testForTwoElements() | ||
{ | ||
assertTrue(NewManShanksPrime.newManShanksPrime(2,3)); | ||
} | ||
|
||
@Test | ||
void testForThreeElements() | ||
{ | ||
assertTrue(NewManShanksPrime.newManShanksPrime(3,7)); | ||
} | ||
|
||
@Test | ||
void testForFourElements() | ||
{ | ||
assertTrue(NewManShanksPrime.newManShanksPrime(4,17)); | ||
} | ||
|
||
@Test | ||
void testForFiveElements() | ||
{ | ||
assertTrue(NewManShanksPrime.newManShanksPrime(5,41)); | ||
} | ||
|
||
@Test | ||
void testForSixElements() | ||
{ | ||
assertTrue(NewManShanksPrime.newManShanksPrime(6,99)); | ||
} | ||
|
||
@Test | ||
void testForSevenElements() | ||
{ | ||
assertTrue(NewManShanksPrime.newManShanksPrime(7,239)); | ||
} | ||
|
||
@Test | ||
void testForEightElements() | ||
{ | ||
assertTrue(NewManShanksPrime.newManShanksPrime(8,577)); | ||
} | ||
} |
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.