Data commit
This commit is contained in:
parent
7387c8f97b
commit
cb5bb5e222
199093 changed files with 3378972 additions and 0 deletions
20
Task/Knuth-shuffle/Lasso/knuth-shuffle.lasso
Normal file
20
Task/Knuth-shuffle/Lasso/knuth-shuffle.lasso
Normal file
|
|
@ -0,0 +1,20 @@
|
|||
define staticarray->swap(p1::integer,p2::integer) => {
|
||||
fail_if(
|
||||
#p1 < 1 or #p2 < 1 or
|
||||
#p1 > .size or #p2 > .size,
|
||||
'invalid parameters'
|
||||
)
|
||||
#p1 == #p2
|
||||
? return
|
||||
|
||||
local(tmp) = .get(#p2)
|
||||
.get(#p2) = .get(#p1)
|
||||
.get(#p1) = #tmp
|
||||
}
|
||||
define staticarray->knuthShuffle => {
|
||||
loop(-from=.size, -to=2, -by=-1) => {
|
||||
.swap(math_random(1, loop_count), loop_count)
|
||||
}
|
||||
}
|
||||
|
||||
(1 to 10)->asStaticArray->knuthShuffle&asString
|
||||
Loading…
Add table
Add a link
Reference in a new issue