Catalan numbers/Pascal's triangle: Difference between revisions

→‎{{header|jq}}: emphasize alternative computation
m (→‎{{header|REXX}}: added a section header comment about arbitrary numbers.)
(→‎{{header|jq}}: emphasize alternative computation)
Line 166:
}:@:(}.@:((<0 1)&|:) - }:@:((<0 1)&|:@:(2&|.)))@:(i. +/\@]^:[ #&1)@:(2&+)</lang>
=={{header|jq}}==
The first identity (C(2n,n) - C(2n, n-1)) given in the reference is used in accordance with the task description, asbut it would of course be more efficient to factor out C(2n,n) and use the expression C(2n,n)/(n+1). See also [[Catalan_numbers#jq]] for other requiredalternatives.
by the task description, but see [[Catalan_numbers#jq]] for better alternatives.
 
''Warning'': jq uses IEEE 754 64-bit arithmetic,
Line 176 ⟶ 175:
end;
 
# Direct (naive) computation using two numbers in Pascal's triangle:
def catalan_by_pascal: . as $n | binomial(2*$n; $n) - binomial(2*$n; $n-1);</lang>
 
2,484

edits