rosetta-code.pascals-triangle: adding a coefficients method.

db4
John Benediktsson 2013-05-07 21:06:00 -07:00
parent 9b0989a901
commit 38833fcafe
1 changed files with 6 additions and 1 deletions

View File

@ -1,6 +1,6 @@
! Copyright (c) 2012 Anonymous ! Copyright (c) 2012 Anonymous
! See http://factorcode.org/license.txt for BSD license. ! 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 IN: rosetta-code.pascals-triangle
! http://rosettacode.org/wiki/Pascal%27s_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 ! function. Behavior for n <= 0 does not need to be uniform, but
! should be noted. ! should be noted.
:: pascal-coefficients ( n -- seq )
1 n [1,b] [
dupd [ n swap - * ] [ /i ] bi swap
] map nip ;
: (pascal) ( seq -- newseq ) : (pascal) ( seq -- newseq )
dup last 0 prefix 0 suffix 2 <clumps> [ sum ] map suffix ; dup last 0 prefix 0 suffix 2 <clumps> [ sum ] map suffix ;