HP Forums

Full Version: (49g 50g) Zigzag numbers
You're currently viewing a stripped down version of our content. View the full version with proper formatting.
The following program returns a list of the Euler 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.



Code:

\<< I\->R \-> n
  \<< 1 { 1 } 1. n
    START REVLIST 0 :: + Scanl DUP Last NEWOB 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. They requireGoferLists, and should be used in exact mode due to the size of integers involved.

Edited 9/22/2019 to replace the first program with a smaller, faster version.
Reference URL's