/*
 * Kangaroo Punch MultiPlayer Game Server Mark II
 * Copyright (C) 2020-2021  Scott Duensing
 *
 * This program is free software: you can redistribute it and/or modify
 * it under the terms of the GNU General Public License as published by
 * the Free Software Foundation, either version 3 of the License, or
 * (at your option) any later version.
 *
 * This program is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU General Public License for more details.
 *
 * You should have received a copy of the GNU General Public License
 * along with this program.  If not, see <https://www.gnu.org/licenses/>.
 *
 */


#include <stdio.h>

int main(int argc, char *argv[]) {

	(void)argc;
	(void)argv;

	// Generate a list of all primes that will fit in a 16 bit integer.

	int   i;
	int   n;
	int   p;
	int   count;
	int   flag;
	FILE *out;

	n = 8192;
	p = 2;
	i = 1;

	out = fopen("prime.txt", "wt");

	while (i <= n) {
		flag = 1;
		for(count=2; count <= p-1; count++) {
			if (p % count == 0) {  // Will be true if p is not prime
				flag = 0;
				break;           // Loop will terminate if p is not prime
			}
		}
		if (flag == 1) {
			printf("%d\n", i);
			fprintf(out, "%d, ", p) ;
			i++;
			if (p > 65535) n = 0;
		}
		p++;
	}

	fclose(out);
}
