math.extras: adding moving-count.
parent
20100d7853
commit
a454b2e384
|
@ -1,7 +1,7 @@
|
|||
! Copyright (C) 2012 John Benediktsson
|
||||
! See http://factorcode.org/license.txt for BSD license
|
||||
|
||||
USING: math.extras math.ranges tools.test ;
|
||||
USING: math math.extras math.ranges tools.test ;
|
||||
|
||||
IN: math.extras.test
|
||||
|
||||
|
@ -21,6 +21,8 @@ IN: math.extras.test
|
|||
|
||||
{ { 2 5 5 4 3 } } [ { 1 2 5 6 1 4 3 } 3 moving-median ] unit-test
|
||||
|
||||
{ { 2 1 1 2 1 1 } } [ { 1 1 2 3 5 8 13 } 2 [ odd? ] moving-count ] unit-test
|
||||
|
||||
{ { } } [ { 0 0 } nonzero ] unit-test
|
||||
{ { 1 2 3 } } [ { 0 1 0 2 0 3 0 } nonzero ] unit-test
|
||||
|
||||
|
|
|
@ -105,6 +105,9 @@ PRIVATE>
|
|||
: moving-sum ( u n -- v )
|
||||
<clumps> [ sum ] map ;
|
||||
|
||||
: moving-count ( ... u n quot: ( ... elt -- ... ? ) -- ... v )
|
||||
[ <clumps> ] [ [ count ] curry map ] bi* ; inline
|
||||
|
||||
: nonzero ( seq -- seq' )
|
||||
[ zero? not ] filter ;
|
||||
|
||||
|
|
Loading…
Reference in New Issue