Matt can buy 48 buns in 3 ways:
... 6 packages of 8
... 3 packages of 8 and 2 packages of 12
... 4 packages of 12
_____
The least common multiple of 8 and 12 is 24. There are 2 ways to get 24 (3×8 or 2×12), and 2 groups of 24 in 48. Both groups can be of 8s or 12s or there can be one of each.