No translations... yet

It is said Hex means "Witch" in German. However it is not about life of Witches :)

Hopefully you remember exercises on Conway's Game of Life, for example Life is Simple.

Naturally, here comes simple exercise - I come upon this on my own when yet in school - but surely idea came to other people too. Imagine this game played on hexagonal grid (remember we had related exercise too).

Now every cell has only 6 neighbors, so rules could be slightly modified to prevent explosive growth or fast extinction. For example, let's agree new organism is born in any empty cell having 2 neighbors, while any living cell with less or more than exactly 3 shall perish.

Regard evolution of this simple pattern:

 - - - -     - - - -     - - - -
- - - - -   - - $ - -   - - - - -
 - $ $ -     - - - -     - $ $ -
- - $ - -   - $ - $ -   - - $ - -
 - - - -     - - - -     - - - -

This obviously a kind of flip-flop - repeated pattern. You may find that with some simple rules periodical patterns are very abundant.

However I failed to find any self-moving pattern (similar to glider in classic "Life") - you may try yourself, it's curious - just don't forget to share if you find it!

Problem Statement

You are given a fragment of hexagonal field as input, with some random colony of organisms. Produce the same fragment on the next "generation" of Hexagonal Life!

Input comes in several lines, which have cells marked with "dashes" (empty) or "dollars" (live).
Spaces are inserted for formatting in the hexagonal style, as in example above. It is granted that border cells are empty so you'll need not resize the field or truncate population on border.
The first line gives W and H - length of lines (in characters, not cells) and their amount.

Answer should give the same fragment in the same formatting, just representing next generation.

Example

input:
9 3
- - - - -
 - $ $ - 
- - - - -

answer:
- - $ - -
 - - - - 
- - $ - -
You need to login to get test data and submit solution.