Around 40 track pieces. If you make something with this, don't forget to show me! (though this is not a requirement)
Inspired by cuboro and by similar stuff made by this guy: https://www.youtube.com/channel/UCZe0uB2yIo5RDz_-_GlDK-w
The switch hasn't got any rigidbody constraints added to it yet, but it shouldn't be too hard to add yourself.
This should work for both eevee and cycles.