He will need 47 planks.
Fence length - 31 ft., which is 372 inches
4 inch plank + 4 inch gap = 8 inches
372 divided by 8 = 46.5 - but the last plank used will be a full plank, not a half plank, so 47 planks are required.
What ever width plank & gap you decide to use add the two up together & divide into 372 inches, then round up.