summary refs log tree commit diff homepage
path: root/2018/day10.c
blob: dddae455f3c5af77cd991038751fbcc9ab3f3c77 (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
33
34
35
36
37
38
39
40
41
42
43
44
45
46
#include <limits.h>
#include <stdio.h>
#include <stdlib.h>

struct Point {
	int x, y;
	int dx, dy;
};

int main() {
	size_t len = 0;
	struct Point points[500];
	while (!feof(stdin)) {
		scanf(
			"position=<%d, %d> velocity=<%d, %d>\n",
			&points[len].x, &points[len].y, &points[len].dx, &points[len].dy
		);
		len++;
	}
	int minX, minY, maxX, maxY;
	int secs = 0;
	do {
		minX = minY = INT_MAX;
		maxX = maxY = INT_MIN;
		for (size_t i = 0; i < len; ++i) {
			points[i].x += points[i].dx;
			points[i].y += points[i].dy;
			if (points[i].x < minX) minX = points[i].x;
			if (points[i].y < minY) minY = points[i].y;
			if (points[i].x > maxX) maxX = points[i].x;
			if (points[i].y > maxY) maxY = points[i].y;
		}
		secs++;
	} while (maxY - minY > 9);
	for (int y = minY; y <= maxY; ++y) {
		for (int x = minX; x <= maxX; ++x) {
			size_t i;
			for (i = 0; i < len; ++i) {
				if (points[i].x == x && points[i].y == y) break;
			}
			printf("%c", (i == len ? '.' : '#'));
		}
		printf("\n");
	}
	printf("%d\n", secs);
}
e supposed to have intervening fseeks. 2019-12-24Exit git-fetch-email on getopt failure 1.0June McEnroe 2019-12-23Export References headerJune McEnroe 2019-12-23Add (GNU/)Linux compatibilityJune McEnroe Implements a dumb version of readpassphrase that calls getpass and implements funopen in terms of fopencookie. 2019-12-23Handle folded From headersJune McEnroe 2019-12-23Restrict search to plain-text messagesJune McEnroe 2019-12-23Properly support using drill rather than digJune McEnroe Silly drill doesn't have +short, so emulate it by waiting for the ANSWER SECTION and skipping the leading fields. 2019-12-22Document dig requirement in imbox(1)June McEnroe 2019-12-22Add CAVEAT about expecting plain-textJune McEnroe 2019-12-22Quote user, pass and mailboxJune McEnroe 2019-12-22Use sequence numbers rather than UIDsJune McEnroe We aren't doing any expunging or anything across different sessions, so it's safe to just use sequence numbers. 2019-12-22Use EXAMINE rather than SELECTJune McEnroe This is a read-only operation. 2019-12-22Export To and CC headersJune McEnroe 2019-12-22Add missing includeJune McEnroe 2019-12-22Export In-Reply-To headersJune McEnroe 2019-12-21Add git-fetch-email to READMEJune McEnroe 2019-12-21Clarify purpose in READMEJune McEnroe 2019-12-21Add READMEJune McEnroe 2019-12-21Add copyright header to git-fetch-emailJune McEnroe 2019-12-21Add git-fetch-email to SEE ALSO of imboxJune McEnroe 2019-12-21Add git-fetch-email wrapperJune McEnroe 2019-12-21Determine host by SRV lookupJune McEnroe 2019-12-21Clean up remaining codeJune McEnroe 2019-12-21Clean up mboxrd codeJune McEnroe 2019-12-21Convert CRLF to LFJune McEnroe 2019-12-21Implement -CFSTJune McEnroe 2019-12-21Rewrite aspirational manualJune McEnroe 2019-12-21Null-terminate read literalsJune McEnroe