This is sort of a puzzle for which I have a solution
but have unsuccessfully puzzled over an alternative solution
and wonder if anyone would like to solve the "puzzle" of
finding how to find the same result but using I. instead of
@. .
My existing solution for the variable trap is as
follows.
aa =: {...@]
dd =: {:@]
bb =: 1&{...@]
cc =: _2&{...@]
ls =: leftsupp =:(([-aa)%bb-aa)
rs =: rightsupp =:((dd-[)%dd-cc)
co =: core =: 1:
ns =: nonsupport =: 0:
ge =: +/"1@(>:/)
le =: 4: - +/&.|."1@(<:/)
ag =: ge`2:@. (2: <: ge - le)
trap =: (ns`ls`co`rs`ns) @. ag
An example of using trap is as follows.
x:1|:((],:3&+)i. 15) (([,trap)"0 1)/_4]\0 5 10 14 2 6 10 14.5
0 1 2 3 4 5 6 7 8 9 10 11 12 13 14
0 1r5 2r5 3r5 4r5 1 1 1 1 1 1 3r4 1r2 1r4 0
0 1 2 3 4 5 6 7 8 9 10 11 12 13 14
0 0 0 1r4 1r2 3r4 1 1 1 1 1 7r9 5r9 1r3 1r9
3 4 5 6 7 8 9 10 11 12 13 14 15 16 17
3r5 4r5 1 1 1 1 1 1 3r4 1r2 1r4 0 0 0 0
3 4 5 6 7 8 9 10 11 12 13 14 15 16 17
1r4 1r2 3r4 1 1 1 1 1 7r9 5r9 1r3 1r9 0 0 0
Notice that all of the outputs of trap are between 0
and 1 and they are expressed as proper fractions in the
example, but that is only for prettying up the readout here.
If you load 'plot', execute the next line, and watch
carefully, you will see why these are called trapezoids.
plot"1 |: ,./;"1/ x:1|:((],:3&+)i. 15) (([,trap)"0 1)/_4]\0 5 10 14 2 6 10 14.5
--
(B=)
----------------------------------------------------------------------
For information about J forums see http://www.jsoftware.com/forums.htm