Data commit
This commit is contained in:
parent
7387c8f97b
commit
cb5bb5e222
199093 changed files with 3378972 additions and 0 deletions
17
Task/Knuth-shuffle/Tcl/knuth-shuffle-1.tcl
Normal file
17
Task/Knuth-shuffle/Tcl/knuth-shuffle-1.tcl
Normal file
|
|
@ -0,0 +1,17 @@
|
|||
proc knuth_shuffle lst {
|
||||
set j [llength $lst]
|
||||
for {set i 0} {$j > 1} {incr i;incr j -1} {
|
||||
set r [expr {$i+int(rand()*$j)}]
|
||||
set t [lindex $lst $i]
|
||||
lset lst $i [lindex $lst $r]
|
||||
lset lst $r $t
|
||||
}
|
||||
return $lst
|
||||
}
|
||||
|
||||
% knuth_shuffle {1 2 3 4 5}
|
||||
2 1 3 5 4
|
||||
% knuth_shuffle {1 2 3 4 5}
|
||||
5 2 1 4 3
|
||||
% knuth_shuffle {tom dick harry peter paul mary}
|
||||
tom paul mary harry peter dick
|
||||
11
Task/Knuth-shuffle/Tcl/knuth-shuffle-2.tcl
Normal file
11
Task/Knuth-shuffle/Tcl/knuth-shuffle-2.tcl
Normal file
|
|
@ -0,0 +1,11 @@
|
|||
% for {set i 0} {$i<100000} {incr i} {
|
||||
foreach val [knuth_shuffle {1 2 3 4 5}] pos {pos0 pos1 pos2 pos3 pos4} {
|
||||
incr tots($pos) $val
|
||||
}
|
||||
}
|
||||
% parray tots
|
||||
tots(pos0) = 300006
|
||||
tots(pos1) = 300223
|
||||
tots(pos2) = 299701
|
||||
tots(pos3) = 299830
|
||||
tots(pos4) = 300240
|
||||
Loading…
Add table
Add a link
Reference in a new issue