Data commit
This commit is contained in:
parent
7387c8f97b
commit
cb5bb5e222
199093 changed files with 3378972 additions and 0 deletions
|
|
@ -0,0 +1,18 @@
|
|||
(*Implement Johnson-Trotter algorithm
|
||||
Nigel Galloway January 24th 2017*)
|
||||
module Ring
|
||||
let PlainChanges (N:'n[]) = seq{
|
||||
let gn = [|for n in N -> 1|]
|
||||
let ni = [|for n in N -> 0|]
|
||||
let gel = Array.length(N)-1
|
||||
yield N
|
||||
let rec _Ni g e l = seq{
|
||||
match (l,g) with
|
||||
|_ when l<0 -> gn.[g] <- -gn.[g]; yield! _Ni (g-1) e (ni.[g-1] + gn.[g-1])
|
||||
|(1,0) -> ()
|
||||
|_ when l=g+1 -> gn.[g] <- -gn.[g]; yield! _Ni (g-1) (e+1) (ni.[g-1] + gn.[g-1])
|
||||
|_ -> let n = N.[g-ni.[g]+e];
|
||||
N.[g-ni.[g]+e] <- N.[g-l+e]; N.[g-l+e] <- n; yield N
|
||||
ni.[g] <- l; yield! _Ni gel 0 (ni.[gel] + gn.[gel])}
|
||||
yield! _Ni gel 0 1
|
||||
}
|
||||
|
|
@ -0,0 +1 @@
|
|||
for n in Ring.PlainChanges [|1;2;3;4|] do printfn "%A" n
|
||||
Loading…
Add table
Add a link
Reference in a new issue