HP Forums
(49g 50g) Zigzag numbers - Printable Version

+- HP Forums (https://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 01:53 PM

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.