[REBOL] Re: REBOL Enhancement Proposals (REPs)
From: joel:neely:fedex at: 27-Sep-2001 13:28
Hi, Andrew,
Andrew Martin wrote:
> Joel wrote:
> > Given a block of numbers, what's the simplest way in REBOL to
> > write a "smoothing" operation that averages each interior value
> > (i.e., all but the first and last) with the two values on either
> > side of it? >>
>
> I think this approach gives the correct result:
>
> >> b: [1 2 3 4 5 6 7 8 9 10]
> == [1 2 3 4 5 6 7 8 9 10]
> >> c: []
> == []
> >> i: b
> == [1 2 3 4 5 6 7 8 9 10]
> >> forall i [t: copy/part i 3 if 3 = length? t [append/only c t]]
> == []
> >> c
> == [[1 2 3] [2 3 4] [3 4 5] [4 5 6] [5 6 7] [6 7 8] [7 8 9] [8 9 10]]
> >> map c func [t][(t/1 + t/2 + t/3) / 3]
> == [2 3 4 5 6 7 8 9]
>
That's certainly a nice entry to the discussion; thanks!
Note that there is a subtle difference between the result of
code and the results of the other versions. Since the others
(including the "spec-by-example" descriptions) do an in-place
update, the effects of previous smoothing propagates through
the collection of values. OTOH, if all values are copied
before any smoothing, the propagation doesn't happen.
Just being nit-picky for the sake of conversation... ;-)
-jn-
--
This sentence contradicts itself -- no actually it doesn't.
-- Doug Hofstadter
joel<dot>neely<at>fedex<dot>com