Water collected between towers: Difference between revisions

Content added Content deleted
(added Factor)
(→‎{{header|Factor}}: Wasn't aware of cumulative max word from math.statistics vocab; use that instead of rolling my own.)
Line 703: Line 703:


=={{header|Factor}}==
=={{header|Factor}}==
<lang factor>USING: formatting kernel math math.order sequences ;
<lang factor>USING: formatting kernel math math.order math.statistics
sequences ;
IN: rosetta-code.water-towers
IN: rosetta-code.water-towers


Line 715: Line 716:
{ 6 7 10 7 6 }
{ 6 7 10 7 6 }
}
}

: max-sweep ( seq -- seq' ) 0 [ max ] accumulate* ;


: area ( seq -- n )
: area ( seq -- n )
[ ] [ max-sweep ] [ <reversed> max-sweep reverse ] tri
dup [ cum-max ] [ <reversed> cum-max reverse ] bi
[ min ] 2map swap [ - ] 2map sum ;
[ min ] 2map swap [ - ] 2map sum ;