Jump to content

Factorial base numbers indexing permutations of a collection: Difference between revisions

→‎{{header|F_Sharp|F#}}: modified lN to take a start value
(→‎{{header|F_Sharp|F#}}: Undo some idiots edit which stops it compiling)
(→‎{{header|F_Sharp|F#}}: modified lN to take a start value)
Line 66:
let rec fN i g e l=match l-i with 0->Ω.[i]<-e |_->Ω.[l]<-Ω.[l-1]; fN i g e (l-1)// rotate right
[0..((Array.length Ω)-2)]|>List.iter(fun n->let i=c.[n] in if i>0 then fN n (i+n) Ω.[i+n] (i+n)); Ω
let lN Ωn =
let nΩ=(Array.zeroCreatelength Ωn)
let fN g=if n.[g]=Ω-g then n.[g]<-0; false else n.[g]<-n.[g]+1; true
seq{yield n; while [1..Ω]|>List.exists(fun g->fN (Ω-g)) do yield n}
Line 74:
;Re-create the table:
<lang fsharp>
lN 3[|0;0;0|] |> Seq.iter (fun n->printfn "%A -> %A" n (lN2p n [|0;1;2;3|]));;
</lang>
{{out}}
2,172

edits

Cookies help us deliver our services. By using our services, you agree to our use of cookies.