~laumann/C

b5e917402f651de69e12fb2a009ddf2cba6d24f8 — Thomas Laumann 11 years ago 2a03a76
Shorter dead/alive calculation
1 files changed, 4 insertions(+), 8 deletions(-)

M conway/conway.c
M conway/conway.c => conway/conway.c +4 -8
@@ 92,15 92,11 @@ conway_timeslice(int **current, int **new, int rows, int cols)
	int i, j, sum;
	for (i=0; i<rows; i++) {
		for (j=0; j<cols; j++) {
			new[i][j] = current[i][j]; /* copy! */

			sum = neighbor_sum(current,i,j);

			/* Rule 1 + 3: He dies (under- and overpopulation) */
			if (current[i][j] && (sum < 2 || sum > 3))
				new[i][j] = 0;
			else if (sum == 3) /* dead */
				new[i][j] = 1;
			new[i][j] = (current[i][j]) ?
				((sum == 2 || sum == 3) ? 1 : 0) :
				((sum == 3) ? 1 : 0);
		}
	}
}


@@ 113,7 109,7 @@ const char conway_usage[] = "Usage: ./conway [options]\n\n"
	" -f, --file <file>       Set in input file.\n";

void
handle_cmd_args(int *argc, const char ***argv)
handle_cmd_args(int *argc, char ***argv)
{
	while (*argc > 0) {
		const char *cmd = (*argv)[0];