-
Notifications
You must be signed in to change notification settings - Fork 63
faster permutations, based on what rdeits suggested #122
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
Changes from 3 commits
Commits
Show all changes
24 commits
Select commit
Hold shift + click to select a range
7e87322
update permutations to what rdeits suggested
natemcintosh 4ec6e8f
remove old code
natemcintosh 11faf25
add suggestions from bkamins
natemcintosh d19eb42
add offset arrays for testing purposes only
natemcintosh 9a16a25
add necessary libs to test dependencies
natemcintosh 5deef9c
Added tests for offsetarrays
natemcintosh 6584e8b
Apply suggestions from code review
natemcintosh cd561c1
all tests now passing
natemcintosh 6324a53
apply whitespace suggestions
natemcintosh 14e4713
try to make julia 1.0 happy
natemcintosh f315d65
Add OffsetArrays as a test dependency
natemcintosh 6a97953
Apply suggestions from code review
natemcintosh 188e69b
everything seems to be working now
natemcintosh b759984
Return empty vector for invalid t args
natemcintosh 0b34a6b
special case for t=1
natemcintosh f5db942
updates to reduce size of type union
natemcintosh 4bd818b
A few more explanatory comments
natemcintosh 1828493
Add suggestions
natemcintosh 182b67e
Change name of iterator to match convention
natemcintosh 1bca991
Update src/permutations.jl
natemcintosh 1c5b304
Update src/permutations.jl
natemcintosh 86b7a3a
Update src/permutations.jl
natemcintosh 8c2ac68
Update src/permutations.jl
natemcintosh 8852542
fix tests, and don't use Big
natemcintosh 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
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
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 |
|---|---|---|
| @@ -1,43 +1,46 @@ | ||
| @test [combinations([])...] == [] | ||
| @test [combinations(['a', 'b', 'c'])...] == [['a'],['b'],['c'],['a','b'],['a','c'],['b','c'],['a','b','c']] | ||
|
|
||
| @test [combinations("abc",3)...] == [['a','b','c']] | ||
| @test [combinations("abc",2)...] == [['a','b'],['a','c'],['b','c']] | ||
| @test [combinations("abc",1)...] == [['a'],['b'],['c']] | ||
| @test [combinations("abc",0)...] == [[]] | ||
| @test [combinations("abc",-1)...] == [] | ||
|
|
||
| @test filter(x->iseven(x[1]),[combinations([1,2,3],2)...]) == Any[[2,3]] | ||
|
|
||
| # multiset_combinations | ||
| @test [multiset_combinations("aabc", 5)...] == Any[] | ||
| @test [multiset_combinations("aabc", 2)...] == Any[['a','a'],['a','b'],['a','c'],['b','c']] | ||
| @test [multiset_combinations("aabc", 1)...] == Any[['a'],['b'],['c']] | ||
| @test [multiset_combinations("aabc", 0)...] == Any[Char[]] | ||
| @test [multiset_combinations("aabc", -1)...] == Any[] | ||
| @test [multiset_combinations("", 1)...] == Any[] | ||
| @test [multiset_combinations("", 0)...] == Any[Char[]] | ||
| @test [multiset_combinations("", -1)...] == Any[] | ||
|
|
||
| # with_replacement_combinations | ||
| @test [with_replacement_combinations("abc", 2)...] == Any[['a','a'],['a','b'],['a','c'], | ||
| ['b','b'],['b','c'],['c','c']] | ||
| @test [with_replacement_combinations("abc", 1)...] == Any[['a'],['b'],['c']] | ||
| @test [with_replacement_combinations("abc", 0)...] == Any[Char[]] | ||
| @test [with_replacement_combinations("abc", -1)...] == Any[] | ||
| @test [with_replacement_combinations("", 1)...] == Any[] | ||
| @test [with_replacement_combinations("", 0)...] == Any[Char[]] | ||
| @test [with_replacement_combinations("", -1)...] == Any[] | ||
|
|
||
|
|
||
| #cool-lex iterator | ||
| @test_throws DomainError [CoolLexCombinations(-1, 1)...] | ||
| @test_throws DomainError [CoolLexCombinations(5, 0)...] | ||
| @test [CoolLexCombinations(4,2)...] == Vector[[1,2], [2,3], [1,3], [2,4], [3,4], [1,4]] | ||
| @test isa(iterate(CoolLexCombinations(1000, 20))[2], Combinatorics.CoolLexIterState{BigInt}) | ||
|
|
||
| # Power set | ||
| @test collect(powerset([])) == Any[[]] | ||
| @test collect(powerset(['a', 'b', 'c'])) == Any[[],['a'],['b'],['c'],['a','b'],['a','c'],['b','c'],['a','b','c']] | ||
| @test collect(powerset(['a', 'b', 'c'], 1)) == Any[['a'],['b'],['c'],['a','b'],['a','c'],['b','c'],['a','b','c']] | ||
| @test collect(powerset(['a', 'b', 'c'], 1, 2)) == Any[['a'],['b'],['c'],['a','b'],['a','c'],['b','c']] | ||
| @testset "combinations" begin | ||
| @test [combinations([])...] == [] | ||
| @test [combinations(['a', 'b', 'c'])...] == [['a'], ['b'], ['c'], ['a', 'b'], ['a', 'c'], ['b', 'c'], ['a', 'b', 'c']] | ||
|
|
||
| @test [combinations("abc", 3)...] == [['a', 'b', 'c']] | ||
| @test [combinations("abc", 2)...] == [['a', 'b'], ['a', 'c'], ['b', 'c']] | ||
| @test [combinations("abc", 1)...] == [['a'], ['b'], ['c']] | ||
| @test [combinations("abc", 0)...] == [[]] | ||
| @test [combinations("abc", -1)...] == [] | ||
|
|
||
| @test filter(x -> iseven(x[1]), [combinations([1, 2, 3], 2)...]) == Any[[2, 3]] | ||
|
|
||
| # multiset_combinations | ||
| @test [multiset_combinations("aabc", 5)...] == Any[] | ||
| @test [multiset_combinations("aabc", 2)...] == Any[['a', 'a'], ['a', 'b'], ['a', 'c'], ['b', 'c']] | ||
| @test [multiset_combinations("aabc", 1)...] == Any[['a'], ['b'], ['c']] | ||
| @test [multiset_combinations("aabc", 0)...] == Any[Char[]] | ||
| @test [multiset_combinations("aabc", -1)...] == Any[] | ||
| @test [multiset_combinations("", 1)...] == Any[] | ||
| @test [multiset_combinations("", 0)...] == Any[Char[]] | ||
| @test [multiset_combinations("", -1)...] == Any[] | ||
|
|
||
| # with_replacement_combinations | ||
| @test [with_replacement_combinations("abc", 2)...] == Any[['a', 'a'], ['a', 'b'], ['a', 'c'], | ||
| ['b', 'b'], ['b', 'c'], ['c', 'c']] | ||
| @test [with_replacement_combinations("abc", 1)...] == Any[['a'], ['b'], ['c']] | ||
| @test [with_replacement_combinations("abc", 0)...] == Any[Char[]] | ||
| @test [with_replacement_combinations("abc", -1)...] == Any[] | ||
| @test [with_replacement_combinations("", 1)...] == Any[] | ||
| @test [with_replacement_combinations("", 0)...] == Any[Char[]] | ||
| @test [with_replacement_combinations("", -1)...] == Any[] | ||
|
|
||
|
|
||
| #cool-lex iterator | ||
| @test_throws DomainError [CoolLexCombinations(-1, 1)...] | ||
| @test_throws DomainError [CoolLexCombinations(5, 0)...] | ||
| @test [CoolLexCombinations(4, 2)...] == Vector[[1, 2], [2, 3], [1, 3], [2, 4], [3, 4], [1, 4]] | ||
| @test isa(iterate(CoolLexCombinations(1000, 20))[2], Combinatorics.CoolLexIterState{BigInt}) | ||
|
|
||
| # Power set | ||
| @test collect(powerset([])) == Any[[]] | ||
| @test collect(powerset(['a', 'b', 'c'])) == Any[[], ['a'], ['b'], ['c'], ['a', 'b'], ['a', 'c'], ['b', 'c'], ['a', 'b', 'c']] | ||
| @test collect(powerset(['a', 'b', 'c'], 1)) == Any[['a'], ['b'], ['c'], ['a', 'b'], ['a', 'c'], ['b', 'c'], ['a', 'b', 'c']] | ||
| @test collect(powerset(['a', 'b', 'c'], 1, 2)) == Any[['a'], ['b'], ['c'], ['a', 'b'], ['a', 'c'], ['b', 'c']] | ||
|
|
||
| end |
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 |
|---|---|---|
| @@ -1,38 +1,41 @@ | ||
| @test factorial(7,3) == 7*6*5*4 | ||
| @test_throws DomainError factorial(3,7) | ||
| @test_throws DomainError factorial(-3,-7) | ||
| @test_throws DomainError factorial(-7,-3) | ||
| #JuliaLang/julia#9943 | ||
| @test factorial(big(100), (80)) == 1303995018204712451095685346159820800000 | ||
| #JuliaLang/julia#9950 | ||
| @test_throws OverflowError factorial(1000,80) | ||
|
|
||
| # derangement | ||
| @test derangement(4) == subfactorial(4) == 9 | ||
| @test derangement(24) == parse(BigInt,"228250211305338670494289") | ||
|
|
||
| # partialderangement | ||
| @test partialderangement(7, 3) == 315 | ||
| @test_throws DomainError partialderangement(8, 9) | ||
| @test_throws DomainError partialderangement(-8, 0) | ||
|
|
||
| # doublefactorial | ||
| @test doublefactorial(70) == parse(BigInt,"355044260642859198243475901411974413130137600000000") | ||
| @test_throws DomainError doublefactorial(-1) | ||
|
|
||
| # hyperfactorial | ||
| @test hyperfactorial(8) == parse(BigInt,"55696437941726556979200000") | ||
| @test hyperfactorial(0) == parse(BigInt,"1") | ||
| @test hyperfactorial(1) == parse(BigInt,"1") | ||
| @test hyperfactorial(2) == parse(BigInt,"4") | ||
|
|
||
| # multifactorial | ||
| @test multifactorial(40,2) == doublefactorial(40) | ||
| @test_throws DomainError multifactorial(-1,1) | ||
|
|
||
| # multinomial | ||
| @test multinomial(1,4,4,2) == 34650 | ||
|
|
||
| # primorial | ||
| @test primorial(17) == 510510 | ||
| @test_throws DomainError primorial(-1) | ||
| @testset "factorials" begin | ||
| @test factorial(7, 3) == 7 * 6 * 5 * 4 | ||
| @test_throws DomainError factorial(3, 7) | ||
| @test_throws DomainError factorial(-3, -7) | ||
| @test_throws DomainError factorial(-7, -3) | ||
| #JuliaLang/julia#9943 | ||
| @test factorial(big(100), (80)) == 1303995018204712451095685346159820800000 | ||
| #JuliaLang/julia#9950 | ||
| @test_throws OverflowError factorial(1000, 80) | ||
|
|
||
| # derangement | ||
| @test derangement(4) == subfactorial(4) == 9 | ||
| @test derangement(24) == parse(BigInt, "228250211305338670494289") | ||
|
|
||
| # partialderangement | ||
| @test partialderangement(7, 3) == 315 | ||
| @test_throws DomainError partialderangement(8, 9) | ||
| @test_throws DomainError partialderangement(-8, 0) | ||
|
|
||
| # doublefactorial | ||
| @test doublefactorial(70) == parse(BigInt, "355044260642859198243475901411974413130137600000000") | ||
| @test_throws DomainError doublefactorial(-1) | ||
|
|
||
| # hyperfactorial | ||
| @test hyperfactorial(8) == parse(BigInt, "55696437941726556979200000") | ||
| @test hyperfactorial(0) == parse(BigInt, "1") | ||
| @test hyperfactorial(1) == parse(BigInt, "1") | ||
| @test hyperfactorial(2) == parse(BigInt, "4") | ||
|
|
||
| # multifactorial | ||
| @test multifactorial(40, 2) == doublefactorial(40) | ||
| @test_throws DomainError multifactorial(-1, 1) | ||
|
|
||
| # multinomial | ||
| @test multinomial(1, 4, 4, 2) == 34650 | ||
|
|
||
| # primorial | ||
| @test primorial(17) == 510510 | ||
| @test_throws DomainError primorial(-1) | ||
|
|
||
| end |
Oops, something went wrong.
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.