Catalan numbers/Pascal's triangle: Difference between revisions
Content deleted Content added
Added EchoLisp |
|||
Line 275: | Line 275: | ||
{{out}} |
{{out}} |
||
<pre>1 2 5 14 42 132 429 1430 4862 16796 58786 208012 742900 2674440 9694845 </pre> |
<pre>1 2 5 14 42 132 429 1430 4862 16796 58786 208012 742900 2674440 9694845 </pre> |
||
=={{header|EchoLisp}}== |
|||
<lang scheme> |
|||
(define dim 100) |
|||
(define-syntax-rule (Tidx i j) (+ i (* dim j))) |
|||
;; generates Catalan's triangle |
|||
;; T (i , j) = T(i-1,j) + T (i, j-1) |
|||
(define (T n) |
|||
(define i (modulo n dim)) |
|||
(define j (quotient n dim)) |
|||
(cond |
|||
((zero? i) 1) ;; left column = 1 |
|||
((= i j) (T (Tidx (1- i) j))) ;; diagonal value = left value |
|||
(else (+ (T (Tidx (1- i) j)) (T (Tidx i (1- j))))))) |
|||
(remember 'T #(1)) |
|||
</lang> |
|||
{{out}} |
|||
<lang scheme> |
|||
;; take elements on diagonal = Catalan numbers |
|||
(for ((i (in-range 0 16))) (write (T (Tidx i i)))) |
|||
</lang> |
|||
→ 1 1 2 5 14 42 132 429 1430 4862 16796 58786 208012 742900 2674440 9694845 |
|||
</lang> |
|||
=={{header|Elixir}}== |
=={{header|Elixir}}== |