Ball Draw No Repeat

Draw N balls such that you get no repeats

Ball Draw Without Repeat in Last 3 Positions

Problem Statement

You are drawing from 10 colored balls (labeled 0-9) in a sequence of 10 draws. The constraint is that no color can be drawn in the last 3 consecutive positions.

  • Current draw cannot equal previous three draws

Generate a valid sequence of 10 draws that satisfies these constraints.

Constraints

  • Sequence length: 10
  • Colors available: 0-9 (integers)

Examples

Example 1:

Generate a valid sequence
Output: [0, 1, 2, 3, 4, 5, 2, 1, 3, 0]
Explanation:
- Each position i differs from i-1, i-2, and i-3
- Color 2 appears at indices 2 and 6 (difference of 4, which is > 3)
- Color 0 appears at indices 0 and 9 (difference of 9, which is > 3)

Example 2:

[0, 1, 0, 1, 0, 1, 0, 1, 0, 1]
Invalid
Explanation: Position 2 (value 0) violates the constraint because:
- Position 1 (value 1) differs: OK
- Position 0 (value 0) is the same: VIOLATION

Example 3:

[1, 2, 3, 4, 1, 2, 3, 4, 1, 2]
Valid
Explanation: Each element differs from the three preceding elements.

Loading the interactive workspace...