(49g 50g) Zigzag numbers

+- HP Forums (http://www.hpmuseum.org/forum)
+-- Forum: HP Software Libraries (/forum-10.html)
+--- Forum: General Software Library (/forum-13.html)
+--- Thread: (49g 50g) Zigzag numbers (/thread-11512.html)



(49g 50g) Zigzag numbers - John Keith - 10-02-2018 08:53 AM

The following program returns a list of the zigzag numbers (A000111) from 0 though n. The even-indexed terms (starting with 0) of the list are the unsigned Euler numbers, also known as secant numbers (A000364). The odd-indexed terms (starting with 1) are the tangent numbers, A000182.

The program requires GoferLists, and should be used in exact mode due to the size of integers involved.

Code:

\<< I\->R  \-> n
  \<< 1 DUPDUP { 1 } 3. n
    FOR n 0 SWAP + REVLIST
      \<< +
      \>> Scanl1 DUP \GSLIST SWAP
    NEXT DROP n 1. + \->LIST
  \>>
\>>

The next program returns rows 0 through n of A008281, the triangle from which the zigzag numbers are derived:

Code:

\<< I\->R \-> n
  \<< { 1 } 1. n
    START DUP REVLIST
      \<< +
      \>> Scanl1 0 SWAP +
    NEXT n 1. + \->LIST
  \>>
\>>

These programs are based on the "Boustrophedon transform", which is detailed in the Links section of the A008281 link above.