User:Oleg Kobchenko/Extended H
Jump to navigation
Jump to search
Alternative solutions to Essays/Extended H
tr=: 1 : '({ ,&a.)~ (m.,a.)&i.' extH2=: 0&$: : (4 : 0) if. y.=0 do. ,:,:'o' return. end. c=. <.-: #h=. |:'|-' '-|'tr 1 extH2 y.-1 p=. '-'(],,)c#' ' o=. (c#' '),'o',c#x.{' |' h,.p,.o,.p,.|."1 h )
Example: parent-child spacial relationship
extH2 each 1 0,2 3,:5 4 +-----------------------------+-------------+ |o-o-o |o | +-----------------------------+-------------+ |o o |o-o-o o-o-o| || | | | | | |o-o-o | o---o---o | || | | | | | |o o |o-o-o o-o-o| +-----------------------------+-------------+ |o-o-o o-o-o o-o-o o-o-o|o o o o| | | | | | || | | || | o---o---o o---o---o |o-o-o o-o-o| | | | | | | | || | | | | || |o-o-o | o-o-o o-o-o | o-o-o|o | o o | o| | | | | | | | | o-------o-------o | o---o---o | | | | | | | | |o-o-o | o-o-o o-o-o | o-o-o|o | o o | o| | | | | | | | || | | | | || | o---o---o o---o---o |o-o-o o-o-o| | | | | | || | | || |o-o-o o-o-o o-o-o o-o-o|o o o o| +-----------------------------+-------------+
The tr adverb, modeled after Amend is an adaptation of RogerHui's simultaneous shape preserving translator. I was looking for the pattern for a while.
-- Oleg Kobchenko <<DateTime(2005-11-09T07:00:37Z)>>
Here is more solutions
H2a, externalized connector
extH2a=: 0&$: : (4 : 0) if. y.=0 do. ,:,:'o' return. end. h=. |:'|-' '-|'tr 1 extH2a y.-1 h,.(x. con #h),.|."1 h ) con=: 4 : 0 c=. <.-: y. p=. '-'(],,)c#' ' o=. (c#' '),'o',c#x.{' |' p,.o,.p )
H3, halved iterations, eliminating transposition
cc=: (],1:,])@<.@-: c2=: cc #"1 (' | ', ' o-',:' | ')"_ c3=: cc # (' - ',.' o ',.' - ')"_ c4=: cc # (' - ',.' o|',.' - ')"_ c34=: c3`c4@. extH3=: 0&$: : (4 : 0) if. y.=0 do. ,:,: 'o' return. end. if. y.=1 do. ,:'o-o-o' return. end. g=. h , ( c2 {:$h) , |. h=. 1 extH3 y.-2 g ,. (x. c34 #g) ,. |."1 g )
H4, semi-tacit by reusing arguments
extH4=: 0&$: : (4 : 0) if. y.=0 do. ,:,: 'o' return. end. if. y.=1 do. ,:'o-o-o' return. end. (,.(x.c34@#,.|."1))(,(c2@{:@$,|.)) 1 extH4 y.-2 )
H5, more tacit by removing controls
h0=: (,:,:'o')"_ h1=: (,:'o-o-o')"_ extH5a=: 4 : '(,.(x.c34@#,.|."1))(,(c2@{:@$,|.)) 1 extH5 y.-2' extH5=: 0&$: : (h0`h1`extH5a@.(2&<.@]))
H6, monadic and fully tacit
'd2 d3 d4'=: (3 3 3$' | o- | -o- -o- | ') '`e2 e3 e4'=: (#"1&d2)`(#&d3)`(#&d4)@cc extH6 =: h0`h1`extH6a@.(2&<.@]) extH6b=: h0`h1`extH6c@.(2&<.@]) extH6a=: [: (,.(e3@#,.|."1)) [: (,(e2@{:@$,|.)) [: extH6b -&2 extH6c=: [: (,.(e4@#,.|."1)) [: (,(e2@{:@$,|.)) [: extH6b -&2
H7, non-recursive tacit
'`f0 f1 f2'=: (, (c2@{:@$, |.))`(,. (c4@#,. |."1))`(,. (c3@#,. |."1)) extH7=: f2@:f0@:( f1@:f0@]^:((-&2 <.@% 2:)@[) )^:(1&<@[) h0`h1@.(2&|)
ts vs. the original.
ts=: 6!:2 , 7!:2@] 't2 s2'=. |: (5: ts 'extH2 '&,@":)"0] 2*i.10 NB. ... (;:'H2 H3 H4 H5 H6 H7'),:(<t1) (] 8j4 6j2&":@:,. %)&,.&.> t2;t3;t4;t5;t6;t7 +--------------+--------------+--------------+--------------+--------------+--------------+ |H2 |H3 |H4 |H5 |H6 |H7 | +--------------+--------------+--------------+--------------+--------------+--------------+ | 0.0000 1.04| 0.0000 0.97| 0.0000 1.00| 0.0000 2.19| 0.0000 2.41| 0.0000 1.37| | 0.0001 0.88| 0.0001 2.01| 0.0001 2.01| 0.0000 2.47| 0.0000 3.91| 0.0000 3.48| | 0.0002 0.88| 0.0001 2.19| 0.0001 2.23| 0.0001 2.55| 0.0001 4.20| 0.0001 4.14| | 0.0004 0.87| 0.0001 2.28| 0.0001 2.33| 0.0001 2.60| 0.0001 4.23| 0.0001 4.33| | 0.0006 0.89| 0.0002 2.45| 0.0002 2.50| 0.0002 2.71| 0.0001 4.23| 0.0001 4.42| | 0.0009 0.97| 0.0003 2.94| 0.0003 2.97| 0.0003 3.14| 0.0002 4.60| 0.0002 4.52| | 0.0025 1.15| 0.0008 3.61| 0.0008 3.65| 0.0008 3.73| 0.0006 4.61| 0.0007 4.46| | 0.0114 0.99| 0.0028 3.99| 0.0028 4.02| 0.0028 4.01| 0.0025 4.55| 0.0027 4.28| | 0.0579 1.04| 0.0124 4.87| 0.0130 4.66| 0.0117 5.16| 0.0114 5.28| 0.0122 4.95| | 0.2479 1.05| 0.0545 4.80| 0.0548 4.77| 0.0554 4.72| 0.0545 4.79| 0.0544 4.80| +--------------+--------------+--------------+--------------+--------------+--------------+ (;:'H2 H3 H4 H5 H6 H7'),:(<s1) (] 8 6j2&":@:,. %)&,.&.> s2;s3;s4;s5;s6;s7 +--------------+--------------+--------------+--------------+--------------+--------------+ |H2 |H3 |H4 |H5 |H6 |H7 | +--------------+--------------+--------------+--------------+--------------+--------------+ | 2240 0.94| 2240 0.94| 2240 0.94| 960 2.20| 960 2.20| 1472 1.43| | 8256 0.81| 3712 1.79| 4992 1.33| 5312 1.25| 1536 4.33| 1984 3.35| | 11072 0.86| 5184 1.83| 7232 1.31| 7744 1.22| 1792 5.29| 2240 4.23| | 13888 0.88| 6656 1.85| 9472 1.30| 10176 1.21| 3520 3.49| 4160 2.95| | 26496 0.94| 14592 1.71| 13568 1.84| 13952 1.79| 9152 2.73| 10560 2.36| | 88000 1.05| 48704 1.90| 41280 2.24| 41664 2.22| 33792 2.74| 38272 2.42| | 333760 1.09| 184384 1.97| 151872 2.39| 152256 2.38| 132096 2.75| 148864 2.44| | 1316800 1.10| 726080 1.99| 594240 2.43| 594624 2.43| 525312 2.75| 591232 2.44| | 5248960 1.10| 2890816 2.00| 2363712 2.44| 2364096 2.44| 2098176 2.75| 2360704 2.44| |20977600 1.10|11545664 2.00| 9441600 2.44| 9441984 2.44| 8389632 2.75| 9438592 2.44| +--------------+--------------+--------------+--------------+--------------+--------------+
-- Oleg Kobchenko <<DateTime(2005-11-11T11:25:32Z)>>