Talk:Knuth's algorithm S: Difference between revisions

 
(One intermediate revision by one other user not shown)
Line 5:
: The task description is questionable. "Return a funciton" is not necessarily desirable or even possible for some languages, not to mention fixed function names. A names like "s_of_n" isn't all that descriptive to start with, and is patentedly against naming conventions in different languages, I don't see the point of sticking with them. --[[User:Ledrug|Ledrug]] 03:01, 12 November 2011 (UTC)
 
: I think it is attempting to achieve Currying in non-functional languages. In F# I might more naturally write:
<lang fsharp>
let s_of_n_creator i g = Seq.fold(fun (n:_[]) g->if N.Next()%(g+1)>i-1 then n else n.[N.Next()%i]<-g;n) (Array.ofSeq (Seq.take i g)) (Seq.skip i g)
let s_of_n<'a>= s_of_n_creator 3
printfn "%A" (List.init 100000 (fun _->s_of_n_creator 3 [0..9]) |> Array.concat |> Array.countBy id |> Array.sort)
printfn "%A" (List.init 100000 (fun _->s_of_n_creator 3 [|0..9|]) |> Array.concat |> Array.countBy id |> Array.sort)
printfn "%A" (List.init 100000 (fun _->s_of_n [|0..9|]) |> Array.concat |> Array.countBy id |> Array.sort)
printfn "%A" (List.init 100000 (fun _->s_of_n [0..9]) |> Array.concat |> Array.countBy id |> Array.sort)
</lang>--[[User:Nigel Galloway|Nigel Galloway]] ([[User talk:Nigel Galloway|talk]]) 11:05, 7 August 2018 (UTC)
=== Algorithm R? ===
 
Line 26 ⟶ 35:
 
::I meant 'artificial' in the requirement to create, in advance, a function taking a single parameter (i.e. introducing a First Class Function element to the task). The actual Knuth S algorithm is embodied in the BBC BASIC function <code>FNs_of_n</code> which can be called directly without any of the memory usage complications, but it takes additional parameters (the sample size and an array to hold the sample). [[User:RichardRussell|RichardRussell]] 10:14, 5 November 2012 (UTC)
 
:::Thanks for the explanation Richard. --[[User:Paddy3118|Paddy3118]] 11:23, 5 November 2012 (UTC)
2,172

edits