Let x = the number of donuts Gamma took.
The total donuts Gamma and Beta have is 40 - 8 = <<40-8=32>>32 donuts.
3x is the number of donuts for Beta.
3x + x is the number of total donuts for Beta and Gamma.
If we add the two x terms, we get 4x = 32.
If we divide both sides by 4, we get x = 8, so Gamma has 8 donuts.
#### 8