intermediate20 min

Puzzles and Grouping

Assign people to groups or a schedule while satisfying every stated constraint.

What you'll learn

  • Check whether a proposed group or schedule assignment satisfies every constraint
  • Systematically generate candidate assignments instead of guessing
  • Recognize the difference between an arrangement puzzle (unique positions) and a grouping puzzle (repeatable assignments)

Prerequisites

Explanation

Grouping and scheduling puzzles assign people to categories -- teams, days, committees -- subject to constraints like "Sam does not work the same day as Priya" or "exactly one person is on the Red team." They look like seating arrangements, but there's a key structural difference: in a seating arrangement, each position is used by exactly one person (it's a strict ordering); in a grouping puzzle, multiple people can share the same group or day, since a group isn't a single seat.

That difference changes how you generate candidates. Seating arrangements use permutations (every person gets a distinct position). Grouping puzzles use every possible combination of assignments -- each person independently picks one of the available groups, so with p people and g groups, there are g^p possible assignments to check, not p! orderings.

The constraint-checking discipline is identical to seating arrangements: write each clue as a function that inspects a full assignment and returns true or false, then only accept an assignment that passes every clue. "Sam does not work the same day as Priya" becomes a function checking that assignment.Sam is different from assignment.Priya.

A common shortcut: if a constraint fixes one person's group directly ("Priya is assigned Monday"), you don't need to search at all for that person -- just narrow the remaining options for whoever is constrained relative to them. But when constraints interact (several people all constrained relative to each other), a systematic search across all combinations is the only way to guarantee you haven't missed a case or accepted an invalid one.

Example

Checking whether a proposed assignment satisfies every constraint function.

function isValidGrouping(assignment, constraints) {
  return constraints.every((c) => c(assignment));
}
// isValidGrouping({ Amy: 'Mon', Ben: 'Tue' }, [(a) => a.Amy !== a.Ben]) -> true

Guided exercise

Guided exercise

Write isValidGrouping(assignment, constraints) where assignment maps each person's name to their assigned group/day, and constraints is an array of functions taking assignment and returning a boolean. Return true only if every constraint passes.

Checks: Confirms a satisfied constraint · Detects a violated constraint · plus 1 hidden check

Code editor. Press Escape then Tab to leave the editor if keyboard focus becomes trapped. Press Control+Shift+M inside the editor to toggle Tab-key focus trapping.

Loading editor…

Stuck? Get a hint.

Independent exercise

Independent exercise

Write solveGrouping(people, options, constraints) that tries every possible assignment of each person to one of options (people can share options) and returns the first assignment that satisfies every constraint, or null if none do.

Checks: Finds a valid two-person assignment · Handles a single-person case · plus 1 hidden check

Code editor. Press Escape then Tab to leave the editor if keyboard focus becomes trapped. Press Control+Shift+M inside the editor to toggle Tab-key focus trapping.

Loading editor…

Stuck? Get a hint.

Common mistakes

  • Using permutations (like seating arrangements) instead of allowing repeated group assignments.
  • Checking constraints against a partial assignment before every person has been placed.
  • Assuming a constraint that fixes one person's group automatically resolves everyone else's.

Knowledge check

Knowledge check

1. Four friends are each assigned to exactly one of two teams, Red or Blue. If exactly one friend must be on Red, how many valid team assignments are possible?
2. A scheduling puzzle states 'Sam does not work on the same day as Priya.' If there are 3 available days and Priya is assigned Monday, how many valid day options remain for Sam?
3. Why do grouping puzzles use combinations of assignments rather than permutations, unlike seating puzzles?

Takeaway

Grouping puzzles allow shared assignments, so generate candidates by combination (each person picks independently), not by permutation.

Summary

Grouping and scheduling puzzles are solved the same way as seating arrangements -- systematically checking candidates against every constraint -- but candidates are generated differently, since people can share a group or day rather than occupying a unique position.

Your notes

Notes save automatically.

Finished this lesson?

Mark it complete to track your progress and schedule a future review.