-
Notifications
You must be signed in to change notification settings - Fork 0
/
day10.c
54 lines (41 loc) · 1.17 KB
/
day10.c
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
47
48
49
50
51
52
53
54
#include "advent_of_code.h"
void solve_day10(AdventOfCode* aoc, Stream* file_stream) {
FuriString* line = furi_string_alloc();
int p1 = 0;
int cycle = 0;
int x = 1;
int interest = 20;
int step = 40;
int stop = 220;
uint8_t screen[1 + 240 / 8] = {0};
Image img;
img.width = 40;
img.height = 6;
img.data = screen;
while(true) {
if(!stream_read_line(file_stream, line)) break;
furi_string_trim(line);
if(abs(x - cycle % step) <= 1) {
screen[1 + cycle / 8] |= 1 << (cycle % 8);
}
cycle++;
const char* l = furi_string_get_cstr(line);
if(l[0] == 'n') {
continue;
}
if(abs(x - cycle % step) <= 1) {
screen[1 + cycle / 8] |= 1 << (cycle % 8);
}
cycle++;
if(cycle >= interest && interest <= stop) {
p1 += interest * x;
interest += step;
}
x += strtol(l + 5, NULL, 10);
}
FuriString* part_1 = furi_string_alloc_printf("%d", p1);
update_results(aoc, part_1, NULL);
update_images(aoc, NULL, &img);
furi_string_free(part_1);
furi_string_free(line);
}