The task here is to read from a Golly .rle
or plaintext file (your choice) whose filename is provided (on STDIN or as a command line argument) and identify and count the common patterns in the grid encoded therein.
Alternatively, you may choose to have the contents of the file provided directly over STDIN instead.
Your program should be able to identify and distinguish at least the fifteen most common strict still lifes and the five most common oscillators, plus gliders.
All phases of these oscillators should be recognized, as should all four phases of the glider.
It should output a list containing the final count of each pattern, with the name and quantity of each pattern on a separate line. Your program may include in the ouput list either all of these patterns or only the ones of which at least one was found.
Patterns which are part of other patterns being counted should not be counted. (for example, the 8-cell phase of a beacon should not also be counted as two blocks, and a ship-tie should not also be counted as two ships)
You may assume that the input has already stabilized and contains no patterns not in the aformentioned set. You may also assume that the input grid will fit within a 1024x1024 box.
This is code-golf, so the shortest program wins.
RLE file format description
An RLE file contains a run-length encoded life grid. All lines starting with #
are comments and should be ignored.
The first non-empty, non-comment line is of the form x=<width>,y=<height>,rule=<rule>
. For the purposes of this task, the rule will always be B3/S23
. It may contain spaces which should be stripped before processing this line (of course, it is not necessary to process this line at all.)
Non-comment lines after the first should be treated as a single string. This should consist only of decimal digits, the characters $
, b
, and o
, and line breaks, and will not end with a digit. Line breaks are to be ignored, but you may assume that line breaks will not interrupt strings of digits.
This may be terminated by a single !
.
b
represents a dead cell, o
represents a live cell, and $
represents the end of a row. Any decimal number indicates that the following symbol is to be treated as repeating that many times.
Plaintext pattern encoding
The other option is to read the pattern in another plaintext format described here. In this encoding, off cells are represented with hyphens and on cells are represented with uppercase Os, with newlines separating rows.
You may assume that all non-comment lines will be padded to equal length with hyphens.
Lines starting with !
are comments and are to be ignored.
Some test cases
RLE:
#This is a comment
x = 35, y = 16, rule = B3/S23
bo$2o$obo5$22bo$22bo$22bo2$18b3o3b3o2$22bo$22bo10b2o$22bo10b2o!
Plaintext:
!This is a comment
-O---------------------------------
OO---------------------------------
O-O--------------------------------
-----------------------------------
-----------------------------------
-----------------------------------
-----------------------------------
----------------------O------------
----------------------O------------
----------------------O------------
-----------------------------------
------------------OOO---OOO--------
-----------------------------------
----------------------O------------
----------------------O----------OO
----------------------O----------OO
Results:
Glider 1
Blinker 4
Block 1
RLE:
x = 27, y = 15, rule = B3/S23
5b2o$5b2o9$11bo$o9bobo$o9bobo$o10bo12b3o!
#Here's a comment at the end
Plaintext:
-----OO--------------------
-----OO--------------------
---------------------------
---------------------------
---------------------------
---------------------------
---------------------------
---------------------------
---------------------------
---------------------------
-----------O---------------
O---------O-O--------------
O---------O-O--------------
O----------O------------OOO
!Here's a comment at the end
Results:
Block 1
Blinker 2
Beehive 1
RLE:
#You may have multiple comments
#As shown here
x = 13, y = 11, rule = B3/S23
2o$2o2$12bo$12bo$12bo$2b2o$2b2o4b2o$7bo2bo$7bobo$8bo!
Plaintext:
!You may have multiple comments
!As shown here
OO-----------
OO-----------
-------------
------------O
------------O
------------O
--OO---------
--OO----OO---
-------O--O--
-------O-O---
--------O----
Results:
Block 2
Blinker 1
Loaf 1
RLE:
# Pentadecathlon
# Discovered by John Conway
# www.conwaylife.com/wiki/index.php?title=Pentadecathlon
x = 10, y = 3, rule = B3/S23
2bo4bo2b$2ob4ob2o$2bo4bo!
Plaintext:
! Pentadecathlon
! Discovered by John Conway
! www.conwaylife.com/wiki/index.php?title=Pentadecathlon
--O----O--
OO-OOOO-OO
--O----O--
Results:
Pentadecathlon 1
Bonus
If you support both input formats (using the file extension [.rle
for rle files and .cells
for plaintext- how other extensions are to be read is undefined] or a command line flag to distinguish between them) you may subtract 5% from your score.
OOO.OO\n....OO
\$\endgroup\$