# HP Forums

Full Version: (50g) Delannoy numbers
You're currently viewing a stripped down version of our content. View the full version with proper formatting.
Delannoy numbers have many applications in combinatorics and number theory. Fortunately they are fast and easy to compute. Further details here.

The following program returns a rectangular array of Delannoy numbers. Given two integers referred to as m and n in the linked article, the program will return an array of m columns and n rows. The program actually returns a list of lists, and may be followed by AXL if a matrix is desired. The program requires the GoferLists library.

Code:
``` \<< \-> m n   \<< 1 m NDUPN \->LIST 2 n     START DUP 2.       \<< +       \>> DOSUBS 1       \<< +       \>> Scanl     NEXT n \->LIST   \>> \>>```

The next program returns the Delannoy triangle, also known as the tribonacci triangle. The numbers are the same as in the array but arranged in a triangle. Given an integer n, the program returns rows 0 through n of the triangle as a list of lists.

Code:
``` \<< \-> n   \<< { 1 } DUP 1 + 2 n     START DUP2 2.       \<< +       \>> DOSUBS ADD 1 + 1 SWAP +     NEXT n 1 + \->LIST   \>> \>>```

Finally, a program that computes the central Delannoy numbers which are the central column of the triangle and the main diagonal of the array. Given an integer n the program returns terms 0 through n of the sequence.

Code:
``` \<< \-> n   \<< 1 3 2 n     FOR k DUP2 k 6 * 3 - * SWAP k 1 - * - k /     NEXT n 1 + \->LIST   \>> \>>```

The last two programs will run on the HP-48G but are of limited usefulness since the numbers involved grow rapidly beyond 12 digits.
I never heard of Delannoy numbers. Thanks for sharing John.
Reference URL's
• HP Forums: https://www.hpmuseum.org/forum/index.php
• :