Building Trains by Counting: Sum and Product Rules, Arrangements, and Restrictions

What a counting problem actually asks

Train-building problems are a convenient laboratory for elementary counting because every design decision is visible: which cars go into the train, and in what order along the track. Before reaching for a formula, settle three questions about the scenario.


  1. Are the objects distinguishable? Two numbered locomotives are distinct; two identical hopper cars from the same fleet are not.
  2. Does order along the train matter? A consist with the tank car ahead of the boxcar is a different train from the reverse. If the question only asks which cars are in the yard's outbound group, order is irrelevant.
  3. Are the choices made simultaneously or in sequence? Sequential independent choices multiply; mutually exclusive alternative scenarios add.

The sum rule and the product rule

The product rule applies when a single outcome is built by making several choices in sequence, and the number of options at each stage does not depend on which options were chosen earlier.


If a dispatcher must attach one head-end power unit chosen from 2 available units and one rear-end unit chosen from 7, the number of complete pairings is 2 × 7 = 14. Every head-end choice can be completed in 7 ways, and no pairing is counted twice.


The sum rule applies when the outcomes fall into cases that cannot occur together. If a train must be either an all-freight consist (counted one way) or an all-passenger consist (counted another way), and no train is both, the totals add.


The single most common error in elementary counting is adding where the structure calls for multiplication, or multiplying across cases that were meant to be alternatives.


The diagnostic question is simple: does a completed outcome involve all of the stages (multiply), or does it belong to exactly one of the cases (add)?

Ordered selections: permutations

Arranging r distinct objects chosen from n distinct objects in a definite order can be done in


P(n, r) = n! / (n − r)!


ways, which is just the product rule applied to shrinking choices: n options for the first position, n − 1 for the second, and so on. When every object is used, r = n and the count is n!. Four distinct cars arranged behind a locomotive give 4! = 24 orderings.

Repeated identical objects

Identical cars break the permutation count, because swapping two identical hoppers does not produce a new train. If a train of n cars contains groups of identical cars of sizes n1, n2, …, nk, the number of distinguishable orderings is the multinomial count


n! / (n1! n2! … nk!)


Six cars consisting of three identical hoppers and three identical tankers give 6!/(3!3!) = 720/36 = 20 distinguishable trains. The division removes exactly the overcounting introduced by pretending identical cars were labelled.

Unordered selections: combinations

When the question is which cars are chosen and not how they are arranged, use


C(n, r) = n! / [ r!(n − r)! ]


Selecting 2 cars from 10 distinct cars for inspection can be done in C(10, 2) = 45 ways. The relationship P(n, r) = C(n, r) × r! is worth holding onto: a permutation is a selection followed by an arrangement, so dividing a permutation count by r! discards the ordering information.

Restrictions: blocks, gaps, and complements

Most interesting problems attach a condition, and three techniques cover the common cases.


Blocks, for "must be adjacent". Glue the objects that must sit together into one composite unit, arrange the resulting units, then arrange the members inside the block.


With 5 distinct cars of which 2 specified cars must be adjacent, treat those two as one unit: 4 units arrange in 4! = 24 ways, the pair internally in 2! = 2 ways, giving 24 × 2 = 48 trains.


Gaps, for "must not be adjacent". Arrange the unrestricted objects first, then place the restricted objects into the gaps between and around them, at most one per gap. Arranging m unrestricted cars creates m + 1 gaps.


Complement, for "at least" conditions. Count everything, then subtract the outcomes that violate the condition. Continuing the example above, all 5 distinct cars arrange in 5!


= 120 ways, so the arrangements in which the two specified cars are not adjacent number 120 − 48 = 72. Complementary counting is usually the faster route whenever the condition contains the words "at least one".


A final habit: after computing, sanity-check the magnitude. An answer must never exceed the unrestricted total, adding a restriction must never increase the count, and a combination count must never exceed the corresponding permutation count.

A rail yard assembles a train consisting of exactly one locomotive, one baggage car, and one caboose. There are 5 distinct locomotives, 3 distinct baggage cars, and 4 distinct cabooses available, and the three vehicles always occupy the same fixed positions in the train. How many distinct trains can be assembled?

Choose an answer

Create a free account to get started

Unlock full course notes by signing up

  • Video lessons taught by top educators
  • Practice questions with guided solutions
  • Written review notes for reference
  • Expert answers anytime from course tutors

Mark Yourself Question

  1. Grab a piece of paper and try this problem yourself.
  2. When you're done, check the "I have answered this question" box below.
  3. View the solution and report whether you got it right or wrong.

A freight train is made up of 9 cars in a single line: 4 identical hopper cars, 3 identical tank cars, and 2 identical boxcars. Cars of the same type cannot be told apart from the outside.

How many distinguishable orderings of this train are possible? Explain why the answer is not simply 9!.

Create a free account to get started

Unlock full course notes by signing up

  • Video lessons taught by top educators
  • Practice questions with guided solutions
  • Written review notes for reference
  • Expert answers anytime from course tutors

Mark Yourself Question

  1. Grab a piece of paper and try this problem yourself.
  2. When you're done, check the "I have answered this question" box below.
  3. View the solution and report whether you got it right or wrong.

A yard holds 7 distinct tank cars and 6 distinct boxcars. A dispatcher must select a group of 5 cars to be sent out; at this stage only which cars are selected matters, not the order in which they will be coupled.

(a) How many selections contain exactly 3 tank cars? (b) How many selections contain at least 4 tank cars?

Create a free account to get started

Unlock full course notes by signing up

  • Video lessons taught by top educators
  • Practice questions with guided solutions
  • Written review notes for reference
  • Expert answers anytime from course tutors