On this page
Write 1 to n in a row so that they go up, down, up, down. How many ways are there? The answer starts as a counting puzzle and ends inside trigonometry.
What is an alternating permutation?
An alternating (or zigzag) permutation of {1, 2, ..., n} is an arrangement in which each entry is alternately greater and less than the one before, per Wikipedia's definition. In the up–down version, c1 < c2 > c3 < c4 > ..., so every inside entry is a peak or a valley. Down–up permutations give the same count: replace each entry c with n + 1 − c.
The number of up–down permutations of n letters is called the Euler zigzag number (also the up/down number) A_n: 1, 1, 1, 2, 5, 16, 61, 272, 1385, 7936 for n = 0 to 9, according to OEIS A000111. The French mathematician Désiré André studied them in his 1881 memoir on alternating permutations.
How do you list the 5 zigzag permutations of 1, 2, 3, 4?
The pattern for n = 4 is c1 < c2 > c3 < c4. The largest number, 4, can only stand on a peak: position 2 or 4.
4 in position 2: the pattern is a, 4, b, c with b < c. Pick a from {1, 2, 3} in 3 ways and put the other two in increasing order: 1 4 2 3, 2 4 1 3, 3 4 1 2.
4 in position 4: the pattern is a, b, c, 4 with a < b > c. The middle must be 3: 1 3 2 4, 2 3 1 4.
That gives 3 + 2 = 5, matching Wikipedia's list. So a random shuffle of 1, 2, 3, 4 zigzags with probability 5/24; in general A_n/n! is that probability, as OEIS A000111 records.
How does the boustrophedon (Seidel) triangle compute the zigzag numbers?
Philipp Ludwig von Seidel published a method in 1877 that needs only addition, described in the Wikipedia article and listed as OEIS A008280. Boustrophedon means "as the ox ploughs": each row runs the opposite way to the one before.
Row 0 is a single 1.
Start each new row with 0, at the end where the previous row finished.
Move across. Each new entry is the entry you just wrote plus the entry of the row above that you have just passed.
The last number you write in row n is A_n.
The rows, each in the order it was filled:
Row 1: 0, 1
Row 2: 0, 1, 1
Row 3: 0, 1, 2, 2
Row 4: 0, 2, 4, 5, 5
Row 5: 0, 5, 10, 14, 16, 16
Row 6: 0, 16, 32, 46, 56, 61, 61
The row ends read 1, 1, 2, 5, 16, 61, and row 7 ends in 272, matching the table in OEIS A008280.
Why is the generating function sec x + tan x?
Split the zigzags of n + 1 letters by where the largest entry sits, as we did for n = 4. Counting both up–down and down–up kinds gives 2A_(n+1) = sum over k of C(n, k) A_k A_(n−k) for n ≥ 1, as derived in the Wikipedia article. Check it at n = 3: 2A_4 = 2 + 3 + 3 + 2 = 10, so A_4 = 5.
Turn the recurrence into the exponential generating function A(x) = sum of A_n x^n / n!. It becomes the differential equation 2A′ = A² + 1 with A(0) = 1, and solving it gives A(x) = tan(π/4 + x/2) = sec x + tan x. This is André's theorem; André used this recurrence to get the differential equation in his 1881 memoir, as the Wikipedia article explains.
Since sec x is even and tan x is odd, sec x carries the even-index numbers 1, 1, 5, 61 (secant numbers) and tan x the odd ones 1, 2, 16, 272 (tangent numbers), per Wikipedia. Check one: tan x = x + x³/3 + 2x⁵/15 + ..., and 2x⁵/15 = 16x⁵/5!.
Because sec x + tan x first blows up at x = π/2, the numbers grow like 2(2/π)^(n+1) n!. So the ratio 2n A_(n−1)/A_n tends to π, as OEIS A000111 notes. At n = 7 it is 2 × 7 × 61/272 ≈ 3.140: a counting problem that estimates π.
How can you check the zigzag numbers yourself?
List the 2 zigzags of 1, 2, 3 and the 5 of 1, 2, 3, 4 with the largest-on-a-peak rule.
Build the triangle to row 7 and check that it ends in 272.
Expand sec x to the x⁴ term and confirm 5x⁴/4!.
For more counting practice, try the 8 JEE Advanced permutations and combinations questions, solved or revise the Class 11 permutations and combinations key terms. For another way to sort permutations by rises and falls, see Eulerian numbers and descents.
If Taylor series are the shaky step, the Fermi Concept Library gives every concept in mathematics its own lesson and its place in the map. When your own count does not match, the Fermi Problem Library has worked problems with a step-by-step solver that explains the reasoning rather than printing an answer.



