Hardware interview practice
Random palindrome array constraint
A sequence item needs a short digit array that reads the same forward and backward. Write constraints for size, digit range, full palindrome symmetry, and a bounded sum.
Starting point
Question code
class palindrome_item;
rand int unsigned digits[];
endclassReviewed example
Work through one case
Input
digits='{4,0,1,1,0,4}Expected output
Legal; size=6 and sum=10Every element equals its mirror, every digit is 0..9, and the total is within 36.
What to cover
Requirements
- Constrain digits.size() to be from 5 through 9 inclusive.
- Constrain every element to the inclusive range 0 through 9.
- For every valid index i, constrain digits[i] to equal digits[digits.size()-1-i].
- Constrain the sum of all digits to be no greater than 36.
