day 16 part 2 solved
[aoc_eblake.git] / 2016 / advent6.c
blobb3df6336365112ac0fec9b01d9c8cb95ba1af5d1
1 #define _GNU_SOURCE 1
2 #include <stdio.h>
3 #include <string.h>
4 #include <stdlib.h>
5 #include <unistd.h>
6 #include <stdbool.h>
7 #include <ctype.h>
9 unsigned int grid[8][26];
11 int main(int argc, char **argv)
13 int count = -1;
14 int limit = 8;
15 if (argc == 2) {
16 limit = atoi (argv[1]);
17 if (limit > 8)
18 return 1;
20 int c = '\n';
21 while (c == '\n') {
22 count++;
23 for (int i = 0; i < limit; i++) {
24 if ((c = getchar ()) < 0)
25 break;
26 grid[i][c - 'a']++;
28 c = getchar ();
30 printf ("after reading %d repetitions, message was: ", count);
31 for (int i = 0; i < limit; i++) {
32 int min = 0;
33 int j;
34 for (j = 0; j < 26; j++)
35 if (grid[i][j] - 1 < grid[i][min] - 1)
36 min = j;
37 putchar (min + 'a');
39 putchar ('\n');
40 return 0;