Phrases/Sets/Metrics

From J Wiki
< Phrases‎ | Sets
Jump to navigation Jump to search

purpose

This script compares the "variations" algorithms given on the Sets page.

script

   hui0      =. dyad define
 k=. i.>:d=.y-x
 z=. (d$<i.0 0),<i.1 0
 for. i.x do. z=. k ,.&.> ,&.>/\. >:&.> z end.
 ; z
)

   seed      =.  [: i.@(,&0)&.> <:@- {. 1:
   cf        =.  i.@# ,.&.> ,&.>/\.@:(>:&.>)
   hui1      =.  [: ; [ cf@[&0 seed

   H0B       =:  ] {~ ,/@:((i.@:!@:[ A."0 1/ hui0 f.) #)
   H1B       =:  ] {~ ,/@:((i.@:!@:[ A."0 1/ hui1 f.) #)

   BJ0       =:  4 :'>@:,@:({."1) (0&{:: (<@:,"_ _1 ,"0 (<@:<@:<"0@:i.@:#<@{])@:]) 1&{::)"1^:x ($0);<y'
   BJ1       =:  vari =: [{."_1]A.~#@:]([(]*i.@:%)&!-)[

   r         =: 1000 ts&>  ' ''abcdefg''' , L:0~  '4 ' , L: 0 fn =.  BJ0`BJ1`H0B`H1B

   ts        =:  6!:2 , 7!:2@:]
   fmt       =:  [: ,.&:>/ [: }.@:, (< ' ' $~ 1 ,~ 2 + # fn) ,. (;:'Name Time Space') ,&.> '-' ,&.> [: <@:>"1@:|: [ ,. '0.3d' 8!:0 ] %"1 <./@:]

   fn fmt r

see also