Data commit

This commit is contained in:
Ingy döt Net 2023-07-01 11:58:00 -04:00
parent 7387c8f97b
commit cb5bb5e222
199093 changed files with 3378972 additions and 0 deletions

View file

@ -0,0 +1,29 @@
{def shuffle
{def shuffle.in
{lambda {:a}
{S.map {{lambda {:a :i}
{A.swap :i
{floor {* {random} {+ :i 1}}} // j = random integer from 0 to i+1
:a}} :a}
{S.serie {- {A.length :a} 1} 0 -1}}}} // from length-1 to 0
{lambda {:a}
{let { {:b {A.duplicate :a}} } // optionnaly prevents modifying the original array
{S.replace \s by in {shuffle.in :b} // trim extra spaces
:b}}}} // return the new array
-> shuffle
{def A.swap // should probably be promoted as a primitive
{lambda {:i :j :a}
{let { {:i :i}
{:gja {A.get :j :a}}
{:b {A.set! :j {A.get :i :a} :a}}
} {let { {_ {A.set! :i :gja :b} }}}}}} // side effect without any return value
-> A.swap
{def B {A.new a b c d e f g h i j k l m n o p q r s t u v w x y z}}
-> B
{shuffle {B}}
-> [z,t,q,w,c,n,a,u,r,y,i,s,f,d,g,m,h,x,b,e,k,p,l,o,j,v]