summary refs log tree commit diff homepage
path: root/2020/day05.c
blob: ab39815de78ac73a5d54f971bdfc32ce990461c9 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
#include <stdbool.h>
#include <stdio.h>
#include <stdlib.h>
static int id(const char *s) {
	int row = 0, col = 0, size = 128;
	while (*s == 'F' || *s == 'B') {
		size /= 2;
		if (*s++ == 'B') row += size;
	}
	size = 8;
	while (*s) {
		size /= 2;
		if (*s++ == 'R') col += size;
	}
	return row * 8 + col;
}
int main(void) {
	char s[11];
	int max = 0;
	bool ids[1024] = {0};
	while (EOF != scanf("%s\n", s)) {
		if (id(s) > max) max = id(s);
		ids[id(s)] = true;
	}
	printf("%d\n", max);
	for (int i = 1; i < 1024; ++i) {
		if (ids[i-1] && !ids[i]) {
			printf("%d\n", i);
			break;
		}
	}
}