0
1
The goal of this challenge is to write a program that will simulate a single round of Conway's Game of Life on an existing grid.
Input format:
Input will be read from stdin. The input will consist of a line containing two numbers, r and c, separated by a single space. These will be the number of rows and columns of the input grid, respectively.
Following the dimensions will be the grid itself, one row per line. Each character in the row will either be a . (meaning a dead cell) or a # (meaning a living cell).
Output format:
Output will be written to stdout. The output should be formatted exactly the same way as the input (including the width and height). It should consist of the state of the grid after simulating one generation. In this way, it should be possible to simulate as many generations as desired by piping the output of one run of your program into it again in a new run. Note that your program must actually perform the simulation and cannot use external resources such as other programs or network access.
Grid boundaries are to be considered dead zones.
Sample input:
5 6
......
..#...
..#...
..#...
......
Sample output:
5 6
......
......
.###..
......
......
Scoring
Programs will be scored on the total unique bytes in the program's source. The smaller the score, the better.
Here is the scoring system that will be used to judge entries (Python):
data = open(fname, "rb").read()
unique = set(data)
score = len(unique)
print("Score for %s: %d" % (fname, score))
If two entries happen to tie, then the total length in bytes of the source will be used as a tiebreaker.
Of course, there have to be some limitations as to what programming languages may be used. Clearly I cannot allow Whitespace or Brainf*ck in this challenge or there would be no chance for other languages. Therefore, I will implement a whitelist of allowed languages. If you wish to use a language that is not present in the whitelist, post a comment and I will decide whether to add it to the list.
Language Whitelist
- Assembly
- C
- C#
- C++
- Go
- Haskell
- Java
- Lisp
- Lua
- Objective-C
- Perl
- PHP
- Python
- Ruby
- Rust
- Swift
The winner will be decided on August 1 at 11:59pm EST.
UPDATE:
As of August 1st, the winner is @mniip with a Lua solution consisting of only 9 unique characters.
How should the input/output be implemented? (Do we have to use standard input/output or read files or write a function or assume the string is saved in a variable etc?) – flawr – 2014-07-16T09:16:07.113
Is this an [tag:atomic-code-golf]? – Isiah Meadows – 2014-07-16T09:41:24.043
2
If you have to restrict languages then a) it's a deficiency of the question; b) make sure you do it right! If you're going to disqualify Brainfuck for having an 8-character symbol set you must surely disqualify JavaScript. There are several answers on this site which use JSFuck to reduce JS to a 6-character symbol set.
– Peter Taylor – 2014-07-16T10:55:38.1731
Although this question can be seen as an extreme specialisation of http://codegolf.stackexchange.com/q/11690/194 so it might be better to just close it as a dupe than try to fix it.
– Peter Taylor – 2014-07-16T10:58:17.190And it really isn't like Java can win anyway.
public static void main(String[] a){}is already 21! – Cruncher – 2014-07-16T13:38:42.983@flawr I updated the question to clarify this – C0deH4cker – 2014-07-16T15:20:55.317
@impinball No this isn't atomic-code-golf. That is when the challenge defines a subset of tokens allowed. I am not defining the allowed subset of tokens, but rather leaving it open and allowing people to pick the smallest subset of characters they can use. – C0deH4cker – 2014-07-16T15:22:30.987
1@PeterTaylor That's like saying we should close every new code-golf challenge since there have already been other code-golf challenges before. This is not a dupe. That question was overly general and had no specific challenge besides creating a really small program. Also I removed Javascript from the list of allowed languages. Had not known about that before! – C0deH4cker – 2014-07-16T15:27:03.753
@Cruncher Yeah likely not, but I decided I might as well allow it to see if some really smart person could make it very small. I know for example in java you can encode the entire program in UNC notation (a whole bunch of
\uXXXX's), so it has that going for it – C0deH4cker – 2014-07-16T15:28:29.1601@C0deH4cker in that case, you can encode any java program in 12 characters. There's no cleverness in writing it. Unless you do something special to avoid all 4's or something. – Cruncher – 2014-07-16T15:46:42.967
er... no javascript? – xem – 2014-07-16T17:43:50.917
The linked question is not relevant to this one. The other question is asking to write a program which encodes the source code of a program. This one is asking to implement conways game of life. The only similarity is the scoring mechanism of this challenge vs the outcome of the answers in the other challenge. – rdans – 2014-08-05T06:50:03.047