Skip to content

Commit

Permalink
Updates for Julia 0.6 (#47)
Browse files Browse the repository at this point in the history
  • Loading branch information
ararslan authored Mar 17, 2017
1 parent d44f1a0 commit dca8530
Show file tree
Hide file tree
Showing 6 changed files with 15 additions and 13 deletions.
3 changes: 2 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
# Combinatorics

[![Combinatorics](http://pkg.julialang.org/badges/Combinatorics_0.5.svg)](http://pkg.julialang.org/?pkg=Combinatorics&ver=0.5)
[![Combinatorics](http://pkg.julialang.org/badges/Combinatorics_0.5.svg)](http://pkg.julialang.org/?pkg=Combinatorics)
[![Combinatorics](http://pkg.julialang.org/badges/Combinatorics_0.6.svg)](http://pkg.julialang.org/?pkg=Combinatorics)
[![Build Status](https://travis-ci.org/JuliaMath/Combinatorics.jl.svg?branch=master)](https://travis-ci.org/JuliaMath/Combinatorics.jl)
[![Coverage Status](https://coveralls.io/repos/github/JuliaMath/Combinatorics.jl/badge.svg?branch=master)](https://coveralls.io/github/JuliaMath/Combinatorics.jl?branch=master)
[![Codecov](https://codecov.io/gh/JuliaMath/Combinatorics.jl/branch/master/graph/badge.svg)](https://codecov.io/gh/JuliaMath/Combinatorics.jl)
Expand Down
2 changes: 1 addition & 1 deletion REQUIRE
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
julia 0.5
Compat 0.9.4
Compat 0.18.0
Polynomials
Iterators
2 changes: 1 addition & 1 deletion src/factorials.jl
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ factorial(n::Integer, k::Integer) = factorial(promote(n, k)...)
"The number of permutations of n with no fixed points (subfactorial)"
function derangement(sn::Integer)
n = BigInt(sn)
return num(factorial(n)*sum([(-1)^k//factorial(k) for k=0:n]))
return numerator(factorial(n)*sum([(-1)^k//factorial(k) for k=0:n]))
end
subfactorial(n::Integer) = derangement(n)

Expand Down
10 changes: 5 additions & 5 deletions src/numbers.jl
Original file line number Diff line number Diff line change
Expand Up @@ -11,15 +11,15 @@ export bellnum,
stirlings2

import Base: factorial, binomial

"Returns the n-th Bell number"
function bellnum(bn::Integer)
if bn < 0
throw(DomainError())
else
n = BigInt(bn)
end
list = Array(BigInt, div(n*(n+1), 2))
list = Vector{BigInt}(div(n*(n+1), 2))
list[1] = 1
for i = 2:n
beg = div(i*(i-1),2)
Expand Down Expand Up @@ -92,7 +92,7 @@ function stirlings1(n::Int, k::Int, signed::Bool=false)
if signed == true
return (-1)^(n - k) * stirlings1(n, k)
end

if n < 0
throw(DomainError())
elseif n == k == 0
Expand All @@ -110,7 +110,7 @@ function stirlings1(n::Int, k::Int, signed::Bool=false)
elseif k == n - 3
return binomial(n, 2) * binomial(n, 4)
end

return (n - 1) * stirlings1(n - 1, k) + stirlings1(n - 1, k - 1)
end

Expand All @@ -126,6 +126,6 @@ function stirlings2(n::Int, k::Int)
elseif k == 2
return 2^(n-1) - 1
end

return k * stirlings2(n - 1, k) + stirlings2(n - 1, k - 1)
end
6 changes: 3 additions & 3 deletions src/youngdiagrams.jl
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,9 @@
# Young diagrams, partitions of unity and characters of the symmetric group Sn #
################################################################################

typealias Partition Vector{Int}
typealias YoungDiagram Array{Int,2}
typealias SkewDiagram Tuple{Partition, Partition}
const Partition = Vector{Int}
const YoungDiagram = Array{Int,2}
const SkewDiagram = Tuple{Partition, Partition}

export Partition,
YoungDiagram, #represents shape of Young diagram
Expand Down
5 changes: 3 additions & 2 deletions test/permutations.jl
Original file line number Diff line number Diff line change
@@ -1,12 +1,13 @@
using Combinatorics
using Base.Test
using Compat

# permutations
@test collect(permutations("abc")) == Any[['a','b','c'],['a','c','b'],['b','a','c'],
['b','c','a'],['c','a','b'],['c','b','a']]

@test collect(filter(x->(iseven(x[1])),permutations([1,2,3]))) == Any[[2,1,3],[2,3,1]]
@test collect(filter(x->(iseven(x[3])),permutations([1,2,3]))) == Any[[1,3,2],[3,1,2]]
@test collect(Compat.Iterators.filter(x->(iseven(x[1])),permutations([1,2,3]))) == Any[[2,1,3],[2,3,1]]
@test collect(Compat.Iterators.filter(x->(iseven(x[3])),permutations([1,2,3]))) == Any[[1,3,2],[3,1,2]]

@test length(permutations(0)) == 1

Expand Down

0 comments on commit dca8530

Please sign in to comment.