]> gitweb.factorcode.org Git - factor.git/commitdiff
rosetta-code.pascals-triangle: adding a coefficients method.
authorJohn Benediktsson <mrjbq7@gmail.com>
Wed, 8 May 2013 04:06:00 +0000 (21:06 -0700)
committerJohn Benediktsson <mrjbq7@gmail.com>
Wed, 8 May 2013 04:06:40 +0000 (21:06 -0700)
extra/rosetta-code/pascals-triangle/pascals-triangle.factor

index 2c1a55ad43bd41da552f17089f685f197dd07b5b..ab5b90354573f8600f354892cba2ca3bf46ec60c 100644 (file)
@@ -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 ;