rosetta-code.pascals-triangle: adding a coefficients method.
parent
9b0989a901
commit
38833fcafe
|
@ -1,6 +1,6 @@
|
|||
! Copyright (c) 2012 Anonymous
|
||||
! See http://factorcode.org/license.txt for BSD license.
|
||||
USING: grouping kernel math sequences ;
|
||||
USING: grouping kernel locals math math.ranges sequences ;
|
||||
IN: rosetta-code.pascals-triangle
|
||||
|
||||
! http://rosettacode.org/wiki/Pascal%27s_triangle
|
||||
|
@ -26,6 +26,11 @@ IN: rosetta-code.pascals-triangle
|
|||
! function. Behavior for n <= 0 does not need to be uniform, but
|
||||
! should be noted.
|
||||
|
||||
:: pascal-coefficients ( n -- seq )
|
||||
1 n [1,b] [
|
||||
dupd [ n swap - * ] [ /i ] bi swap
|
||||
] map nip ;
|
||||
|
||||
: (pascal) ( seq -- newseq )
|
||||
dup last 0 prefix 0 suffix 2 <clumps> [ sum ] map suffix ;
|
||||
|
||||
|
|
Loading…
Reference in New Issue