Solution (source code)

= Solution

Generate successive states lazily and take exactly their initial nonempty segment:
``
runSystem :: (State, [Rule]) -> [State]
runSystem (state, rules) =
  takeWhile (not . null) (iterate (step rules) state)
``
The <iterate function> starts with `state` itself and repeatedly applies `step rules`. The <takeWhile function> excludes the first empty state and everything after it. If the initial state is empty, the result is `[]`. If the process never reaches an empty state, the answer is a potentially infinite <list> whose finite prefixes can be observed through <lazy evaluation>. No artificial maximum number of rewriting steps is introduced.