-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathSymGrp.jl
47 lines (45 loc) · 1.08 KB
/
SymGrp.jl
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
function Sym(A::Union{Set,Array})
unique!(A)
P = Array{eltype(A),1}[]
function continuePerm(head,tail)
if length(tail) > 0
for t in tail
newHead = union(head, [t])
newTail = setdiff(tail, [t])
continuePerm(newHead, newTail)
end
else
push!(P, head)
end
end
continuePerm(eltype(A)[], A)
return P
end
function Sym(n::Integer)
A = collect(1:n)
P = Array{Int,1}[]
function continuePerm(head,tail)
if length(tail) > 0
for t in tail
newHead = union(head, [t])
newTail = setdiff(tail, [t])
continuePerm(newHead, newTail)
end
else
push!(P, head)
end
end
continuePerm(Int[], A)
return P
end
function P(τ::Array; inSnWithn=nothing)
if inSnWithn==nothing
M = zeros(Int16, length(τ),length(τ))
else
M = zeros(Int16, inSnWithn,inSnWithn)
end
for i in 1:length(τ)
M[ i , τ[i] ] = 1
end
return M
end