VLSI DV Interview Puzzles · All levels

Relational Pair Counting

Find all legal (a,b) pairs and compute P(a==0).

Puzzle

Difficulty: Medium · Puzzle 5 of 6 · Topic: Constraint Solving Order Puzzles

Find all legal (a,b) pairs and compute P(a==0).

Code

systemverilog
class pair_rel;
  rand int unsigned a;
  rand int unsigned b;
  constraint c {
    a inside {[0:6]};
    b inside {[0:6]};
    a < b;
    a + b == 6;
  }
endclass

Hint

Enumerate integer pairs that sum to 6, then apply a<b.

Step-by-step solution

diagram
1) Candidate pairs in 0..6 with sum 6 are (0,6),(1,5),(2,4),(3,3),(4,2),(5,1),(6,0).
2) Apply a<b -> keep (0,6),(1,5),(2,4).
3) Legal tuple count=3 and one tuple has a==0.
4) So P(a==0)=1/3.

Answer

Answer: Legal tuples are (0,6),(1,5),(2,4), so P(a==0)=1/3 (~33.33%).

Why candidates get it wrong

Candidates often enforce a<=b by mistake and incorrectly keep (3,3).

Interviewer follow-up

If you add solve a before b, does legality change? What might shift in observed solver bias?

Related topics