Is there a smart way to produce the following diagram using tikz?

[![enter image description here](https://i.stack.imgur.com/2zUcG.png)](https://i.stack.imgur.com/2zUcG.png)

With smart I mean not drawing each line for line and node for node but rather something like a for loop.