1
0

day02 - day05

This commit is contained in:
Kevin Trogant 2025-12-12 11:29:07 +01:00
commit 837b1adfe0
19 changed files with 2861 additions and 0 deletions

19
Makefile Normal file
View File

@ -0,0 +1,19 @@
CC?=gcc
CFLAGS?=-O0 -g
CFLAGS:=$(CFLAGS) -Wall -Wextra -Werror -Wno-missing-field-initializers -Wno-unused-function -std=c17 -march=core-avx2 -lm
all: day02 day03 day04 day05 day06
day02: day02.c
day03: day03.c
day04: day04.c
day05: day05.c
day06: day06.c
clean:
rm -f day02 day03 day04 day05 day06

39
aoc.h Normal file
View File

@ -0,0 +1,39 @@
#ifndef AOC_H
#define AOC_H
#include <stdlib.h>
#include <string.h>
#include "rtcore.h"
typedef enum
{
DS_FULL,
DS_DEMO,
} dataset;
static inline dataset
ParseDatasetOption(int argc, char **argv)
{
dataset ds = DS_FULL;
if (argc >= 2)
{
if (strcmp(argv[1], "full") == 0)
ds = DS_FULL;
else if (strcmp(argv[1], "demo") == 0)
ds = DS_DEMO;
}
return ds;
}
static inline arena
CreateArena(void)
{
byte *mem = malloc(megabytes(256));
return (arena){
.begin = mem,
.end = mem + megabytes(256),
};
}
#endif

132
day02.c Normal file
View File

@ -0,0 +1,132 @@
#define RT_CORE_IMPLEMENTATION
#include "rtcore.h"
#include "aoc.h"
#include <math.h>
typedef struct
{
i64 first;
i64 last;
} range;
i64 S8ToInt(s8 s, int base)
{
isize at = s.length - 1;
i64 exp = 1;
i64 val = 0;
while (at >= 0)
{
u8 c = s.data[at];
int digit = 0;
if (c >= '0' && c <= '9')
digit = c - '0';
else if (c >= 'A' && c <= 'Z')
digit = c - 'A';
else if (c >= 'a' && c <= 'z')
digit = c - 'a';
else if (c == '-')
{
val *= -1;
break;
}
else if (c == '+')
{
break;
}
else
return 0;
val += digit * exp;
exp *= base;
--at;
}
return val;
}
internal int
NumberOfDigits(i64 v)
{
return (int)floor(log10((double)v)) + 1;
}
int
main(int argc, char **argv)
{
arena arena = CreateArena();
dataset ds = ParseDatasetOption(argc, argv);
s8 input = {0};
if (ds == DS_FULL)
input = ReadEntireFileS8(S8("inputs/day02_full"), &arena);
else if (ds == DS_DEMO)
input = ReadEntireFileS8(S8("inputs/day02_demo"), &arena);
if (!input.data)
return 1;
/* First parse the ranges. */
split_result split = S8Split(input, ',');
range *ranges = (range *)arena.begin;
isize num_ranges = 0;
while (split.first.data)
{
split_result range_str = S8Split(split.first, '-');
range range = {0};
range.first = S8ToInt(range_str.first, 10);
range.last = S8ToInt(S8TrimRight(range_str.second), 10);
ranges[num_ranges++] = range;
split = S8Split(split.second, ',');
}
arena.begin += sizeof(range) * num_ranges;
/* We can generate numbers that consist of 2 repeating sequences with:
* (10**n + 1) * m (with m < 10**n)
*
* For a number with k digits, n is k / 2
* ex. 123123 has k=6 digits, which gives n = 3
* and obviously m = 123
* => (10**3 + 1) * 123 = 1001 * 123 = 123123
*
* Now we can step through every (m,n) that generates numbers in the current range.
*/
double sum = 0.0;
for (isize range_idx = 0; range_idx < num_ranges; ++range_idx)
{
int k0 = NumberOfDigits(ranges[range_idx].first);
int k1 = NumberOfDigits(ranges[range_idx].last);
printf("%ld - %ld -> %d %d\n", ranges[range_idx].first, ranges[range_idx].last, k0, k1);
double range_first = (double)ranges[range_idx].first;
double range_last = (double)ranges[range_idx].last;
for (int k = k0; k <= k1; ++k)
{
if ((k % 2) != 0)
continue;
double n = (double)k / 2;
double fac = pow(10.0, n) + 1.0;
double max_m = pow(10.0, (double)n);
double min_m = pow(10, (double)n - 1);
double m_from_range = ceil(range_first / fac);
min_m = max(min_m, m_from_range);
printf("For k=%d we get n=%lf min_m = %lf max_m = %lf, m_from_range = %lf\n", k, n, min_m, max_m, m_from_range);
for (double m = min_m; m < max_m; m += 1.0)
{
double id = fac * m;
if (id >= range_first && id <= range_last)
{
printf("Invalid id: %lf\n", id);
sum += id;
}
if (id > range_last)
break;
}
}
}
printf("Answer: %lf\n", sum);
return 0;
}

100
day03.c Normal file
View File

@ -0,0 +1,100 @@
#define RT_CORE_IMPLEMENTATION
#include "rtcore.h"
#include "aoc.h"
global_variable i64 _exponents[12] = {
100000000000, /* 10^11 */
10000000000, /* 10^10 */
1000000000, /* 10^9 */
100000000, /* 10^8 */
10000000, /* 10^7 */
1000000, /* 10^6 */
100000, /* 10^5 */
10000, /* 10^4 */
1000, /* 10^3 */
100, /* 10^2 */
10, /* 10^1 */
1, /* 10^0 */
};
int
main(int argc, char **argv)
{
(void)_exponents;
arena arena = CreateArena();
dataset ds = ParseDatasetOption(argc, argv);
s8 input = {0};
if (ds == DS_FULL)
input = ReadEntireFileS8(S8("inputs/day03_full"), &arena);
else if (ds == DS_DEMO)
input = ReadEntireFileS8(S8("inputs/day03_demo"), &arena);
if (!input.data)
return 1;
split_result split = S8Split(input, '\n');
i64 total = 0;
while (split.second.data)
{
s8 bank = S8Trim(split.first);
assert(bank.length >= 12);
printf("%.*s - ", (int)bank.length, bank.data);
i64 max = 0;
s8 workbank = bank;
isize selected[12] = {};
i64 val = 0;
memset(selected, -1, sizeof(selected));
for (isize digit = 0; digit < 12; ++digit)
{
/* 11 - digit is the number of digits that need to
* fit into the remaining string */
isize limit = workbank.length - (11 - digit);
i32 max = -1;
for (isize i = 0; i < limit; ++i)
{
i32 v = workbank.data[i] - '0';
if (v > max)
{
max = v;
selected[digit] = i;
}
}
workbank.data += selected[digit] + 1;
workbank.length -= selected[digit] + 1;
if (digit > 0)
selected[digit] += selected[digit - 1] + 1;
val += _exponents[digit] * (bank.data[selected[digit]] - '0');
}
printf("%ld\n", val);
total += val;
#if 0
i32 max = 0;
for (isize first = 0; first < bank.length - 1; ++first)
{
i32 tens = (i32)(bank.data[first] - '0') * 10;
for (isize second = first + 1; second < bank.length; ++second)
{
i32 ones = (i32)(bank.data[second] - '0');
i32 joltage = tens + ones;
if (joltage > max)
max = joltage;
}
}
printf("%d\n", max);
#endif
total += max;
split = S8Split(split.second, '\n');
}
printf("Answer: %ld\n", total);
return 0;
}

175
day04.c Normal file
View File

@ -0,0 +1,175 @@
#include <limits.h>
#include <stdlib.h>
#define RT_CORE_IMPLEMENTATION
#include "rtcore.h"
#include "aoc.h"
enum
{
F_EMPTY = '.',
F_PAPER = '@',
};
typedef struct
{
char *fields;
int *weights;
int rows;
int cols;
} grid;
typedef struct
{
int x;
int y;
} cell_coord;
force_inline char GetField(const grid *g, int x, int y)
{
if (x < 0 || x >= g->cols || y < 0 || y >= g->rows)
return F_EMPTY;
return g->fields[y * g->cols + x];
}
force_inline int *GetWeight(const grid *g, int x, int y)
{
if (x < 0 || x >= g->cols || y < 0 || y >= g->rows)
return 0;
return &g->weights[y * g->cols + x];
}
internal void CountInputRes(s8 input, int *x, int *y)
{
split_result split = S8Split(input, '\n');
int rows = 0;
int cols = 0;
while (split.second.data)
{
if (cols == 0)
cols = (int)split.first.length;
++rows;
split = S8Split(split.second, '\n');
}
*x = cols;
*y = rows;
}
internal grid FillGrid(s8 input, arena *a)
{
grid grid = {0};
CountInputRes(input, &grid.cols, &grid.rows);
grid.fields = alloc(a, char, grid.cols * grid.rows);
grid.weights = alloc(a, int, grid.cols * grid.rows);
split_result split = S8Split(input, '\n');
int y = 0;
while (split.second.data)
{
memcpy(&grid.fields[y * grid.cols], split.first.data, grid.cols);
++y;
split = S8Split(split.second, '\n');
}
for (int y = 0; y < grid.rows; ++y)
{
for (int x = 0; x < grid.cols; ++x)
{
if (GetField(&grid, x, y) == F_PAPER)
{
int p = (GetField(&grid, x - 1, y - 1) == F_PAPER) +
(GetField(&grid, x, y - 1) == F_PAPER) +
(GetField(&grid, x + 1, y - 1) == F_PAPER) +
(GetField(&grid, x - 1, y) == F_PAPER) +
(GetField(&grid, x + 1, y) == F_PAPER) +
(GetField(&grid, x - 1, y + 1) == F_PAPER) +
(GetField(&grid, x, y + 1) == F_PAPER) +
(GetField(&grid, x + 1, y + 1) == F_PAPER);
*GetWeight(&grid, x, y) = p;
}
else
{
*GetWeight(&grid, x, y) = INT_MAX;
}
}
}
return grid;
}
global_variable grid _g;
internal int compare_cells(const void *_a, const void *_b)
{
// We subtract b - a, so that the lower elements get moved to the back
// (Ret < 0 -> _a gets placed before _b)
const cell_coord *a = _a, *b = _b;
return *GetWeight(&_g, b->x, b->y) - *GetWeight(&_g, a->x, a->y);
}
int
main(int argc, char **argv)
{
arena arena = CreateArena();
dataset ds = ParseDatasetOption(argc, argv);
s8 input = {0};
if (ds == DS_FULL)
input = ReadEntireFileS8(S8("inputs/day04_full"), &arena);
else if (ds == DS_DEMO)
input = ReadEntireFileS8(S8("inputs/day04_demo"), &arena);
if (!input.data)
return 1;
grid g = FillGrid(input, &arena);
_g = g;
cell_coord *paper_coords = alloc(&arena, cell_coord, g.rows * g.cols);
int num_papers = 0;
for (int y = 0; y < g.rows; ++y)
{
for (int x = 0; x < g.cols; ++x)
{
if (GetField(&g, x, y) == F_PAPER)
{
paper_coords[num_papers++] = (cell_coord){x, y};
}
}
}
int count = 0;
while (num_papers > 0)
{
qsort(paper_coords, num_papers, sizeof(cell_coord), compare_cells);
cell_coord lowest = paper_coords[--num_papers];
int neighbors =
(GetField(&g, lowest.x - 1, lowest.y - 1) == F_PAPER) +
(GetField(&g, lowest.x, lowest.y - 1) == F_PAPER) +
(GetField(&g, lowest.x + 1, lowest.y - 1) == F_PAPER) +
(GetField(&g, lowest.x - 1, lowest.y) == F_PAPER) +
(GetField(&g, lowest.x + 1, lowest.y) == F_PAPER) +
(GetField(&g, lowest.x - 1, lowest.y + 1) == F_PAPER) +
(GetField(&g, lowest.x, lowest.y + 1) == F_PAPER) +
(GetField(&g, lowest.x + 1, lowest.y + 1) == F_PAPER);
// Terminate condition: No paper can be removed
if (neighbors >= 4)
break;
g.fields[lowest.y * g.cols + lowest.x] = F_EMPTY;
++count;
for (int dy = -1; dy <= 1; ++dy)
{
int y = lowest.y + dy;
if (y >= 0 && y < g.rows)
{
for (int dx = -1; dx <= 1; ++dx)
{
int x = lowest.x + dx;
if (x >= 0 && x < g.cols)
{
*GetWeight(&g, x, y) -= 1;
}
}
}
}
}
printf("Answer: %d\n", count);
return 0;
}

92
day05.c Normal file
View File

@ -0,0 +1,92 @@
#include <limits.h>
#include <stdint.h>
#define RT_CORE_IMPLEMENTATION
#include "rtcore.h"
#include "aoc.h"
typedef struct
{
i64 first;
i64 last;
} range;
int sort_range(range *a, range *b)
{
return a->first <= b->first ? -1 : 1;
}
int
main(int argc, char **argv)
{
arena arena = CreateArena();
dataset ds = ParseDatasetOption(argc, argv);
s8 input = {0};
if (ds == DS_FULL)
input = ReadEntireFileS8(S8("inputs/day05_full"), &arena);
else if (ds == DS_DEMO)
input = ReadEntireFileS8(S8("inputs/day05_demo"), &arena);
if (!input.data)
return 1;
range *ranges = (range *)arena.begin;
isize range_count = 0;
split_result line = S8Split(S8Trim(input), '\n');
while (line.first.data)
{
if (line.first.length == 0)
{
break;
}
split_result split = S8Split(S8Trim(line.first), '-');
s8_parse_i64_result parsed_first = S8ParseI64(split.first, 10);
if (!parsed_first.ok)
return 1;
s8_parse_i64_result parsed_second = S8ParseI64(split.second, 10);
if (!parsed_second.ok)
return 1;
i64 first = parsed_first.i;
i64 last = parsed_second.i;
ranges[range_count].first = first;
ranges[range_count].last = last;
++range_count;
line = S8Split(line.second, '\n');
}
line = S8Split(line.second, '\n');
i32 fresh_count = 0;
while (line.first.data)
{
s8_parse_i64_result id_ = S8ParseI64(line.first, 10);
if (!id_.ok)
return 1;
i64 id = id_.i;
for (isize i = 0; i < range_count; ++i)
{
if (id >= ranges[i].first && id <= ranges[i].last)
{
++fresh_count;
break;
}
}
line = S8Split(line.second, '\n');
}
printf("Answer: %d\n", fresh_count);
qsort(ranges, range_count, sizeof(range), (__compar_fn_t)sort_range);
/* Part two */
for (isize i = 0; i < range_count; ++i)
{
printf("%ld-%ld\n", ranges[i].first, ranges[i].last);
}
return 0;
}

86
day06.c Normal file
View File

@ -0,0 +1,86 @@
#define RT_CORE_IMPLEMENTATION
#include "rtcore.h"
#include "aoc.h"
int
main(int argc, char **argv)
{
arena arena = CreateArena();
dataset ds = ParseDatasetOption(argc, argv);
s8 input = {0};
if (ds == DS_FULL)
input = ReadEntireFileS8(S8("inputs/day06_full"), &arena);
else if (ds == DS_DEMO)
input = ReadEntireFileS8(S8("inputs/day06_demo"), &arena);
if (!input.data)
return 1;
i64 *cells = (i64 *)arena.begin;
char *ops = NULL;
i32 idx = 0;
i32 columns = -1;
i32 rows = 0;
/* First parse the matrix. */
split_result line = S8Split(input, '\n');
while (line.first.data)
{
i32 cols = 0;
split_result fields = S8Split2(S8Trim(line.first), ' ');
while (fields.first.data)
{
if (fields.first.data[0] == '*' || fields.first.data[0] == '+')
{
if (cols == 0)
{
arena.begin += idx * sizeof(i64);
ops = alloc(&arena, char, columns);
}
ops[cols] = fields.first.data[0];
}
else
{
s8_parse_i64_result r = S8ParseI64(fields.first, 10);
if (!r.ok)
return 1;
cells[idx++] = r.i;
}
++cols;
fields = S8Split2(fields.second, ' ');
}
assert(columns == -1 || columns == cols);
columns = cols;
++rows;
line = S8Split(S8Trim(line.second), '\n');
}
--rows; /* Don't count the ops */
i64 *results = alloc(&arena, i64, columns);
for (i32 i = 0; i < columns; ++i)
{
if (ops[i] == '+')
{
results[i] = 0;
for (i32 j = 0; j < rows; ++j)
{
results[i] += cells[j * columns + i];
}
}
else if (ops[i] == '*')
{
results[i] = 1;
for (i32 j = 0; j < rows; ++j)
{
results[i] *= cells[j * columns + i];
}
}
}
i64 answer = 0;
for (i32 i = 0; i < columns; ++i)
answer += results[i];
printf("Answer: %ld\n", answer);
return 0;
}

18
helpers/day03_exps.c Normal file
View File

@ -0,0 +1,18 @@
#include <stdio.h>
#include <stdint.h>
int
main()
{
int64_t exponents[12];
exponents[11] = 1;
for (int i = 10; i >= 0; --i)
exponents[i] = 10 * exponents[i + 1];
printf("global_variable i64 _exponents[12] = {\n");
for (int i = 0; i < 12; ++i)
{
printf(" %li, /* 10^%d */\n", exponents[i], 11-i);
}
printf("};\n");
return 0;
}

1
inputs/day02_demo Normal file
View File

@ -0,0 +1 @@
11-22,95-115,998-1012,1188511880-1188511890,222220-222224,1698522-1698528,446443-446449,38593856-38593862,565653-565659,824824821-824824827,2121212118-2121212124

1
inputs/day02_full Normal file
View File

@ -0,0 +1 @@
199617-254904,7682367-7856444,17408-29412,963327-1033194,938910234-938964425,3207382-3304990,41-84,61624-105999,1767652-1918117,492-749,85-138,140-312,2134671254-2134761843,2-23,3173-5046,16114461-16235585,3333262094-3333392446,779370-814446,26-40,322284296-322362264,6841-12127,290497-323377,33360-53373,823429-900127,17753097-17904108,841813413-841862326,518858-577234,654979-674741,773-1229,2981707238-2981748769,383534-468118,587535-654644,1531-2363

4
inputs/day03_demo Normal file
View File

@ -0,0 +1,4 @@
987654321111111
811111111111119
234234234234278
818181911112111

200
inputs/day03_full Normal file
View File

@ -0,0 +1,200 @@
5336553644444345344544134246423443634474453456455433543434354444344554344336446734443434424442135474
2231552222211222122232222222153222143972321313222122221132199121111212232232222223322324232211141222
2772224762425225322223343411225274238762252256511426224222252321273712444222223222322212222372514722
2222332122223225222222231122322211162222222122222223222222112222222221222221122222211222221323211121
2442432212422332232212684452222313252425265641254324242452246232226535522434643524124524537424423362
2222233422111423621122222212311251411422222223222912458231222425211121231623223282223222522223222122
6222223242223652228324218422222362221764545245524242232623222297125251246222225724122121211122224222
4232224233342412225323232213216232342313322232223122122235533321125233534232433231314523232332322221
2122322222214334122221225332224135442322222222212222422222323226222122212232212224221122213432222122
2424223122212362222224552241443214224422422432222223843433512122232228212222124434222582122223222222
2432223333332221313232223422213342233315232323222331512443326233254223233333233636213322362222256222
7122126632562515224125225362667124227322322242224271222621716242222212522123121227432224225952272253
2222212212242122222232222221221722123232232212122212232222221222322221222233321212222421322222222212
2221221422211222212322322121412222222222122222222224241219222222222222221222112223222322212632122222
5534445456247653656757666664627455835542585748445743654764144452444387554884458915245555558444643884
9512534434375364134535574254437735656452833258371533854544254231533455464457764721474675412285253244
1222132235322123232352222234221222222232222343133534223311734323361424423343223254323262234232412232
3335393323363345233744353533723247497385344635743444543334136356167734741354933353336333373325323363
6246535473632347143443572543225451752532247667623444533348753324456165153345524525229354246267552136
3833423335226442242752254233438221626337276763855254394314383424391322976834897938339225342384484139
6566326325524467263334162556535653665353335233353664454455232456455242645465666454544553386416347535
4324186432313312134243423843486524124326333333433323213351442733425223432233323283333443833433213244
5331244255455613356533321313557625245322332438123334257346465238275342452343137252243454142412433412
3636221535225324121161754452223333432625253335323942128583211532241273421552322635332525352358633395
1434424644342423614412464334249543241223622174434228241426244444222346244218262266224444458241414316
4429643565232425335455432594493435463576463335543244433365262284343643434433375323444336235434367853
3333348355135625533433434354535533552333333254363623545454353346333355553533355333333335545375745333
9413365353252234324342233243221133223434433413483224344244114522232211446173522421253531512217333231
5355634553564545344643644465443354144553453444453345354624334535434345444544445634341555444557443455
1242224257112316335224222232243261832293222423332732225242234225232332382414535443333422422333222331
2221332115546245222243332562793281316628425355453522312122442428632218343424314238511422857223243245
3212222212222312212222224211242222112322232222222222151223211222252122524222222276222221212232212323
3222225222232221112232232222223342231221221223342212223134233222222332222315332222322212341222124232
2212334243133632233222232132122547323243313433286331313223512422233234232332223244323223327523226335
2122223432122231232152222122224122443212122222422222242253222212222222321225323232232211222223231232
2244622222232212222242224212142423222123323122422412232423323324432241321323364142423222223233411225
6222423434424455444354144148342344374233244314223355434444343114251222313122428334422422443428433223
3325133224211221234125132133262122322121125262222122273311632232111232122322423232324421233162432232
5637666677943457253454738838787924579339159539896464934479569377944395958548836349747363665486449333
2335224252512222332222512422323442312222432222121131222224422433531222232224321331123352233321361521
2132128512324422422435822243221724432283234851222824264222292232222264242333343231122258221452223252
5526862426624475574252856573796356754365634425536464563546663465229665555553346633385746235344462425
8222263129412219224258536469522726265398956353283431222762985937532863646362328356224222642445222111
6236221122224222122213221222126622145225272222226222121122422221631122222232223222223422231124224414
2122332124322232232222222221226112257422632232423232221216222222244232142443322321722212124222233223
2233222222211228282214322222227212222222212221244224212263712213342222232522142122415222232322283232
4633454261634464152435443124252423444372351444625334424633335426645322323226634643354242253135326245
5678982394685564845994548657644669444558464947748578335844998769476397766345944646499828444464863436
2432353123332533122523225323134434143222322323321442323223441143535334332344233333333433333332322432
5445354524444553433774155342432544354435484255854333514533562923334444543244335434343346344134333476
2321344223851236236322443422436332443414234464224817412442644242424222244632232542234532335324242334
2222223122523215222222222221362222122132322342254232325222125131222262231223222123212122223224111262
2533333663433435543462553544333464333233532345326332253233633453447435342242415433343655634335352266
2233432331345835321313332433222633566311333365337323237332444564333332432423334215232332224322433634
7224252465341134353224671212245243514323345312427223442242132255742541224325533433326331221432243212
3222232163134332123233342223322233383262222333123231232332243323533223234233334332422433334334232432
2154534332343514341333463325334645234573643247242544225243633435524224433432656273633324637523322143
5145513444512134242431353321552131334342142341531323351541353545355124411435413544254442343313346789
4634443444547564454535457334435334463553456444843344524344832442855447443844354754345448415474845343
1323131421243626533322324315621261232129463912228668231154214444517427321284416448333612262343332527
2322222322222157522321312232232271322222222234272246222221331322332413225221222322237212222213452222
3232522214322232222232324231232431722322222342342241443122222323322322322243222322231243123231233323
4345222132632322234242343613632223331222223328383242222632233133522435222633222221326123243621122436
7433257484523366444617242684443254482342134233331526534514323426271284776345312453344186353431639431
9214342212223723243326422342652224164271452123412422532623224322341231223212235212223221222634434435
3564546123223222531252252522121332524612412253222222232232224424422151215212522221342242211424222134
7453433853366853658525854223338553667352333585343344315442274459554343694755458365524564583734397265
3553515453526335821442323544154332433425255115455219523343223225655453383221253393442333635322232355
2323232322233122221224222111322222332322211222332221333232222323333222322314223222323112242233222333
4333331335432323737332423343343224333233273132433133323432342423833234352623142313332333343323233224
6322223221223223222222222222223122242122342212222222222212722122832322213212424331222212223222262214
1423443416323252424932416443425571522534322276431723266212255282578276186352235252224258522515621452
3573553334519433332763744335535636343362286677837432334354435463765235352664356363263356336532237237
6113635328352623431322232828262444746448414873243353662187252466123634264535262243834442323326254553
5486574862454574344447734335813467864444275314764454438848385373449844532533797368534836815543674567
5624241446642762525428236843434782152225343232123686742575651477545574442472256643243624145433545252
3322332325512323242112542327331233335355332323833223343232333363332231332222233233343143332633252212
2221221221211222332725232512221242213332122265225221224432263232212242232272272155254347725123524212
3435623433452254355334236443122433433774353441243343723523344354357333347323334346333324335331342396
3372133423342432543423233333332934423433223322263331333222323343333432332333622332433323624243323443
5153522485233336423557422642523125555232424314216363223931474143556314435424333333134344543353634724
4431333322223322122322133242332237223216217233262123423236336221233331323212332432321233212312233211
4273766364364364655646636764456566664486572444347935446768668666555466465466324635358758666626644765
8353428675276531424242352242842454528545321623173972565527756985264327342746265422243376731272443245
3244442364341425252371262243432122221422624233364335216334132224653452124253421225252422244133252363
3322112212722221225221222422123221111242264212622222542722232237122221222142222113322292222221222221
4224443345445736233345344453424443444443434454444341421433354334644445343543441444243378343524415483
5543555445444342555344353455333452553253432354364435334423551355454124334343433443463433245555334463
9459632664652175793511423543438453733546775296353233368372323633444893214375436376751336365296442933
6684956778789897766976966779578748656676877675996987448628697786699977485795996797799499599879366597
2332333353364332643333335332623333523332233332535523333313363222242362322333336443523335433314334333
2212333262343232222142224653123133133332336442332233223323323233322213231322233123222433632232533222
4244332443324312745322622221314464334132126237435332222214231553234233212232123234343435435224722323
5235454144443534343235442423344235444323432442454454454443444332233433544244633434554426345333434334
6162321135333124313242362623262352325228242354422226233323133113632326225333223332592222315163266232
6443453543334546545634524843553334424254145545425564345335534451472437755444765635244223453336533595
5235553432323222434353234554332212315224155332242483222543221135253533223242437333533242254334258542
5212231224312712512222124253421112212441424122122146222221262225232622112264322222223244124253233541
1561232212221221221721221327324642414342517662211357223356477323132351242122563322243213412522622512
2323969243372322938332526337221165933235227131687296213252662531524437527284729253511334229133235436
2342232222222146125316153626218245622433222236542233625353314232263222244513524321313222232322232823
1342334332323323434451123323233433233121144331322342315342522731333332122233371323326124423313224253
1223122222323222222344332322222512222223222222222222132222224224212333422331223234323233222123132224
5255323322222131232339223153323322221222223312325332225522333422333322213322236431421333333223232133
5774662565434662544452426446275286662563474232352644526648674554413544854255424662535673643565765663
4433545546337355545455654557555465733569744955683676558545454545549565344855554594454718565459546445
4336523445443593523464455244445738633353444454456234434533244534443445432312472334346234535433544553
2833324214522451212343233441642223232222313383222229514133245413412942232431434236244222332252246122
4457462445545666854155774823256874546455554516646457186727856445223576676267358538826287614348132732
1233223122223133221322221321221212132222211242122224222211213322323222232222212423222222212226222222
6424433252446633434461322433222433342133334476234523452345342132423436133236243232345434434933333454
3474443452446431344474444436443244223533242344244444443443444464344344342343463659435732344434447244
6224463414754576665425424544934552736357254143355333542564547555445335623322323693434433345453357453
4232422525233332345352243234256237325354742355315935122265254245275534322646144325262335634355243233
3421222232322235232225233242222235322451222222222221622222522221221352222222222123242113222322222232
4525354634252345424334662656165234433352556232316562562544345223343812143422473434632433632344232266
3333331462244343343343213342323233333333643333332223333211133433333144333333333433133334333342332323
3351444423337331433253625345533335333254522543375435453135433473442353233645534333453334333332444532
2231261133222247347224721312733322532223222222282233417132522424432343359324664322223233343212663331
2793725437323644653254435233353433425345335223554345423475334233523435623354323451622672343424346931
7561722372945437489223787771362729622836228356343333843917723462433378833638238394835351887379738939
3222262286724212792226485212314122752232242225327234734322322232136333264522231222715142731823223334
3312345432264325394217133433324213343222322445241241453125221432222132122351223212326435257232323222
2732332335423425242354262231123131929233152335311331233363573112323732123212232222413127381333814123
2336322233223332223443322371252223324223222333342222224312323331722242244243222323321224222223222412
6311751123743582558757672228658342222515356174644587274476221364232421756887783677887812824778636839
1421111442223124421441434411211222441313144121242441414413224322113124434423331124233143242113356789
1445245523424245334544553433315432342123525425435244256533533513434242225343254533524555456233224432
2123222311224132122212222221122231223222342222231322122222222212221242322232212231231122211322221222
8883985796555675426659999936373533987958952445479449677795598777858999733957599799545656875568335547
2112122623212322223331212212222226422222214172122523122642224222222242323421234123532222223321121249
8458686378754755587576576589759659886465778678778374653583587623886477867777584584684886675656756958
3223322133332333212231223224333221222251232331121212423134622122122223232332122254222333333131312212
4141542644444245445244432265424447445234422343354234444324683233258244684445364225538464926432442143
3228223453425236412466264333633533272367226881356944372356332332444323236327623433745523344538923323
2333313332332212222722222331221225143333133313232223322232223124213232122232243443422434321313432141
7342923454835333333223225633427423444122333272533453323472533585545331433323533728542233363447333336
2212232212121242233225222422222222421432421222423132142222221122221422322212533222522222222212122224
4622234322422124213121323333233233312174431342133231211242324323232421221233234223333342323332311333
2321232211222222212223222121222126123122123222212222222713222122122221212122212222222221132212241222
3332321222521221232324223413226223332213645322222222222222421332164412132122523232221121332532143222
3232328233423212123332333323432733423313433321231333532413232322314323311222334243233245323225433213
4736875381141534423854564745441756442425372355252315442444344425221525324555345527441547525234274422
3332355333332355333353443333352353433342413333323533333314333332334223333244333123333353433433313333
3223242252222112251255231122331222222112452424221221232312115222235222221212222222275212222212552125
4513232513422226322223622426222412252242432315264615452122324244441362543232243243543143415432123444
1242225222444327221222225524222322244123112632325122264221462222221363222229224423242222424562622252
4333531223234423332413333423463243434363235234334453422343231433233334441412433333415334333258333313
4448433512666323424233523547255464334345321633343458215355344466552336444317333333127434753334332333
7345354336432434223224313354453545434252434283344552223423328443342344455612425453344412312224425274
4221122232333322224122322232521124223221222222221222231236242222421222222231311222343292223323322252
2213212223323321232243221332134233321424332222122212232135222231932224221222225112221242321433222132
4253724445422452428224374464243663253445354661415412544424627465526524452334354534241532245612415423
2122214225223214222222443211212422217412125212525121224425346421223352221224213232342224442322224311
3322234333332321263333333933333333733323432553533333333323633351333333523661333331134332333323433233
3222721312222123412223432171222123223263322221332122232313322222123232312432223221129222121122132221
2522642322122524142231231422542242211122346222242324322322334423414322223212522326521335224321212524
7553353156356515584343226346544565558264254226827567475462364576544228552423461321682755526346356484
4435442344132654633442424443432364554344232245252233532473441344443343345431445153243434444437364644
2222226455121242221225227222221122222241634222141233324322722222722232167222122222332125321322222263
7254834412454523224344289334292442522324374251784354254324565948424741878316233472532363245233452233
2214324482133242143233644434321222114444322184532346242314337742123222342425145131344125232313323453
3152212772331422223213222322221321122326312534326222232125322233225312722212222222324236322572953482
2222425315422422242133422233622424323442461342142434221224122223214222432231242332444233223513232422
2211227222222216222222321212223332212221252231231222222222312222222222312213222222123322113222324122
7532455271643676366357643744618286355632783547834275943358643936546449636336433675848332749465865965
2187346795965575617164778898445362464673262395435955562262826331265972347286947324355426636242496642
2322422242221222222212122122232221222221322432322121212222212232231111232322223222222223222323212212
2233122126528772261371837532333324342772239253233622326643713535363522234117223231374315133572652228
5665546456565433655524616154465355565856519531236454485345645653613435834436545555555725665566655465
2222222222122221222221222222122132122222213212223222222221213222332222122233212212122221322122222122
6454665342425535613452653343646233543337326322643654552363523466535954553423457655246663542346683234
2324333343126133232362221432343432363433323323322333533643313222335333323236333533343543333333332235
1324223213232113321221222222223231312433321122512231422123241222223122223222222122322332123223422222
3475645674676475778545676874855755774336685398586375377655764858454755766636767775677477876667676336
3222412222512322112313232322222584222231781222322222251222222442222121485233112322224334222425121242
3223223224542333335232322732357332331242263392763752451262272231351236222223132134562126334742427322
2542252222231522856625152142232223221212521122419222122325112212122222122222422222222217254223222262
4547537513254245344346234124455433474433372433242538444452445755331312425442434554315527443241422325
4445335445556244762835243646283335359378432443745564643552444353345434587147443333334365255367356454
3234643355933222333323333133333244252142323323332333124334323323333312634333353353333123343233225532
5528234277872276744672842355726235847489732777137777824367399396996478652456491298349416453921854337
1223322542132222223323132222122222233412132322334221223243213223223112233332322241421223211222331323
2322225222222122235232112221242222422127222222431224222232123541254252222257431244122152321712322221
7657456331563216562634654224322452566143465272217643337113211677757511536441571276777725366617123589
3812813224822442932432242733222322142425241922249236226112221247222242273323313223232594223222253279
3857567657498655647688677456315675545174335342575756956565566645779787645754698334355685458746426456
2746424442421333364244543322434374364434624542878275422541337522434764724222454754733222343251453452
4243222222223122232514242122223343244444243322434432414232624363241441311434322223422422442122224225
5422323334251453444454343442444434444433444444424434464355445636343364223233547334243565463223543353
4333444243432413544332351334434323124522324325342433143343154344343322334233342223224443354424444424
2234442134457543366242252433532452522242824343224231342327717322434444724512416452223223754324715727
8332268533222112243243252346613483242232224132353122842733522684235222222571235232232253127222262222
2321231223322333213363333272323232323332416222733212233222332212221222233243243231223322313323233413
3423422124542223133242222222221632213224222222112422643222332422322541212451123232222233123222222227
2323332222215222232223227232222342323223221423113232232232322732221322242222312213223323112322223222
2245715272513133322434335464322323333232754364273424241423222463424522223533112411739542122823433443
8294484637572964647574463598342154393863775265338396542534532354545669212856524784298281514656455646
1136232521161566663356511554543612421615256265466164316421666416414542446556624131632223534212255789
8253243324523333532224546353152554242525224253255824125264455332262523225422354333245722624625223832

10
inputs/day04_demo Normal file
View File

@ -0,0 +1,10 @@
..@@.@@@@.
@@@.@.@.@@
@@@@@.@.@@
@.@@@@..@.
@@.@@@@.@@
.@@@@@@@.@
.@.@.@.@@@
@.@@@.@@@@
.@@@@@@@@.
@.@.@@@.@.

138
inputs/day04_full Normal file
View File

@ -0,0 +1,138 @@
.@@@@.@@@@.....@@@@....@.@@.@@.@@.@@..@@.@.@@@@@@@@@.@@@@....@@.@@@@@......@@@@@@.....@.@@@@@.@@.@@.@@.@.@@@@@@@@.@@.@.@.@.@@.@@.@.@.@.@@.
@@@@.@@@@...@@@@.@...@....@@@@.@@.@.@@@@@@@.@...@@.@@.@@@@@.@@@@....@@@..@...@@@@.@@.@@@@..@.@.@@@@@@.@@...@@@@.@@.@@.@..@@@..@@@@@.@@@.@@
@...@.@.@.@..@@@.@...@@.@@..@.@...@@@@.@@@@@@@@@@@@@.@....@@@@@@...@@@@..@@@..@@...@.@@@@.@...@@@@@@@@@.@@@@@.@@@@@@@.@@@@@..@@@...@.@@@@@
@@.@@@@@@.@..@..@@@@@@@@@.@...@@@.@@.@.@@.@.@@@@.@.....@.@@@@@@.@.@..@@@@.@@@...@...@.@..@@..@.@..@.@.@@.@@@@.@..@@@@@..@@@@@.@..@@...@@@@
@.@@@@@.@@@@@@..@@.@@@@...@.@.@.@@@@.@@@@.@...@@@@@.@.@..@@@@@@.@.@@.@@@@.@@@@..@@@.@.@@.@.@.@...@..@..@@.....@@@@.@@@.@.@.@..@@@.@..@@@@@
@.@.@@@@.@..@..@@@@@.@.@.@@.@.@.@@@@..@.@@.@@@@@.@.@@@.@@.@..@@@@@@@@.@@....@@@.@.@@@.@@@.@@@...@@@@.@@@@....@@@@.@..@@@.@@@@.@@@@.@@@@@.@
@@..@@..@@@@@.@.@.@@@@@.@@@@@@@@@.@@.@@@@@@@@@@@@@@.....@@@@@@@@.......@@@@.@..@@@.@...@@@@@@@@.@@@@@.@@..@@.@@@@@.@.@@@@.@@....@@@@@.@.@@
.@.@@.@@@@@.@..@@@@@@@@@@.@@@@@@@@....@@..@@.@.@...@@.@@@@..@@@..@@@.@@@@@@..@@@@.@@@@@..@@....@.@@@@@.@@...@@@@@@.@@....@@@@@.@@@..@..@@.
.@@.@@.@....@@.@@@...@@@@@@..@@@@@..@@@..@..@..@@@.@@@..@@.@@@@@@@.@@@...@@@.@@..@.@@@@@.@@@@...@.@@@@@@.@@@@@...@..@@@@@..@.@@@@@@@...@..
@..@@@.@.@@@@@@@@@.@@@@@@..@@..@.@@@@@.@..@@@..@@@@.@.@...@.@@@@.@@..@@@@.@...@@@..@.@@@@.@@@@@@@.@.@@@@.@.@@@@@@@.@.@..@@..@@.@@.@@@@...@
@@.@@.@.@@.@.....@@@@.@@@@@....@@.@@@@.@.@.@@..@..@@@@@@@@.@@@.@@..@@@@@@@@@@@@@...@.@@@..@@.@@@....@@@...@@..@..@..@@....@.@@@@@@@@..@.@.
.@@@@@@@@@@.@@@@..@@@.@@@.@..@....@.@@@@@@@@..@@@@@@@@@@@.@.....@@@@..@@@..@@@@@..@.@@@@@@.@..@.@..@@.@.@@.@@@@@@@.@@@@@@...@@@@@.@@.@.@.@
.@.@@@..@@@....@..@.@@@.@@@@.@@@@@....@.@.@@@..@@..@.@@.@@.@@@.@.@.@@@@.@.@@@...@@.@@@...@.....@@@@@.@@@.@@@@.@@..@..@@.@@@.@@.@..@@@@@@@@
...@.@...@...@@@.@.@@.@.@@.@.@.....@.....@@@@@@.@@@.....@@@@.@@@@..@@..@@@@@@@@@@@@@..@@@@.@@@@.@..@@@@@@@..@@.@@@.@@@@@@@@@.@@..@@@@@@@.@
..@@@@@@@@@@..@@.@@@.@..@@@@@@@@@@...@@.@@.@@@@@@@@@@.@@.@.@@@@@@@.@.@..@@..@@@@@.@@.@@@@@@@@..@@@@@@.@@@@@@@@@@@.@.@@@@@.@@.@.@@@.@@.@...
.@@@.@@@.@.@@.@@@@@@@.@...@@@@.@@@.@@.@@..@..@@@@@@..@@.@@@.@.@@@@..@@@@@@@@@@@@.@@@@@.@@.@@@@@.@@@.@@@@@@@.@@@.@@@@@.@..@@.@@@.@@.@@@@@@@
.@@@@.@@@@@@@@@@@@@@...@@..@@.@@@.@@.@.@@@..@.@..@@@.@@@.@.@@@@@@@@@.@@@@.@..@@..@@@@@@@@.@..@@@....@.@@@@@@@.@.@@.@@..@@@@.@@@..@@.@@@.@@
...@@@@@...@@@@@@.@...@@.@@@@@..@@@@@@@.@@@@@@@@@@...@@@.@..@..@@@..@@@@@..@@@..@@@@.@@@@@@@@@.@.@@@.@@@.@@@@......@@@.@..@@.@.@..@@..@...
@@@.@@@.@@@@..@@.@..@.@@.@@@.@@@@@@@@@.@@.@@@.@@@@@@@@.@..@@@.@@@@.@@@..@@.@@@.@@.@..@@@@@.@.@.@.@@@..@@..@@...@..@@..@@@@@.@@@@@.@@@@..@@
@@@.@...@@.@@@.@@@@.@@@@@...@.@@.@.@@@@.@@@@.@@@..@@.@.@.@@@@.@@.@@..@@@@..@@@.@@@.@.@@@@.@.@@@.@@@@@@@@.@..@.@@@@.@@.@.@@@.@...@@@@@.@@@@
@.@@@.@.@.@@@@@@...@@@.@@@@@.@@@@@@@@..@@@@@@@@@@@@@@.@@.@@.@@@.@@@.@..@@@@.@...@@.@@@@@....@@.@.@@.@@@@@@...@@..@@@.@@.@@.@.@@@@..@..@@@.
.@@.@@...@@@.@@@@.@@@.@@@@@@@@@.@.@.@...@@...@@@@@@@@@@@@@@@@@@@.@..@.@@@..@..@@@..@@@@@.@@@@@@.@@@.@@@.@.@.......@@.@@....@@@@@@@.@@.@@.@
@.@.@@.@@@@.@@.@@@.@@..@@@@.@@.@.@@....@@@.@@.@@.@@..@@@.@@.@.@@.@.@@@@.@@@.@@@.@@@.@@.@@...@.@@@@@..@.@@@@@.@@.@.@..@@@@@@.@...@.@@@@...@
.@@@.@@@@@.@@@.@...@.@@@@@.@..@.@@@@@@@@@@@.@@@@@@@@@@.@.@@.@@@@.@@@@@..@@..@@.@@@@@.@@..@@@@@@@@...@@..@.@@@@.@@@.@.@@..@..@@.@@@..@@@@@.
.@.@@..@@.@.@...@@@.@@@@@@@@@....@.@@.....@@@...@@@@@@.@@.@....@@.@.@.@@@@@.@......@.@@@@@.@@@@.@@@@.@.@@@@@@@.@@.@@@@@@@..@@@@@@@.@@.@.@.
@@@.@@@.@@.@@@@.@@@@@..@@@.@.@@.@@@@@@@.@@@@@@.@@@@@.@@@@.@@...@@@.@@.@@@@.@@@@...@@@.@.@@@@@@.@@@@@@@@@@@@@.@@@@@@@...@@@@@@.@@@.@@.@@.@@
.@.@.@.@@@..@@.@@.@.@@@@@.@.@@@@.@..@@..@@@@.@@@@@..@.@.@@@@....@@...@.@@@@@..@@@.@.@@@@@..@.@.@@...@.@.@.@..@.@..@@@@@@@@@.@@@..@@@@@@@@@
@@@@@@@.@..@@@.@@@@@@.@@.@..@@@@@@@.@@.@.@@@.@@@....@@@@.@.@@@@@@..@.@@@.@.@.@@@@@@@@@@.@.@..@.@@@.@.@.@.@@..@.@.@@@@@@@@@.@@@@@@@.@@.@..@
@@@@..@...@@@@.@@@...@@@@@@@@@@@@.@@@.@.@@@@@..@@..@@@@.@...@@.@@@@.@..@....@@@@.@@...@..@..@@@@@@@...@.@@.@@@.@@.@.@.@@@@@.@@.@..@.@.@..@
..@.@.@@@..@..@@@@@@@@@.@@.@@@@@@@@@..@@@@@@@.@@@.......@.@.@@@.@@@@@@@@@@.@@..@@.@.@@.@.@.@@..@@.@@.@@@..@@.@@@@.@@@.@@@@@@@.....@...@.@@
@..@@..@..@@@.@@..@@@@@@.@@@@..@@@@.@@...@@@.@@@..@@@..@.@.@.@@@@@@@..@..@@@@@@@@@@@.@@@@....@@@..@.@@.@.@@@@.@@@@....@@.@.@@..@.@.@@@@.@@
.@.@..@..@@@@@@..@@@@@@@.@@@@@@@.@..@.@@@.@.@@.@..@@@@@.@.@@@@@@.....@.@@..@@@@.@.@@@@@@@@@@.@@@..@@@@@.@...@@@@@@@.@.@...@@@@@@@@.@@.@..@
@@@@.@@@@@.@@@.@.....@..@@..@@@@@@@@.@@......@...@@.@..@@@@.@.@@.@.@@@@.@@@...@@@.@@..@@...@@..@..@@@@.@@@@@@@@.@@@...@@@@@@@@.@..@@@..@@@
@.@..@.@.@@@.@..@@.@@@..@@@.@@....@.@@@@@..@.@.@....@@@.@@@..@..@@@@@@..@.@.@..@@.@..@@@.@@@@@@@@@@...@@@@@.@@.@@.@@@@@@@@@@.@..@@@@@@@..@
@@.@@.@@@.@@@.@@.@..@@@..@@.@@@@.@.@.@@@@@@.@@@@@@@@@......@.@@@.@.@@.@@@@.@@@....@@@.@@.@@..@@@..@.@@@@@@.@@@..@@@@@@@..@..@@@@..@@.@.@.@
.@@..@..@.@@@.@@@@@.@...@@@@@@@@.@...@@.@@@.@.@@@@.@@@@@.@@@@@@....@.@@@@@@@@@@@@..@@@@.@@@.@@.@.@@...@@.@.@...@@.@...@@@..@.@@.@.@@.@@@@@
@.@@.@@@@@@@@@@@@@@@@.@@.@@.@.@@..@@.@.@.@.@@@..@@@@@.@@@@..@@.@@@@@@@@@.@@@.@@@@@.@@@@@@.@@@@@@@.@@@@.@@@@@@@@..@@@@..@.@..@.@@.@@@@....@
@@.@.@.@@@@..@@@@@....@@@@@@@.@@@@.@@.@@@.@.@@.@@@..@@.@@@@.@..@.@@@@..@@@.@..@@@@@@..@.@@...@.@@.@.@.@@@@.@@.@@@.@....@...@.@@..@...@@.@@
@...@.@@.@@@@.@.@.@@.@@@..@@.@@.@@@...@....@@@.@@.@@.@.@@@@..@@@.@.@@@...@@@@@.@.@@.@..@@@...@@.@@.@@.@@@@.@..@@@.@.@.@@@@@@@@@.@@@@.@@@@.
@@@@@@.@@.@@@..@.@@@@@@..@@@.@@@.@@....@..@.@@.@@@@@@@@@@@@@@...@@@.@.@@@.@..@@.@..@@@@.@@@..@@@@..@.@@@@@..@.@@@@@@.@..@@@...@@@@@@.@@@@.
.@.@@@.@@.@@@@@.@@@@@@.@@@@@..@@.@.@@@..@..@@..@..@.@..@@..@..@@@.@@..@@@@.@@.....@@@@.@.@.@@.@@.@@@@.@@@@....@@.@@.@..@@.@.@.@.@@@@.@@@@.
.@@.@@@.@@@@@..@@@.@..@@.@@@@@....@@@@@@.@@@@@@@@@@.@@....@.@.@.@@@.@...@.@@.@@@@@@@.@@@@.@@@@@@@.@@.@@@.@..@@@@@.@.@..@.@..@@.@.@@.@@.@@.
....@.@@..@.@@..@@.@.@..@.@.@@.@@..@@..@@@..@..@.@.@@.@@@@..@.@@@@@....@@..@@.@.@@..@@....@@.@@..@..@......@@@..@@@@...@@@@@.@@@@@@@@@@@@.
@@@.@@@@.@@@.@@@@@@@.@.@@@..@@.@.@@@.@@.@@@...@@@@@@@..@.@@..@@.@...@@.@..@@@..@@.@@@..@@@@@@@@.@@@@@@..@@@@@.@@@@@@@@@@@....@@@@@@@@@@@@@
@..@@@@.@.@.@@@@@@.@.@@@.@@.@.@@@@@..@@.@@.@@@..@@@.@@@..@..@@..@...@...@@@.@.@..@..@@@..@@.@@@.@@@@@@@@@@.@@@@..@@..@..@.@@@@@@@.@@..@.@@
@@.@.@.@.@.@@@@.....@@.@@@@@@@@@..@.....@..@.@@.@.@.@.@.@@...@@@@@@@@...@....@.@@.@@@@.@@@.@@@@.@@@.@@@@@@@@...@@.@.@@@@@@@@@.@@@@@@.@.@@@
..@@@.@@@@.@.@@@.@@@.@@@.@@.@..@@@.@@@.@@..@..@@@@@.@@.@@@.@@@@@@@.@@@.@@@@@.@.@@@@@.@@.@.@@@.@.@@@@.@@@@.@@@@@...@@@@@@@.....@@@..@@.@@.@
.@@...@.@@@@.@@@@..@@@.@..@@@@@...@@.@@@.@.@@.@@@.@@@@@@.@.@@...@@@....@@.@@@@@@.@@@@.@@@..@@@@@.@@.@@.@..@@@@.@@@...@@..@@@@@@.@@@@@.@@@@
@@@@@@@@@.@.@.@.@......@...@@@@..@..@@..@.@@@.@@@@.@.@@@..@@@...@@@@@...@..@@.@@.@@@@@@.@@..@@.@@.@@@.@.@@.@..@.@.@@.@...@@@@.@@@@@@@@@@@@
@@.@@@.@@@@@.@@@...@.@@..@@@@@.@..@.@@..@@.@@.@@@.@@@@..@.@.@@@@@.@@.@@@@.@@@@.@.@@@@.@.@@@...@@@@.@.@@.@..@@@@@..@@@.@@@..@@@.@@.@@..@.@@
.@.@.@.@@@..@.@@@.@@.@@..@@@...@.@...@.@@..@..@.@@@.@@@.@@@@@@.@@@@@@@.@.@.@@.@@@.@@..@@...@@@@@@.@@@@.@..@@@...@@.@@@@@@..@@.@@@@.@@@@...
@@.@@@@@@@.@@@.@@.@@@...@.@@.@.@@@@@@@@@@.@...@@.@.@@@@@@@@.@@@@@.@.@@@@@@...@@......@@@..@@@@@@.@@@@@@@@@@.@...@.@@@@...@@@@.@@.@@@.@.@@@
@@@.@.@@.@@@@@@..@@@@@@.@...@....@@.@@@@@@@@@.@@@@@@@@..@..@@@@@@.@@@@@..@.@@.@.@@@.@@@@@@.@...@@..@..@@@..@@@.@....@@@@.@.@.@@@@@@@@.@@@@
@@@.@@@@@@.@@.@@..@@.@.@.@@@@@.@.@@@@.@@.@.@@@@@.@..@@@.@@@@@@@@.@@..@@@.@@@@@@@@.@@...@.@@@@@@@@@@@@@@@@.@@.@.@@@.@...@@@...@..@.@.@@@@.@
@.@...@@@.@@@@..@@..@@..@.@@@@..@.@.....@@..@.@@@@.@.@@@@@@@.@@.@.@@@...@.@@@@@.@@@..@@.@@@@@..@@@.@.@@.@@.@@@@@@@@@@@..@.@.@@.@@@.@.@@@.@
@@@@@@@..@@.@@.@..@@@...@.@.@@@@..@@@@@@.@..@.@.@@@@@..@@@@..@@@.@@@@@@.@@@@.@.@@@..@@@.@@.@@.@@@@@.@.@@.@.@@@@@.@@@@@@..@@@@@@@..@@@.@@@.
...@@@@@.@@@..@@..@@@@.@.@@@.....@@@@@@.@@@.@@.@@@@.@@...@@@.@@...@.@@@.@@@@@...@.@@@..@.@@.@@@@@@@@@....@.@@@.@@@.@@@@@@..@...@@@.@..@@.@
@..@@@.@@@@.@.@@@@.@.@@@...@@@@@..@@..@@..@@@.@@.@@@@.@@..@@@@@@@@@@@@@.@.@@@.@@..@@...@@@@@.@@.@@.@@@@@@@@@..@@@.@@.@@.@..@@@@@@.@@@@.@@@
@@@@@..@@..@@..@...@@@.@..@@@@@.@@....@@@@@@.@.@@@@@@@.@.@..@..@@@@@@@@.@@@@.....@@@@.@@@@@@@@@.@.....@@@@@@..@.@@@@@@@@@@.@@@@@@......@@@
@.@.@@@....@.@@@@@.@...@.@.@@@@.@@@..@@..@..@@@@@@@@@@@@@@.@.@@.@@@@.@@@@..@@@@.@@@.@@@@..@@@@..@@@..@@@...@..@.@@@@@@@@@@..@@@@@@@@..@@@.
@@....@@@.@@..@.@@.@..@@@.@.@..@@@.@@.@@.@@@@@@@@@@@@@.@@@.@.@.@@@@....@@.@@@.@@...@.@@@@@..@...@....@@@@@@@.@@..@@...@.@@.@@@.@.@@@.@.@.@
..@@@.@.@@@@.@.@@....@@...@@.@@@.@.@@.@.@@@@.@.@...@@@@@.@@.@@@@@.@@@@@@..@@.@@@@@@.@..@.@@.@@.@..@@@@@@@@@.@..@.@@.@@..@@@@@...@@@@@@.@.@
@@.@.@.@@.@@@.@@.@@@@@@.@.@..@.@@@.@@.@..@@@..@@@@@@@.@..@@@@..@@@.@@@.@@.@@@..@....@@@@@@@@@.@@@@@..@.@@@.@..@@@@@...@@@@.@..@.@.@.@...@@
..@@@@.@@@.@.@@..@.@@@@@.@@.@@@@.@@.@.@.@@@.@@.@..@@@@....@@.@@.@@.@.@.@@@@@...@@.@@@@@@@@@@@@@@@.@.@@@.@@.@..@..@@@@..@.@@..@@.@.@@..@@@@
@.@@@@@@.@@.@.@...@..@@..@@...@..@@@.@@@@@.@@@.@....@@@@..@@.@@@@@..@@..@@.@@@...@@.@@@@.@@.@.@.@@@@@@@@@@@.@@@@.@@@@.@..@.@@@@.@@.@.@@@@@
@@@@@.@.@.@@@@@@@@@@@@.@...@@@@@@@@@.@.@.@@@@@@.@.@...@@.@..@.@@@@@.@@.@@@@@.@@@.@@.@@@@@..@@@.@...@@@@..@@.@@.@@@@@@@@@@@@..@..@@.@@@@.@@
@@@@@.@@.@.@@@...@@.@@@@@@..@@@..@@@.@@.@@@.@@@@@.@@@@@...@..@@@@@@@@@@..@@@@.@@...@..@@@..@@@@@@@.@@@.@@..@.@@@@@@@@@..@@@@.@@.@@@@.@@.@.
@@@@@@@@@@@@@.@@@@@.@@@@@@@@@..@@@@@.@@.@@@@@@.@@@@@.@@.@.@.@@@@@.@@@@.@.@@.@@...@.@@@@.@@@@@.@@@@@.@@@@..@@@@@@@@@@@@@@.@..@...@.@@@@.@.@
@...@@@.@..@@@@.@@@@@...@@..@@..@@@@.@.@@..@@@@@@.@@.@@@.@..@@..@@@.@@.@@@@@.@..@.@@.............@@@.@.@@@..@@@@@@@@.@@...@.@@@.@.@@@@@@@.
.@@..@@@..@@.@..@@@@.@@.@...@..@@@@@@@.@@@@.@@@@@.@....@@@@@.@.@..@@.@.@@@..@...@.@@@@@@@.@@@.@..@@.@.@..@.@@..@@.@@@@@.@.@@.@@@@.@.@@@@@.
..@@@@@@.@.@.@.@@.@..@@@.@..@@@.@@@@..@@@@....@@@.@.@@@@@..@.@@@.@.@.@....@@.@...@.@@@@@@.@@@.@.@.@@@.@.@.@@@.@.@@@..@@@@@@@@..@@.....@@@@
.@@.@.@...@@@@@@@...@@@@@@@.@..@@.@@@@.@@@.@@@@...@.@@@@@@@@@...@@@@.@.@@..@@.@@@@@@.....@@@....@.@.@@@@.@@...@...@@@@@.@@.@@@@@.@.@@..@..
@@.@@@@@.@...@@.@@.@@..@.@@@@...@.@.@@.@@@@.@@.@....@@@.@@@@..@.@@..@@.@.@@.@.@@@@.@@..@@.@@@@@@@@@.@.@.@@.@@...@.@.@..@@@@@.@.@@..@@@.@.@
.@..@@...@.@@@@....@.@@@@@@@.@.@@@.@.@@.@@.@..@@@@@@.@@.@@.@.@.@@@@@@@@@..@@@@@@.@.@@.@@@@@.@@.@.@.@@@@@@@..@...@@.@@..@..@@@..@@@@@@@.@@.
.@...@@@@.@@..@...@..@.@@@@@@@@.@@@...@@.@@@@@@@.@@.@.@.@@@@@@@@@.@.@@@..@@.@.@..@.@@@@@.@@@@.@@@.@.@.@@@...@.@..@..@....@@.@@@.@...@.@..@
@...@@..@.@.@@@@..@.@.@@@..@@@.@@@@@..@@.@@@.@.@@..@@@@@.@@@@@@..@@...@@.@@@.@@@@@.@@..@@.@@@@@@@@@@.@@.@@@@@.@.@..@.@@@@.....@@@@@@@.@@@@
@.@@@.@..@@@@.@@.@@@@@@.@.@@@@@@.@..@@.@@@@@@@.@..@.@.@@@@@@..@@@.@.@..@@.@@@@.@@@@@@@@@@@...@....@..@..@.@....@@.@@@@@@@.@@@.@@@@@@.@.@@@
@.@..@@..@@..@....@@.@.@@.@..@@..@@@..@@@.@@.@@@@.@.@@.@.@@@@@@@@@@@.@@@@@@.@@@@@@@..@@.@.@@@@@@@@.....@.@@@.@@@@.@.@.@@..@@@@@.@.@..@@.@@
@@@@@@@.@@@@..@.@@@@@@.@.@.@@@@@.@.@@@@.@@@.@@@@@@@@@@@@@@.@@.@@@@@@@@@...@.@..@@@......@@@.@@@.@@@.@@..@@.@@@@..@.@.@@@.@@.@@..@@@@.@@.@.
.....@@@@...@@..@@.@@.@@@@.@@.@@@@.@@.@@@@@@@..@..@@@@@.@@@@@@@..@@.@@..@.@@@.@..@.@.@@@@@@@...@@@..@@@.@.@.@@..@.@.@@@.@....@.@@@@@...@@@
@..@@@@@.@.@.@@@@@.@@@@@.@@@.@@....@@.@@@@@@@.@.@@@...@@@@@@.@.@@@@.@@@.@@@..@@@@@.@@@@@.@@.@@@@@@@@@@@@@@@@.@@.@@@@.@@@...@@@@@.@@..@.@@.
.@@.@@.@.@@@@.@.@.@@@@@@@@@@@.@.......@@.@@..@@@@..@@.@@.@@.@@@.@@.@@.@@.@.@@.@..@@@.@.@@.@@@.@@.@@@@.@.@@@@@@..@@@@.@.@..@.@...@@@@@...@.
@@@.@.@@@@@@@@@@.@@@...@@@.@@@@...@@@@.@@@.@.@.@@@@@@@@@@....@.@..@.@.@@@@@..@@..@@.@@@@@@..@@.@.@@.@..@@@.@@@@.@@@@.@@@@@@@@@...@@.@@@.@.
@@@@.@@@@@@@.@@@@@@@@@@..@.@@..@@@..@.@@@@.@.@@@@@@..@.@@...@.@@@.@@..@.@..@@...@....@@.@.@@@@@..@@.@@@...@.@@@@@@@@..@@@@@@@@@...@..@..@@
@@@@.@.@@.@@@@.@@@@@.@@.@@@.@@@.@@@..@@..@@@.@@@.@@.@.@@@@.@@.@@.@..@@@@@.@@@@@@@@@@...@@@.@@.@...@.@@@....@@@@...@..@..@@....@.@.@@...@.@
@@..@.@@@@..@@@..@@.@@.@.@@@@...@@.@@.@.@@@.@@@....@@@@@.@@@@.@.@@..@@..@.@..@@@@@..@@.@@.@@@@@@@...@@.@@@..@.@@@.@.@@@@.@@..@@@@.@@@.@.@.
@@.@....@@@@@@@@@@@@@@...@@@.@@@@@@@@.@@.@@.@.@....@@.@.@@@@..@@@@..@@@@@@.@.@@@.@@@..@@@@@@@..@@@@.@@.@@.@...@.@@..@@@..@@@.@.@@@@..@@@@.
@....@.@@@.@.@@.@.@.@@@@....@@@...@@..@.@...@@@@..@@@.@@@@.@@@@@@.@.@@@@@.@@..@@@@@.@@@@...@@@@..@@@@@@@@@.@@@@@@@..@@.@@@@.@@@...@@@@@@.@
@@@@@@@@@@@..@@.@@@@.@@.@@.@@@.@@@.@@@...@@@@.@@..@@@@@@@.@@...@@@@@@.@@@@....@.@@@@@@.@@.@@@@.@.@..@@@@@..@@.@@...@@@@@@@.@.@@..@.@@.@@@.
@@.@@.@@@.@.@@.@..@.@.@@@@@@.@@@.@.@@@.@@@.@@@@..@.....@@@@.@.@@.@..@...@..@@.@@.@@.@@@@@.@..@.@@@@@.@@@..@.@@@.@@@@@@..@.@@@.@@.@@@@.@@@.
@@@@@@@.@@.@@@@.@@@@.@@@@@@@.@@...@@@@.@.@@..@@@@@.@.@@..@@@.@@@..@@@...@@@@..@@@@@...@@@@@.@@@..@.@@@@@@@@.@@.@@@@@.@@@.@@@.@@@...@@.@@.@
@@@..@.@@@.@...@..@@..@@@@@@.@@@@@@@@@.@.@@.@@....@.@@..@..@@@@@@@@@@.@@@@@@@@@.@@@.@..@.@@.@@@.@.@....@@....@@@@.@@.@@.@.@@.@@....@..@@@.
@@@@@@@@@@@@@@.@@@@.@...@.@..@@@.@@@..@@..@@@@@@@@.@..@.@@@..@@..@@..@@.@.@@@.@@@@@@@...@..@@.@@@.@@@@@@.@@@@.@.@@@@..@@@@.@@@..@@.@@@@..@
@.@@@@@@@.@@@@..@.@@@........@@@@@.@@@@@@@@@@.@@@.@..@@@.@@..@@@@@.@..@.@.@..@@....@.@@.@.@..@...@@@.@@@.@.@.@..@.@@@@@@.@@@..@@.@.@@.@.@@
@@@@@@@@@@.@@..@.@@@@@@@@@@.@.@@@.@@....@@@@@@..@@@@@@..@@@..@.@@..@@.@..@.@@.@@.@@..@@@@@@@@@.@@@@.@@@@..@.@@@.@.@.@@.@@@@@@@@@@@.@.@@.@.
@@@@@@@@.@@@@@@@@@.@@@@@@@@@.@..@@@@@@@@@.@@@.@@@@@.@@@@.@@.@@..@.@@@@@@.@@.@@@.@@@@@.@..@@@@..@@@..@@@@@@@@@.@@.@@@.@.@..@@..@@@@@.@.@..@
@@@@..@.@@..@.@@.@@.@.@@@@@@@@@@@@@@@@@@@@@@.@@@@@.@@@@@@.@@.@@@@..@.@@@@@@.@@..@@..@..@@@@@@.@.@@@.@@@@@@.@..@@@@.@@@@@@@@@@@@@@@@@@.@@@@
@..@.@@@@@@..@@..@@.@@@@@...@@.@@...@@@..@@.@@..@@@@@@@@@@.@@@@@@.@@@.@@.@@@.@@@@..@.@@@.@.@.@@.@.@@@..@@@@@@@..@@@.@@@@@..@@@@@@@@.@.....
..@...@@.@...@...@@.@@...@@.@@@@@.@@@@.@.@@.@...@@.@@..@@@@@@.@@@@.@@..@.@@@.@@@@.@@@@@@.@.@..@@@..@@.@.@.@@@@@.@@@@@@@.@.@@@@@@@@.@@.@..@
..@@@@@@@@@@@@@.@@.@@@...@@@@@@@@@@@@@@@@@@.@.@@@@@@@@@@@@@..@@@@@..@@.@@..@....@.@.@..@.@@@@@.@..@.@@@@@@@@..@@@@@@.@@....@@@..@@@@@.@@@@
.@@@@..@@@@@@....@@@@@@@@.@@..@.@.@.@@.@@.@@@.@@@..@..@@@.@.@@@@.@..@@.@.@@@@.@.@.@.@.@@.@@.@@@@@@.@@@..@.@@..@@@.@...@.@.@@@@@@@@@.@@.@@@
@@@...@.@@@@@@.@@@@..@.@@@@@@@@@@@.@@@@.@.@@.@.@@@@@@.@.@@.@@...@@..@.@@@@@@@@@@@.@.@@@.@.@..@@@..@@@.@@@@.@@.@..@.@@@.@.@....@..@.@@@@@@.
.@.@@@@@@.@@@@@@@@@.@@@@..@.@.@...@.@@@@@@.@@.@@@@@@@..@@@@@@..@.@@@.@.@.@..@@...@@@@@@@@.@.@@@.@.@@@.@..@@@.@@..@.@..@...@.@@@@@@@..@@@@.
..@.@..@@@.@@@@@..@.@@@@@@.@.@@@@@@....@.@@.@..@@..@@@@@@..@@@.@.@@@@.@@.......@@@@@...@..@@...@.@@..@.@.@.@@@.@@.@@@...@@@@.@.@.@.@@@@.@.
.@@.@@.@...@..@...@..@.@@.@@.@@@@@@.@@.@.@..@@@@@@@@@@@@@@..@@@@@@.@@@@...@@@@..@.@@@@@.@@@@.@@@@.@@....@@.@..@.@@..@@....@@.@@@@@@@.@..@@
@.@@..@@@.@.@@@@@.@@@@@..@@@.@@@@@@.@.@.@@.@@@......@@@.@..@@@.@@@@@@@@@@@.@.@@@@@@@.@@.@.@...@@...@..@@@@@.@..@@@@@@.@.@@@@@.@....@..@.@.
@@.@@@@.@@@.@@..@@@@@.@..@@.@@@@@@.@.@..@.@@@@@.@@.@.@@..@@@..@..@@.@@@..@@@.@@@..@@..@@......@@@.@@.@@.@@@@@@@..@@@.@@@@@@@@.@.@@@@.@@@@@
.@.@@@@@@...@.@..@@...@@@@@.@..@.@..@@@@@@@@@@.@@@@@@.@@@@.@@.@@.@....@@.@@@@@.@@..@@..@@@.@@@.@@@..@.@.@@@@@@.@@@..@@@@.@.@@.@.@@.@@@.@.@
@@@@@...@@..@.@@@..@@.@@@@@@.@@@@@@.@@@..@@@.@@@@.@@@.@.@.@@@@@@.@@@..@@@.@@.@@@@....@.@.@@@@@@@.@.@@@@@.@@@@@@@....@@@....@..@@@..@@.@@@@
@@.@@@@@@.@..@.@.@.@@...@..@@@@@@@.@@.@@@@..@@...@@..@....@@@..@.@@....@@@@@.@@@@@.@.@@.@..@..@@@@@@@@@@@@..@@@...@..@..@@@..@@.@@@@@@@.@.
.@@..@@@.@.@.@@@@.@...@@@@.@@@@@@.@.@@@@@@@@..@.@@@@@.@@.@@@.@@...@@...@@@.@@@@@@.@@@@@.@..@@@@@@@@@..@.@@..@.@.@..@@..@@@@...@@@..@@@@@@@
@...@...@@@@.@@@@.@.@@@@@.@@.@@..@@@.@.@..@@.@..@@@@@@@..@@..@@@@@@.@..@..@@@@@@@.@.@.@..@@@@@..@@@.@@@..@.@.@@@@@@@@@@.@@.@..@@@@@@@@@...
...@@.@@@@.@@.....@@@.@@@@@@@..@...@....@...@@.@@@@@@.@..@.@@.@..@.@......@@@@...@@@.@..@@@@.@@..@.@@@.@@....@@..@...@.@@..@@@..@@@@@@@.@.
@@.@@@@@@@@@@.@@..@..@@@@.@@@@@@.@..@@@.@@.@..@@@.@@@@..@.@@.@.@@@@@@@..@.@@@@@.@@.@.@.@@@.@.@..@@@..@@.@@@@@@@@@@@@..@@.@.@@..@..@@.@@.@.
@@@.@@@.@@@@@.@.@@@@@@..@@@@@@@...@..@@@@...@.@.@.@@.@..@@@.@@@..@@@@..@@.@@@@@@...@@.@.@@@@@...@@...@@@..@@@.@@@@@@.@@@@@@...@@@@@@.@.@.@
...@...@@@@@..@@.@.@.@@....@@@@@.@@@@@@..@@@@@.@.@.@@@...@..@@.@..@@@@@@..@@@.@@.@@.@.@@..@@@@@@.@..@@..@.@@.@..@@@@..@@@@@@@@@@@.@.@@@@.@
@@.@@@@@@.@@.@@@.@@@....@.@.@@@.@@@.@.@@@@@.@@..@.@@@@.@@@.@.@@.@..@....@@@@@@.@@.@@@@@@@.@@@.@@@@@.@.@@@.@@@.@@@@@..@@.@@@..@@@.@@@@.@...
@@.@@@.@@..@..@.@@.@.@...@.@@.@@@@@@@@@@.@.@@@.@.@..@@@....@@@@@@..@@..@@.@@.@@@@@@.@@@@@@@@.@@..@.@@@..@.@@@@.@@.@...@@@.@@@@@.@.@@@@.@@@
...@@@..@@@..@@.@@.@@@@@@..@@@@@@.@...@@@@.@@@@@@@@.@.@@@@@@@@@.@@@.@@@..@@@.@.@@@@@.@@.@@@@.@@@@@@@@.@.@.@@@...@.......@.@@.@...@@@@@@...
@@@@@@@...@.@@..@....@@@@@..@@@@.@.@@@@@..@@@@..@.@.@@@.@..@.@...@@.@..@@@.@@@.@@@.@@@@@.@.@@@@.@.@..@@.@@..@..@.@@@@@@.@...@.@@@..@@@.@@@
@.@.@@..@@.@@@@@@@@@@@..@@@.@@@..@..@@@@@@@@..@.@@@@@@@@@@.@@.@.@@..@@@.@....@@@.@..@.@@@@@.@.@@@@.@@@@@@@@.@@.@.@@.@.@.@.@@..@@@@@@@.@@..
.@@@@.@.@.@@@..@@@@...@@..@@.@@@@@...@@@@..@.@@@@@..@@.@@...@@@@..@@.@@@@@@.@.@.@@@@@@@@.@..@@@.@@@@.@.@.@@@@@@.@.@@@.@@@.@@@.@@.@@@@@@.@.
..@...@@@..@@@..@@@@@@@@..@.@@@@@..@@....@.@.@@@@@@@@.@@@..@....@@@@@@@@.@@.@..@.@@@..@.@@@.@@@@.@@@....@@@.@@.@.@@@@@.@.@@..@@@@@@..@@@@@
@@@@@@@@@..@@@..@@@@.@.@@@@@@@@@@@@@@@.@@.@..@.@..@@.@...@@@.@@@@.@..@@.@@@@.@@@@..@..@@.@@@@@@@@..@@@@@.@@..@@..@.@@@@.@@@@..@@.@..@@.@@@
@@.@@@@@.@@@@@@@@@.@.@.@.@.@@@@.@@@..@@.@@@@@@.@.@@@@@@@@@@@@@.@@@@.@@@@@.@@@.@@@.@.@@...@@@@.@@@@@.@.@@.@@@@.@@.@..@@@@...@@..@@@@@...@@@
@...@.@.@@@@.@.@..@@@@@.@..@@@.@..@.@.@@.@@@@@@@.@@.@@@@.@@@@@@@@.@@.@.@.@@@@.@@@..@@@@@@.@.@@.@.@@@@.@@.@@@.......@.@@@@@@.@@@.@.@..@@@@.
@@..@@.@@.@@@@..@..@@@@.@@..@@@.@.@.@@@@@@@@....@@.@.@@.@@.@@@.@@.@@@@@.@.@@@.@@@@@.@.@@@@@@@.@@@@@@@.@@@.@.@@.@.@@@.@@@.@.@@@@@@.@.....@@
@@@.@@@.@.@.@..@@@.@@@@@....@@.@@@..@@@@@@@.@@@@..@@@@.@.@.@.@.@@@@..@@.@@...@@...@.@.@.@....@@..@@@@@@@@@@@@@.@@.@@....@@@.@@@@.@...@..@@
..@@@@....@.@@.@.@.@@@@..@....@@@@@@@@@@.@@.@@@@@..@.@@@...@@@@@@..@..@@@@@@.@@@..@@@@@@.@.@@..@@@@@@@@@@.@@@.@@@@.@@@.@...@...@...@.@@@@.
@..@.@.@.@@.@@.@.@.@@...@@...@...@@@..@@@@@..@@@@@@@@.@@.@@@@.@..@@@..@..@@@@@..@..@@@..@@@.@..@.@@.@@@...@@@..@@.@..@..@@.@@@@@@@@@@@@.@@
@..@.@@.@@...@@@@@@@@.@..@@@..@@.@@@..@@@@@.@@@@@.@.@@@@@@@@@..@@.@..@@..@@.@@....@.@.@@.@.@@@@@...@.@..@@@.@...@.@.@@@@.@@.@@.@.@@@@@@.@@
.@.@..@...@@.@@...@..@@.@.@@@.@.@.@@.@@@.@.@@@@.@@...@@..@..@@@.@@@.@@@@@.@.@.@@@.@.@.@@@@@@..@@...@.@.@@.@@@.@@@@@..@.@.@.@@@.@.@.@@.@@@@
@@...@.@.@..@@@@..@..@@...@.@@@.....@.@@.@@@@@@@@@@@@.@@.@.@@@@@@@..@.@@@@@.@@.@@@@@.@@@.@@.@@@.@@@@@@@.@@@.@@@@..@.@@.@@@.@@@@@@@@@@@@.@@
@..@..@@.@@@@@.@@..@.@@.@@..@@.@@@@@.@..@@@@@@@.@@...@@@@@@.@.@.@@@...@.@.@..@@@..@@@@@.@...@.@.@.....@.@@.@..@@.@@@.@@..@@.@@.@@..@..@...
.@@.@.@@@@@@@@@@.@..@@@.@@@@....@@.@@@@@@@.@@.@.@@@@@@@.@..@.@@@@@@@...@@@...@@@...@@@@@@@@...@@@@.....@@@@@@@..@...@@.@@@@@@@@@@@..@@.@@@
..@@@@..@@@@...@@..@@@@@@@.@..@@@@@@@@@@@.....@@...@.@.@@@@.......@.@@@.@.@@@@@@@@@@.@@@@@@@@.@@.@..@.@.@@@.@@.@@@@.@.@@@@@@@@.....@@@@@.@
.....@@@...@@@.@@@@@.@@..@.@@...@...@.@@@@....@@..@@@@@.......@@...@.@@@..@@@@@.@@.@@@@@@@.@@@@@..@@@@..@@@@@@.@.@@@.@@@.@@@@@@..@@.@@@@@.
.@@.@@@@.@.@@.@@@@@@@..@@.@.@.@@@@.@.@@..@.@..@.@@@..@.@@@@@@@@@.......@@@@@..@.@.@@@@@@@@@@@@@..@@.@.@@@@@.@@.@@@@@@.@...@@.@@@.@.@.@..@@

11
inputs/day05_demo Normal file
View File

@ -0,0 +1,11 @@
3-5
10-14
16-20
12-18
1
5
8
11
17
32

1188
inputs/day05_full Normal file

File diff suppressed because it is too large Load Diff

4
inputs/day06_demo Normal file
View File

@ -0,0 +1,4 @@
123 328 51 64
45 64 387 23
6 98 215 314
* + * +

5
inputs/day06_full Normal file
View File

@ -0,0 +1,5 @@
52 812 541 56 25 2 1 59 428 262 15 65 9 8 361 77 923 69 38 92 49 245 375 1231 3 226 67 843 997 949 2514 45 57 73 941 92 466 5259 91 47 57 648 4653 326 38 74 297 33 59 57 2848 3 58 15 95 357 62 95 35 75 886 465 436 74 47 4 22 2 292 9 77 69 9621 8 59 396 36 52 96 53 168 44 58 675 46 3 823 44 519 97 4842 8 68 859 8 52 7 9 53 133 854 92 826 5 6 62 8 25 218 14 772 889 82 88 44 3 57 1691 69 93 77 7 5552 62 699 444 98 8 42 225 7952 7 484 648 2 49 36 97 66 731 24 118 34 29 19 72 4915 11 9743 5 9932 519 37 7 333 534 937 8 159 799 299 176 5 677 45 219 4 58 9 77 9152 124 75 278 29 47 551 31 5 722 2 538 21 23 899 16 2 5 183 26 51 27 88 68 76 894 83 95 11 9 38 366 25 83 432 349 833 31 24 5 3951 228 37 15 536 5 435 36 3463 468 411 84 761 16 984 91 26 45 9598 1 6 1944 986 61 1 4286 46 17 63 74 255 342 38 7 171 7 848 85 9198 11 4983 417 3562 42 46 39 72 4 9 8 19 97 769 1668 43 8 3 11 89 3 831 16 3 91 47 3 553 293 452 384 86 28 77 28 14 6 566 774 8 61 4 9 118 641 51 9 85 28 8833 64 41 5529 13 1164 71 938 8 88 426 979 354 9 888 363 7 8 23 81 82 1384 571 43 965 3 1 6359 117 9 559 76 9 289 818 64 677 133 212 247 8578 655 11 59 69 88 455 293 16 66 931 825 39 473 88 88 618 55 6 2 856 5419 87 9 12 985 233 97 4 8194 1623 8 29 41 7 9 11 38 58 13 253 4453 6837 5 897 12 56 6334 397 59 962 72 11 83 561 9 9515 6694 6927 3277 3386 5 347 35 75 7 95 49 89 3 5478 3 18 61 5374 75 96 24 9919 72 82 817 978 38 1 262 631 79 1468 51 7 27 269 94 7959 979 865 521 886 98 2 379 775 125 9379 757 49 23 6856 1 621 21 83 11 24 61 84 351 3743 94 72 446 41 368 911 56 491 9 57 242 7 39 761 89 9487 89 281 8959 32 58 23 922 848 593 945 68 3642 71 84 68 145 38 3 2568 731 64 54 9 96 386 59 914 112 5 398 21 464 9 994 712 916 189 183 166 6 4 247 14 96 49 72 6146 46 45 39 689 133 85 438 64 79 99 226 9 4291 56 86 7 876 364 6262 4 34 4222 438 1 2 2 148 8735 6 99 28 1 43 83 4 6 68 492 51 24 16 519 18 48 51 5 25 6 56 72 997 7179 449 4831 22 728 3169 31 12 4 146 1878 32 72 938 61 926 25 32 883 761 15 45 797 46 5 6516 39 1 3 162 89 51 49 2 836 233 55 56 155 51 522 6 772 15 14 173 638 6 56 8 84 389 4 858 35 7 5827 629 56 268 75 55 419 4 78 8251 27 7256 94 35 575 9267 1 31 4 726 8 47 9 622 41 811 32 796 457 583 263 33 599 142 7253 75 115 37 8221 7 6 77 92 498 56 4 6 1 19 5 7 968 56 68 57 82 324 73 459 2 6 575 2661 93 895 49 59 7551 22 37 6 372 2 545 335 75 299 32 4 2 8 75 245 437 548 19 3551 21 7 9 36 639 79 21 21 27 5 49 35 94 8965 546 78 837 458 37 94 18 94 6 2 1 19 467 91 2 3 82 6892 58 552 25 865 369 98 6 2847 78 61 43 7763 445 364 7 75 9165 541 222 5 29 38 55 6543 285 233 7 21 85 43 62 22 25 8 538 9 6 58 4527 4 893 4 3 129 9 654 115 7 278 195 27 32 8 8379 2462 7 9 17 41 1998 74 788 425 53 52 516 87 893 7348 95 815 84 66 16 44 46 892 89 85 81 418 52 959 86 67 13 85 377 4 4 62 3191 8997 396 841 67 17 2816 44 8 913 23 79 37 66 52 563 16 781 9691 713 2425 44 78 71 875 2185 1 16 794 381 2 5 73 68 46 17 7 6277 1 28 528 51 97 86 49 5769 398 1519 98 451 284 4637 39 9 573 65 81 72 66 1 59 89 23 826 556 867 897 41 136 593 6848 16 67 4 16 83 349 9 47 367 8 64 499 651 3 646 718 49 38 19 7 999 89 735 92 5 28 52 9 1267 29 712 124 16 55 611 65 3 76 54 12 41 96 27 1 7 3 176 91 2 88 86 144 774 7 6 65 1 29 3 9899 741 6794 51 1 94 99 32 49 14 4 25 415 41 22 73 1 8 73 7 31 12 686 26 67 282 1382 22 7 53 9422 15 82
48 554 421 92 25 218 3 28 284 551 99 35 19 83 651 741 756 22 71 78 2 6349 786 6665 3 839 11 916 541 16 1155 399 39 15 591 6 691 4615 97 117 26 775 2513 662 47 88 852 33 39 39 8144 19 67 47 82 994 13 74 35 8 94 945 724 39 48 8 345 451 173 6189 7 52 6845 28 12 477 87 22 74 59 373 346 87 95 68 43 77 41 8595 98 1426 556 75 5171 7 75 4 64 979 823 229 43 328 2 55 53 69 259 195 15 511 465 78 61 25 36 11 761 541 32 617 3 3387 777 175 697 8 35 42 273 9418 8589 345 379 8 25 63 82 69 794 5498 652 584 22 18 46 89 87 4725 385 371 318 86 78 469 188 242 8 762 742 493 324 9 288 74 594 26 86 9 34 199 681 28 662 81 611 562 13 43 925 5 119 18 38 755 65 81 7 171 92 689 23 14 2 19 373 116 588 74 74 72 557 65 71 94 766 317 38 28 4 3112 8296 39 76 836 1 664 76 8766 239 985 38 16 863 462 12 73 75 1898 163 36 7159 413 89 3 6882 11 3 36 18 93 281 43 31 296 334 946 19 1463 263 6261 659 7894 795 88 64 543 52 89 9 38 93 928 132 51 151 464 34 18 17 25 69 741 38 83 44 948 918 3522 68 35 77 58 67 56 2 418 146 7 54 4969 23 734 592 26 29 79 72 173 228 46 7434 35 9367 15 926 335 94 918 153 529 43 7493 74 9 5684 17 981 72 398 279 55 179 968 56 2529 931 76 335 38 745 18 455 289 723 359 492 917 2489 543 23 89 27 5 897 871 619 54 627 441 16 628 113 91 929 49 48 52 384 2364 34 5118 817 758 624 748 96 242 123 6 71 88 49 88 51 84 2893 41 731 8743 955 738 562 978 53 6552 43 593 858 98 39 21 278 71 8319 7773 1958 2137 4383 9 2967 52 99 914 97 16 75 1 7998 9 66 24 521 19 663 93 2448 24 37 311 834 25 5 254 836 85 1259 815 43 94 559 555 4445 8121 114 54 842 83 74 187 441 623 1195 648 436 82 6841 656 832 76 579 27 49 75 56 262 1677 4266 55 937 264 262 813 85 626 79 892 791 9 99 566 12 2796 55 321 3771 41 67 66 721 22 878 924 23 2897 998 35 861 315 7 25 3427 223 34 699 61 73 318 54 591 343 81 529 367 81 9 978 153 867 935 345 85 16 53 731 24 32 66 23 4162 84 96 61 434 473 365 582 27 778 73 424 1 4235 927 91 2 214 635 3642 53 55 929 462 47 92 73 387 6564 92 65 41 7 44 26 41 16 533 396 2 89 715 846 21 71 24 6 37 71 76 69 754 1274 467 2296 24 666 1149 53 241 93 54 7729 74 13 88 19 954 68 89 929 744 12 55 98 22 18 768 65 98 38 429 2827 87 19 3 864 422 99 77 391 16 591 895 975 69 15 244 999 3 353 55 87 361 54 251 67 3 2182 352 33 989 397 72 919 4 5121 2897 54 5213 57 14 297 2253 19 8 97 44 2 15 34 964 43 996 35 841 545 189 142 98 468 843 7286 95 89 84 776 63 14 92 65 5 38 8 738 312 75 8 17 12 25 45 62 85 611 686 958 387 58 4925 5413 45 715 13 35 9429 47 49 76 436 11 7973 853 162 862 2 683 281 47 55 435 832 99 46 9595 97 42 241 77 333 22 83 41 81 79 23 72 11 6954 142 649 36 446 42 832 22 368 545 2 34 85 352 81 21 2 34 2849 21 951 53 999 336 64 59 7917 68 96 35 6595 172 529 37 52 1311 328 468 16 13 34 18 4555 47 322 6 27 97 842 34 48 339 2 247 79 6 46 2977 15 981 9 8 328 84 337 425 462 43 626 21 6922 3 2419 1929 81 1 43 97 3336 561 657 886 34 6297 281 22 145 8615 69 953 972 14 145 93 341 742 488 31 58 719 38 592 783 59 41 75 474 7 7 45 8171 5124 126 237 15 92 2774 36 72 132 895 4 19 66 16 134 38 476 342 632 4663 31 26 36 48 2433 6789 42 416 833 76 45 74 69 37 31 69 464 47 63 633 45 21 26 63 759 999 567 45 5121 172 3429 77 9 869 85 55 32 28 59 35 1732 3958 75 852 272 6172 17 667 798 8247 553 4 1 13 66 85 95 56 334 9 23 485 364 37 437 182 29 95 1 4 431 53 194 2885 231 685 36 72 2669 89 864 889 75 98 676 6 7 7 63 88 66 52 74 917 8 17 818 15 98 73 25 469 436 4 86 245 3 93 1 8174 929 1199 21 58 999 85 495 33 26 51 13 78 45 624 61 18 266 65 94 94 57 697 257 42 496 494 23 683 52 1279 98 93
92 731 86 68 93 553 92 26 183 5 84 73 891 23 931 1229 916 32 87 99 9 3115 984 3253 4 949 35 876 3 83 379 772 84 495 216 8 315 9756 66 481 7 221 84 725 22 15 664 9144 22 69 769 95 74 88 87 267 57 26 13 1 87 84 96 7 48 4 539 762 55 3277 8 166 838 83 3 896 58 82 84 999 387 726 5 72 14 79 65 27 2197 2232 877 143 17 1252 54 11 18 71 2368 638 71 98 17 789 998 39 74 919 442 48 4892 669 22 26 77 12 44 43 3778 455 3231 962 789 857 736 3 6 13 77 3 571 6245 395 691 44 293 75 25 65 552 2697 93 216 343 31 87 4 72 856 741 28 32 726 26 257 57 482 5 67 55 3 849 26 719 3 8555 88 87 85 27 317 454 67 1638 25 932 934 84 883 6214 2 343 28 995 865 68 46 61 949 84 9676 74 15 4 13 839 876 8889 73 966 26 753 197 383 31 35 273 97 132 33 762 5884 45 44 713 25 285 74 13 949 753 685 1 972 24 59 74 22 8314 823 15 6592 616 99 89 9648 24 5 24 53 56 278 7 42 684 737 976 1 7142 388 1417 163 9121 748 26 632 878 21 64 3 83 8 23 271 34 113 456 788 15 14 79 569 522 388 14 633 121 47 5879 21 76 24 84 2 73 79 692 164 1 22 7595 3648 56 597 586 747 63 41 3 7913 67 946 2 715 31 2 881 78 1819 281 83 573 3712 43 175 6883 18 421 7 385 1696 11 63 751 291 678 252 24 577 24 9239 81 576 8121 244 566 184 94 299 617 68 91 56 1 89 516 781 72 739 729 27 621 375 6 278 61 98 61 69 45 28 6453 773 856 676 8229 97 669 91 5 2 97 77 341 78 65 8266 39 795 638 669 861 664 1795 62 233 85 416 648 25 95 62 92 55 275 1359 2266 69 6966 84 3862 63 67 145 84 95 38 3 4522 58 94 128 426 59 137 27 4274 98 79 835 382 96 97 776 224 218 211 646 99 84 17 991 6427 2844 885 85 943 47 73 664 566 76 41 291 161 267 6939 521 23 28 654 15 54 22 57 69 162 9855 49 724 547 676 52 65 725 3854 685 516 79 4 2149 39 816 29 85 7792 61 49 37 262 27 229 29 97 8549 175 21 535 142 9 551 7116 256 26 715 92 289 527 99 733 46 98 87 643 24 374 77 9 747 199 814 71 33 43 6 23 93 19 41 2173 57 96 75 675 271 123 724 49 747 43 692 42 4813 689 15 46 942 332 3154 92 11 231 332 2584 52 21 169 8328 77 44 51 37 27 87 79 988 5772 521 6 86 615 239 386 67 936 29 4 766 25 8 94 824 334 6189 81 524 317 73 447 826 4 514 43 65 7 28 46 97 91 347 944 51 97 49 3 269 458 29 85 85 795 7934 1 7579 28 179 42 47 54 816 39 43 327 211 41 69 94 511 35 523 167 4 626 84 912 615 53 6498 68 27 397 6422 51 872 99 8549 4267 26 4289 84 45 14 4535 65 8 17 73 71 29 929 469 2 515 43 942 354 496 813 17 624 317 261 4 51 1 834 98 857 44 73 1 42 365 481 267 49 44 389 93 98 35 13 46 982 284 74 462 163 4253 135 5 153 13 67 1897 99 852 56 324 36 5232 232 243 885 5 116 886 647 54 33 554 64 97 524 63 499 533 71 772 37 18 25 3 24 15 44 12 1388 8 384 23 91 54 715 69 939 361 762 12 558 677 12 96 31 75 5841 81 15 67 4 222 2 434 379 13 528 11 446 11 68 932 29 2891 734 55 13 42 37 35 7967 78 1313 12 37 756 946 59 3 345 8 396 65 93 61 238 37 994 3 1 23 691 139 3315 496 35 12 27 5249 47 142 99 689 773 86 15 953 2481 345 432 2 7471 135 174 149 3796 934 133 876 37 456 59 162 367 369 72 91 116 478 667 889 81 642 65 49 21 3518 75 865 4772 294 996 12 73 1743 8 45 671 973 3 14 45 76 547 4 24 28 872 4274 29 18 21 35 5928 7542 26 8675 4843 98 59 97 24 67 46 23 57 72 882 347 23 8 89 68 242 92 759 648 4638 5163 147 226 4 34 87 78 22 25 68 367 5128 8895 29 667 115 2296 41 999 77 127 9192 2 27 71 37 35 24 15 477 7 59 53 213 54 751 739 58 72 2 49 632 92 156 4541 532 381 99 99 919 8 634 592 97 6 437 2 26 3 86 76 74 79 75 5178 62 18 23 2 43 38 6911 684 29 71 62 4492 57 9 67 6969 113 411 53 44 522 12 415 2 657 54 71 6 41 4928 98 793 511 8 759 83 47 7 411 347 61 69 22 8942 14 92 7 5
39 972 8 52 3 435 86 772 56 1 185 78 797 13 549 9795 42 52 7 2 4 6327 61 7893 24 41 8 33 3 26 54 514 61 963 9138 7 27 513 3 846 4 395 36 998 656 74 934 1623 29 4 68 93 32 38 19 84 87 4 7 2 37 7 4 2 69 88 167 315 44 6447 3 579 27 91 4 326 8 28 17 716 4811 183 5 4 3 86 83 57 9953 3378 31 574 6 2969 19 48 32 49 1719 95 98 35 7 448 837 52 31 534 765 37 7474 587 1 65 21 36 2 7 6599 572 8491 483 97 233 26 4 3 72 67 4 71 3364 917 1 57 711 58 9 11 917 1299 75 219 185 656 64 8 83 191 693 77 9 614 27 433 76 17 78 89 35 3 58 134 991 8 9523 67 52 11 75 24 985 1 8242 9 822 767 39 511 5663 26 416 25 981 797 78 35 77 54 36 7128 14 3 1 98 57 9915 2521 77 143 43 69 622 462 7 3 641 52 969 25 13 9258 88 29 259 51 45 55 1 141 5 587 2 199 1 78 1 55 2353 682 99 75 142 67 45 8 95 6 49 56 4 612 8 82 2 661 441 9 541 347 9281 2 643 564 48 476 575 11 22 28 58 1 38 21 87 629 123 443 167 25 6 931 716 161 96 316 578 25 1384 9 12 8 61 6 27 27 983 135 78 45 8385 2625 9 27 436 871 677 5 7 4131 52 7 3 3 32 2 493 23 2611 226 81 616 4966 59 138 1959 84 138 4 777 1426 9 17 536 874 36 32 65 95 9 6657 79 61 6668 611 54 445 47 363 927 76 32 2 3 6 658 639 86 36 35 16 36 623 1 9 36 91 77 43 34 31 8875 588 731 471 3135 661 31 12 72 4 92 48 471 2 92 2257 43 59 831 392 241 82 4316 8 93 12 221 39 44 52 81 85 532 495 8811 3426 98 1677 75 2982 39 774 727 17 15 69 96 1358 14 3 813 671 1 7278 42 5989 16 92 397 532 1 54 16 31 658 26 321 66 83 2 818 9471 3764 758 65 952 67 22 158 479 35 4 18 299 969 58 284 4 25 723 39 433 12 99 3 6 3438 3 2 947 658 7 78 25 9661 411 62 83 7 6668 42 17 24 3 334 54 67 8 57 79 876 55 45 79 315 76 622 133 7 217 841 91 55 553 28 757 135 12 64 9 77 9 544 7 951 12 8 5 295 2 4 36 168 3 2 2 5 55 127 23 3 67 919 615 469 138 13 473 64 947 62 6681 858 996 54 889 76 78 21 26 38 759 1412 44 69 764 3379 96 19 8 14 425 69 95 315 5533 39 4 38 482 924 487 54 633 48 2 967 22 1 81 778 9 386 1 52 95 5 867 111 3 412 56 44 6 8 49 1 27 92 446 84 43 2 7 548 69 64 99 17 462 7645 8 3431 48 162 8 24 43 94 75 16 517 455 8 46 7 216 61 254 229 2 67 21 328 119 49 924 7 87 666 4536 54 26 42 5333 7838 15 7 27 99 51 4484 28 8 36 4 62 6 165 71 7 9 29 22 259 312 833 97 9 21 414 2 1 5 16 51 122 81 785 2 3 731 527 662 83 14 982 8 3 21 69 94 945 237 29 492 656 2453 222 6 64 72 86 859 39 447 36 987 66 7431 5 948 83 7 676 864 921 88 8 713 96 67 33 55 423 599 3 426 4 82 8 4 71 9 9 4 348 2 132 3 5 51 796 346 131 651 473 55 5171 58 44 48 11 48 89 2 18 32 2 337 7 943 496 78 825 43 7 7 31 967 93 47 231 36 15 6 27 63 7 39 1898 44 7 214 351 1 4 649 54 8 871 48 19 27 91 14 82 67 64 918 732 7975 234 8 69 88 9658 97 6 61 711 292 13 875 6 6641 893 468 5 7845 985 898 976 3812 2238 15 737 3 8814 31 1886 6 923 36 2 458 661 811 597 62 473 5 3 62 8157 314 434 471 747 847 63 73 861 6 76 668 441 1 79 8 41 86 5 15 87 2 65 9 83 9 47 854 3569 11 6194 6352 62 19 23 5 28 2 94 63 96 863 24 14 4 28 27 27 24 191 854 8189 9176 624 572 68 4 78 1 35 46 97 757 9633 9169 5 122 33 3994 1 89 41 414 1437 4 35 63 92 5 12 7 151 37 16 73 83 91 93 8 98 66 9 58 78 6 892 7829 718 834 56 81 5 1 522 96 94 8 247 2 543 5 68 93 72 27 91 9352 48 54 81 9 98 93 6319 12 5 33 18 6542 465 7 34 6157 429 6 85 82 674 32 311 7 356 45 13 2 31 8785 88 185 447 7 724 8 73 6 328 835 44 87 89 1495 194 7 6 6
+ + + * + + * * * * * * + * + + + * * * + + * + * + + + + + + + + * + * * + + + * * + * + * * + + * + + * + * * * + * * + * + * * + + * * + * * + * + * * * + + + * * + * + + * + + + * * + + * * + + * * * * + + * * + * + + * * * * * * + + * + + + + + * + * * + + + * * * * * + * * + * * + * * + * + + + * * + + * * * * * + + + + * + * + * * + + + + + * + * * + * * * + * + * * * + + + + * + + + + * * + + * * * + * + + + + + + * * + + + + * + + + * * * * * + * + + + * + + * + + + * * + + * + * + + * + * + * + * + + * * * + * + * * + + + * * * * * + * * * + * + * * * * * * * * * + + * * * * * + + + * + + + * * * * + * * * + * * + * * + + + * * * * + + + * * + * + + + * * + + * * * + + * + * * + + * * + * + * * * * + * + + * + + * + + * * + * * + * + * + + + * * + * + + * * * + + * * + + + + + * + + * * * + * * + + * * + + + * + * + + + + + * + * + * * + + * + + + + * + + * + + + * * * + + * + * * + * + + + + + * * + + * * + * * * + + * + + + + + + + + + + + + + * * * * + + + * * * * + * * * + * * * * * * * * * + * * + + * * * * + + + + * + + * * + * * * + + + + * * + * * + + + * + * + * * + * * * * * + * * * + * * * + * + * + * + + + + + + + * + * + + * + + * + * * + + * + * * * + * * * + + * + * * * * * * * * * * + * + * + * * * * + * * + + + * + + + + * + + * + + + * + + * * * + + * * + + * * + * * * * * + + + * + + + * + + + * * + + * + * * * * + * * + * * + + + + + * + * * * * * + * + + + * + + + * * * + + * * * * + + * * * * * * + + + + * * * * * * * + * + + * * * + + * * + + * * + + * + + + * * * * + * * * * * * + * + * * * * * * + + * + * * + + + + * + * + + * + * + + * + + * * + * + + * * * + + * * + + * + * + * + + + * * + * * + * + * * * + * + + * * * * + * * * + * * * + + * + + * + * * * + + + * + + * * + + + * * + * + * * + * * + * + + + + + * + + + + * * * * + + * * + + + + * + + * * * * * * + * + * + + + + + * + + * + + * + + * + + + + + * + * * + + + * * + + + + * * + + + + + * + + * + + * * + * + * + + * + * * + * + + + * * + * + * * + + + * + + + * + + +

638
rtcore.h Normal file
View File

@ -0,0 +1,638 @@
#ifndef RT_CORE_H
#define RT_CORE_H
/*
* rtcore.h - Simple base layer library for C
* Copyright (C) 2025 Kevin Trogant
*
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to deal
* in the Software without restriction, including without limitation the rights
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
* copies of the Software, and to permit persons to whom the Software is
* furnished to do so, subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included in
* all copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
* SOFTWARE.
*/
/* My base layer library.
* - fixed width types
* - arena allocator
* - utility macros
* - string type
* - simd header inclusion
* - threading wrapper
* - atomics
* - simple file io
*/
#include <inttypes.h>
#include <stddef.h>
#include <stdint.h>
#include <uchar.h>
#include <string.h>
#ifndef RTC_API
#ifdef __cplusplus
#define RTC_API extern "C"
#else
#define RTC_API extern
#endif
#endif
/* Nowadays, immintrin.h includes everything I tend to care about (simd)
* This assume x64, which is what I'm always using.
* You still need to build with the appropriate compilation
* flags (-march=avx2 etc. for gcc, /arch:AVX2 etc. for msvc) */
#include <immintrin.h>
/* MSVC additionally has intrin.h for microsoft specific intrinsics */
#ifdef _MSC_VER
#include <intrin.h>
#endif
/* Types */
typedef uint8_t u8;
typedef uint16_t u16;
typedef uint32_t u32;
typedef uint64_t u64;
typedef int8_t i8;
typedef int16_t i16;
typedef int32_t i32;
typedef int64_t i64;
typedef float f32;
typedef double f64;
typedef ptrdiff_t isize;
typedef size_t usize;
typedef char byte;
typedef char16_t c16;
typedef int32_t b32;
/* Utility macros */
#if defined(__GNUC__) || defined(__clang__)
#ifdef __has_builtin
#if __has_builtin(__builtin_expect)
#define likely(x) __builtin_expect(!!(x), 1)
#define unlikely(x) __builtin_expect(!!(x), 0)
#endif
#endif
#endif
#ifndef likely
#define likely(x) (x)
#define unlikely(x) (x)
#endif
#define internal static
#define global_variable static
#if defined(__GNUC__) || defined(__clang__)
#define exported __attribute__((visibility("default")))
#elif defined(_MSC_VER)
#define exported __dllexport
#endif
#define min(a, b) ((a) < (b) ? (a) : (b))
#define max(a, b) ((a) > (b) ? (a) : (b))
#define kilobytes(n) ((n) * 1024)
#define megabytes(n) ((n) * 1024 * 1024)
#define gigabytes(n) ((n) * 1024 * 1024 * 1024)
#define isizeof(x) (isize)sizeof(x)
/* number of elements in array a */
#define countof(a) (isize)(sizeof(a) / sizeof(*(a)))
/* number of characters in string constant s (exluding the terminating 0) */
#define lengthof(s) (countof(s) - 1)
#if defined(__GNUC__) || defined(__clang__)
#define assert(x) \
while (!(x)) \
{ \
__builtin_trap(); \
__builtin_unreachable(); \
}
#define force_inline inline __attribute__((always_inline))
#elif defined(_MSC_VER)
#define assert(x) \
if (!(x)) \
{ \
__debugbreak(); \
}
#define force_inline __forceinline
#endif
/* Arena allocator */
typedef struct arena
{
byte *begin;
byte *end;
} arena;
typedef struct arena_cp
{
byte *cp;
} arena_cp;
static force_inline arena_cp SaveArena(arena a)
{
return (arena_cp){a.begin};
}
static force_inline void RestoreArena(arena *a, arena_cp cp)
{
a->begin = cp.cp;
}
enum
{
/* Disables memory zeroing */
ALLOC_NOZERO = 0x1,
/* Allocation failure returns NULL instead of aborting */
ALLOC_SOFTFAIL = 0x2,
};
/* allocate objects from an arena.
* usage is one of:
* - a(a, t) - allocate one object of type t from arena a
* - alloc(a, t, n) - allocate n objects of type t from arena a
* - (a, t, n, f) - allocate n objects of type t from arena a using flags f
*/
#define alloc(...) allocx(__VA_ARGS__, alloc4, alloc3, alloc2)(__VA_ARGS__)
#define allocx(a, b, c, d, e, ...) e
#define alloc2(a, t) (t*)ArenaAlloc(a, isizeof(t), _Alignof(t), 1, 0)
#define alloc3(a, t, n) (t*)ArenaAlloc(a, isizeof(t), _Alignof(t), n, 0)
#define alloc4(a, t, n, f) (t*)ArenaAlloc(a, isizeof(t), _Alignof(t), n, f)
RTC_API void *ArenaAlloc(arena *a, isize size, isize align, isize n, int flags);
/* String type */
typedef struct s8
{
u8 *data;
isize length;
} s8;
#define S8(_s) \
(s8) { .data = (u8 *)_s, .length = lengthof(_s), }
typedef struct { s8 first; s8 second; } split_result;
/* constructs a string containing the bytes between begin and end (exclusive) */
RTC_API s8 S8Span(u8* begin, u8* end);
/* check if two strings are equal */
RTC_API b32 S8Equals(s8 a, s8 b);
/* compare two strings. analogue to strcmp */
RTC_API isize S8Compare(s8 a, s8 b);
/* compute a simple hash value for a string. */
RTC_API u64 S8Hash(s8 s);
/* returns s with leading and trailing whitespace removed.
* Treats all characters with a numerical value smaller and equal to 0x20 (space) as whitespace
* The new string shares memory with s */
RTC_API s8 S8Trim(s8 s);
/* returns s with leading whitespace removed.
* Treats all characters with a numerical value smaller and equal to 0x20 (space) as whitespace.
* The new string shares memory with s */
RTC_API s8 S8TrimLeft(s8 s);
/* returns s with trailing whitespace removed.
* Treats all characters with a numerical value smaller and equal to 0x20 (space) as whitespace.
* The new string shares memory with s */
RTC_API s8 S8TrimRight(s8 s);
/* Returns a pointer to the first occurence of character c (or NULL) */
RTC_API u8 *S8Chr(s8 s, u8 c);
/* Returns a pointer to the last valid character of s */
RTC_API u8 *S8End(s8 s);
/* Splits the given string s at the first occurence of c.
* If c does not occur, split_result.first contains the whole string */
RTC_API split_result S8Split(s8 s, u8 c);
/* Splits the given string s at the first occurence of c.
* If c does not occur, split_result.first contains the whole string.
* This version also consumes repeating occurences of c */
RTC_API split_result S8Split2(s8 s, u8 c);
/* Creates a clone of string s on arena a */
RTC_API s8 S8Clone(s8 s, arena *a);
typedef struct { i64 i; b32 ok; } s8_parse_i64_result;
typedef struct { i32 i; b32 ok; } s8_parse_i32_result;
/* Parses a integer from string s */
RTC_API s8_parse_i64_result S8ParseI64(s8 s, int base);
/* Parses an integer from string s */
RTC_API s8_parse_i32_result S8ParseI32(s8 s, int base);
/* Basic file io */
typedef struct file_buffer
{
byte *data;
isize length;
} file_buffer;
/* Loads the content of a file. */
RTC_API file_buffer ReadEntireFile(s8 path, arena *a);
/* Loads the content of a file into a s8 */
RTC_API s8 ReadEntireFileS8(s8 path, arena *a);
/* Write the given buffer to a file */
RTC_API b32 WriteEntireFile(s8 path, byte *data, isize length);
/* Atomics */
#if defined(__GNUC__) || defined(__clang__)
/* Atomic add */
#define AtomicAdd32(_addend, _val) __atomic_add_fetch((i32 *)_addend, _val, __ATOMIC_SEQ_CST)
#define AtomicAdd64(_addend, _val) __atomic_add_fetch((i64 *)_addend, _val, __ATOMIC_SEQ_CST)
#define AtomicStore(_ptr, _val) __atomic_store_n(_ptr, _val, __ATOMIC_SEQ_CST)
#define AtomicStoreRelease(_ptr, _val) __atomic_store_n(_ptr, _val, __ATOMIC_RELEASE)
#define AtomicLoad(_ptr) __atomic_load_n(_ptr, __ATOMIC_SEQ_CST)
#define AtomicLoadAcquire(_ptr) __atomic_load_n(_ptr, __ATOMIC_ACQUIRE)
#elif defined(_MSC_VER)
#define AtomicAdd32(_addend, _val) _InterlockedExchangeAdd((volatile long *)_addend, _val)
#define AtomicAdd64(_addend, _val) _InterlockedExchangeAdd64((volatile __int64 *)_addend, _val)
#define AtomicStore(_ptr, _val) _InterlockedExchange((volatile long *)_ptr, _val)
#define AtomicStoreRelease(_ptr, _val) _InterlockedExchange_HLERelease(_ptr, _val)
#define AtomicLoad(_ptr) _InterlockedOr(_ptr, 0)
#define AtomicLoadAcquire(_ptr) _InterlockedOr_HLEAcquire(_ptr, 0)
#endif
/* Aliases for intrinsics */
#if defined(__GNUC__) || defined(__clang__)
#define CTZ32(ui) __builtin_ctz(ui)
#define CTZ64(ul) __builtin_ctzl(ul)
#define CLZ32(ui) __builtin_clz(ui)
#define CLZ64(ul) __builtin_clzl(ul)
#define PopCount32(_x) __builtin_popcount(_x)
#define PopCount64(_x) __builtin_popcountl(_x)
#elif defined(_MSC_VER)
static force_inline unsigned int CTZ32(u32 x)
{
unsigned int index;
_BitScanReverse(&index, x);
return index;
}
static force_inline unsigned int CTZ64(u64 x)
{
unsigned int index;
_BitScanReverse64(&index, x);
return index;
}
static force_inline unsigned int CLZ32(u32 x)
{
unsigned int index;
_BitScanForward(&index, x);
return index;
}
static force_inline unsigned int CLZ64(u64 x)
{
unsigned int index;
_BitScanForward64(&index, x);
return index;
}
#define PopCount32(_x) __popcnt(_x)
#define PopCount64(_x) __popcnt64(_x)
#endif
/* Threading wrapper */
typedef struct thread thread;
/* Win32 uses DWORD as the return type, Linux uses void *.
* I don't think that I've ever used a threads return value... */
#ifdef _WIN32
#define THREAD_RETURN_TYPE u32
#elif defined(__linux__)
#define THREAD_RETURN_TYPE void *
#endif
/* Generates a thread entry point */
#define THREAD_FN(_name) THREAD_RETURN_TYPE _name(void *param)
typedef THREAD_FN(thread_fn);
/* Starts a new thread */
RTC_API thread *StartThread(thread_fn *fn, void *param);
/* Waits until a thread terminates, returns its return value. */
RTC_API THREAD_RETURN_TYPE JoinThread(thread *t);
#endif
#ifdef RT_CORE_IMPLEMENTATION
#undef RT_CORE_IMPLEMENTATION
#include <stdlib.h>
#include <stdio.h>
#ifdef __linux__
#include <pthread.h>
#elif defined(_WIN32)
#define WIN32_LEAN_AND_MEAN
#include <windows.h>
#endif
/* Alloc */
RTC_API void *
ArenaAlloc(arena *a, isize size, isize align, isize n, int flags)
{
isize padding = -(usize)a->begin & (align - 1);
isize available = (isize)(a->end - a->begin) - padding;
if (available < 0 || n > available / size)
{
if (!(flags & ALLOC_SOFTFAIL))
abort();
return NULL;
}
void *p = a->begin + padding;
a->begin += padding + n * size;
return (flags & ALLOC_NOZERO) ? p : memset(p, 0, n * size);
}
/* S8 funcs */
RTC_API s8
S8Span(u8* begin, u8* end)
{
s8 s = {0};
s.data = begin;
s.length = begin ? end - begin : 0;
return s;
}
RTC_API b32
S8Equals(s8 a, s8 b)
{
return a.length == b.length && (!a.length || (memcmp(a.data, b.data, a.length) == 0));
}
RTC_API isize
S8Compare(s8 a, s8 b)
{
isize n = min(a.length, b.length);
for (isize i = 0; i < n; ++i)
{
if (a.data[i] != b.data[i])
return (isize)a.data[i] - (isize)b.data[i];
}
return a.length - b.length;
}
RTC_API u64
S8Hash(s8 s)
{
u64 hash = 0xcbf29ce484222325;
for (isize i = 0; i < s.length; ++i)
hash = (hash ^ s.data[i]) * 0x00000100000001b3;
return hash;
}
RTC_API s8
S8Trim(s8 s)
{
for (; s.length && *s.data <= ' '; s.data++, s.length--)
{
}
for (; s.length && s.data[s.length - 1] <= ' '; s.length--)
{
}
return s;
}
RTC_API s8
S8TrimLeft(s8 s)
{
for (; s.length && *s.data <= ' '; s.data++, s.length--)
{
}
return s;
}
RTC_API s8
S8TrimRight(s8 s)
{
for (; s.length && s.data[s.length - 1] <= ' '; s.length--)
{
}
return s;
}
RTC_API u8 *
S8Chr(s8 s, u8 c)
{
for (isize i = 0; i < s.length; ++i)
{
if (s.data[i] == c)
return &s.data[i];
}
return NULL;
}
RTC_API u8 *
S8End(s8 s)
{
return &s.data[s.length - 1];
}
RTC_API split_result
S8Split(s8 s, u8 c)
{
u8 *chr = S8Chr(s, c);
if (!chr)
return (split_result){s};
return (split_result){
S8Span(s.data, chr),
S8Span(chr + 1, S8End(s) + 1),
};
}
RTC_API split_result
S8Split2(s8 s, u8 c)
{
u8 *chr = S8Chr(s, c);
if (!chr)
return (split_result){s};
split_result r = {
.first = S8Span(s.data, chr),
};
u8 *end = S8End(s) + 1;
while (chr != end && *chr == c)
++chr;
r.second = S8Span(chr, end);
return r;
}
RTC_API s8
S8Clone(s8 s, arena *a)
{
s8 c = {0};
c.data = alloc(a, u8, s.length);
c.length = s.length;
memcpy(c.data, s.data, s.length);
return s;
}
RTC_API s8_parse_i64_result
S8ParseI64(s8 s, int base)
{
isize at = s.length - 1;
i64 exp = 1;
i64 val = 0;
while (at >= 0)
{
u8 c = s.data[at];
int digit = 0;
if (c >= '0' && c <= '9')
digit = c - '0';
else if (c >= 'A' && c <= 'Z')
digit = c - 'A';
else if (c >= 'a' && c <= 'z')
digit = c - 'a';
else if (c == '-')
{
val *= -1;
break;
}
else if (c == '+')
{
break;
}
else
return (s8_parse_i64_result){0};
if (digit >= base)
return (s8_parse_i64_result){0};
val += digit * exp;
exp *= base;
--at;
}
return (s8_parse_i64_result){
.i = val,
.ok = 1,
};
}
RTC_API s8_parse_i32_result
S8ParseI32(s8 s, int base)
{
isize at = s.length - 1;
i32 exp = 1;
i32 val = 0;
while (at >= 0)
{
u8 c = s.data[at];
int digit = 0;
if (c >= '0' && c <= '9')
digit = c - '0';
else if (c >= 'A' && c <= 'Z')
digit = c - 'A';
else if (c >= 'a' && c <= 'z')
digit = c - 'a';
else if (c == '-')
{
val *= -1;
break;
}
else if (c == '+')
{
break;
}
else
return (s8_parse_i32_result){0};
if (digit >= base)
return (s8_parse_i32_result){0};
val += digit * exp;
exp *= base;
--at;
}
return (s8_parse_i32_result){
.i = val,
.ok = 1,
};
}
/* Basic file io */
RTC_API file_buffer
ReadEntireFile(s8 path, arena *a)
{
char _p[260];
if (path.length >= countof(_p))
return (file_buffer){0};
memcpy(_p, path.data, path.length);
_p[path.length] = '\0';
FILE *f = fopen(_p, "rb");
if (!f)
return (file_buffer){0};
size_t max = (size_t)(a->end - a->begin);
size_t num = fread(a->begin, 1, max, f);
if (ferror(f))
{
fclose(f);
return (file_buffer){0};
}
fclose(f);
file_buffer fbuf = {
.data = (byte *)a->begin,
.length = (isize)num,
};
a->begin += num;
return fbuf;
}
RTC_API s8
ReadEntireFileS8(s8 path, arena *a)
{
file_buffer fb = ReadEntireFile(path, a);
return (s8){
.data = (u8 *)fb.data,
.length = fb.length,
};
}
RTC_API b32
WriteEntireFile(s8 path, byte *data, isize length)
{
char _p[260];
if (path.length >= countof(_p))
return 0;
memcpy(_p, path.data, path.length);
_p[path.length] = '\0';
FILE *f = fopen(_p, "wb");
if (!f)
return 0;
size_t num = fwrite(data, (size_t)length, 1, f);
fclose(f);
return num == 1;
}
/* Threading */
#ifdef __linux__
RTC_API thread *
StartThread(thread_fn *fn, void *param)
{
pthread_t t;
if (pthread_create(&t, NULL, fn, param) != 0)
return NULL;
return (thread *)(usize)t;
}
RTC_API THREAD_RETURN_TYPE
JoinThread(thread *t)
{
void *ret = NULL;
pthread_join((pthread_t)(usize)t, &ret);
return ret;
}
#elif defined(_WIN32)
RTC_API thread *
StartThread(thread_fn *fn, void *param)
{
HANDLE h = CreateThread(
NULL,
0, /* Use default stack size */
(LPTHREAD_START_ROUTINE)fn,
param,
0,
NULL);
return (thread *)h;
}
RTC_API THREAD_RETURN_TYPE
JoinThread(thread *t)
{
HANDLE h = (HANDLE)t;
if (WaitForSingleObject(h, INFINITE) == WAIT_OBJECT_0)
{
DWORD exit;
GetExitCodeThread(h, &exit);
CloseHandle(h);
return exit;
}
return 0;
}
#endif
#endif