I independently arrived at something very similar to Samuel’s 40-part solution, but with the gear bits in a mirror-image orientation, which seems to make things a little more compact:
https://www.lodev.org/jstumble/?board=00llllr0r0eerllleexlleeagagafxareelrlrelexelieilie0
The blue lever is used to start, and the output will always be a red ball. There appears to be a condition where a ball could fall off the left-most gear bit, but in practice this won’t happen because a red ball always winds up in one of the interrupters before a blue ball can come through with the gear bits pointing right.