2016 Update
This commit is contained in:
parent
948b86eafa
commit
dcf5d15da3
7965 changed files with 139854 additions and 31002 deletions
49
Task/Knuths-algorithm-S/Elena/knuths-algorithm-s.elena
Normal file
49
Task/Knuths-algorithm-S/Elena/knuths-algorithm-s.elena
Normal file
|
|
@ -0,0 +1,49 @@
|
|||
#import system.
|
||||
#import system'dynamic.
|
||||
#import extensions.
|
||||
#import system'routines.
|
||||
#import system'collections.
|
||||
|
||||
#class(extension)algorithmOp
|
||||
{
|
||||
#method s_of_n
|
||||
[
|
||||
#var counter := Integer new.
|
||||
|
||||
^ ArrayList new mix &into:
|
||||
{
|
||||
eval : n
|
||||
[
|
||||
counter += 1.
|
||||
|
||||
(this length < self)
|
||||
? [ this += n. ]
|
||||
! [
|
||||
(randomGenerator eval:counter < self)
|
||||
? [ this@(randomGenerator eval:self) := n. ].
|
||||
].
|
||||
|
||||
^ this array.
|
||||
]
|
||||
}.
|
||||
]
|
||||
}
|
||||
|
||||
#symbol program =
|
||||
[
|
||||
#var bin := Array new:10 set &every:(&index:n) [ Integer new ].
|
||||
0 till:10000 &doEach: trial
|
||||
[
|
||||
#var s_of_n := 3 s_of_n.
|
||||
|
||||
0 till:10 &doEach:n
|
||||
[
|
||||
#var sample := s_of_n eval:n.
|
||||
|
||||
(n == 9)
|
||||
? [ sample run &each: i [ bin@i += 1. ]. ].
|
||||
].
|
||||
].
|
||||
|
||||
console writeLine:bin.
|
||||
].
|
||||
Loading…
Add table
Add a link
Reference in a new issue