Cody

Problem 1393. A (wrong) place for everything, and everything in its (wrong) place

You have an equal number of cups and balls, each labelled from one to N. You randomly place one ball in each cup. Determine the number of possible combinations such that no balls are in the cup with a matching number. For example, if you have three balls and three cups, there are two valid solutions:

  • 2, 3, 1
  • 3, 1, 2

The following permutations do not meet the criteria for the reasons listed:

  • 1, 2, 3 (all three balls are in the correct cups)
  • 1, 3, 2 (ball 1 is in cup 1)
  • 3, 2, 1 (ball 2 is in cup 2)
  • 2, 1, 3 (ball 3 is in cup 3)

Good luck!

Solution Stats

48.89% Correct | 51.11% Incorrect
Last solution submitted on Dec 02, 2014

Problem Comments

Discover MakerZone

MATLAB and Simulink resources for Arduino, LEGO, and Raspberry Pi

Learn more

Discover what MATLAB® can do for your career.

Opportunities for recent engineering grads.

Apply Today

MATLAB Academy

New to MATLAB?

Learn MATLAB today!

Join the 15-year community celebration.

Play games and win prizes!

Learn more