Compare commits
31 Commits
03eba3c219
...
master
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
1f855400aa | ||
|
|
1c22f73a2b | ||
|
|
23d9bd4106 | ||
|
|
6646cf557f | ||
|
|
4427590639 | ||
|
|
e8e253128f | ||
|
|
d07adb1b15 | ||
|
|
fe918ad8e3 | ||
|
|
8741d0d456 | ||
|
|
79b32b883b | ||
|
|
ece0243eb4 | ||
|
|
1c202ae46c | ||
|
|
28489fbe29 | ||
|
|
d94a6b3e60 | ||
|
|
7655698056 | ||
|
|
d462e9eea0 | ||
|
|
55ae7103b8 | ||
|
|
71727f812d | ||
|
|
14d18f6814 | ||
|
|
5a812be6f2 | ||
|
|
014936c782 | ||
|
|
0e3c31c0de | ||
|
|
c9a946c54d | ||
|
|
4f0e9d7c7c | ||
|
|
3335442a3f | ||
|
|
3410d1f611 | ||
|
|
7913dcea4a | ||
|
|
ada00b863b | ||
|
|
5329eb948c | ||
|
|
7e9d5e3fdd | ||
|
|
7850c50a55 |
BIN
day1/c/day1
Executable file
BIN
day1/c/day1
Executable file
Binary file not shown.
118
day1/c/day1.c
Normal file
118
day1/c/day1.c
Normal file
@@ -0,0 +1,118 @@
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
#include <string.h>
|
||||
|
||||
#define LINE_MAX_LENGTH 256
|
||||
#define NUM_0_CHARCODE 48
|
||||
#define NUM_9_CHARCODE NUM_0_CHARCODE + 9
|
||||
#define PART_2 1
|
||||
#define FORWARD 1
|
||||
#define BACKWARD -1
|
||||
|
||||
char* english_digit_strings[] = {
|
||||
"zero",
|
||||
"one",
|
||||
"two",
|
||||
"three",
|
||||
"four",
|
||||
"five",
|
||||
"six",
|
||||
"seven",
|
||||
"eight",
|
||||
"nine",
|
||||
};
|
||||
|
||||
#define NUM_OF_DIGITS ((sizeof(english_digit_strings)) / (sizeof(english_digit_strings[0])))
|
||||
|
||||
char *english_digit_strings_reversed[NUM_OF_DIGITS];
|
||||
|
||||
int get_num(char *p, int dir) {
|
||||
// Check whether it is a number
|
||||
if (*p >= NUM_0_CHARCODE && *p <= NUM_9_CHARCODE) {
|
||||
return *p - NUM_0_CHARCODE;
|
||||
}
|
||||
|
||||
// Check spelled out numbers
|
||||
if (PART_2) {
|
||||
// Check each digit
|
||||
for (int i = 0; i < NUM_OF_DIGITS; i++) {
|
||||
char *reference = dir == FORWARD ? english_digit_strings[i] : english_digit_strings_reversed[i];
|
||||
char *tmp = p;
|
||||
int match = 1;
|
||||
while (*reference != '\0') {
|
||||
if (*tmp != *reference) {
|
||||
match = 0;
|
||||
break;
|
||||
}
|
||||
reference++;
|
||||
tmp += dir;
|
||||
}
|
||||
|
||||
if (match) {
|
||||
return i;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return -1;
|
||||
}
|
||||
|
||||
char* reverse_string(char* str) {
|
||||
char *p = str;
|
||||
while (*p != '\0') p++;
|
||||
|
||||
int len = p - str;
|
||||
|
||||
char *newstr = (char *)malloc(len + 1);
|
||||
memset(newstr, 0, len + 1);
|
||||
p--;
|
||||
|
||||
|
||||
char* newp = newstr;
|
||||
while (p != str) {
|
||||
*newp = *p;
|
||||
newp++;
|
||||
p--;
|
||||
}
|
||||
*newp = *p;
|
||||
|
||||
return newstr;
|
||||
}
|
||||
|
||||
void create_reversed_digit_strings() {
|
||||
for (int i = 0; i < NUM_OF_DIGITS; i++) {
|
||||
english_digit_strings_reversed[i] = reverse_string(english_digit_strings[i]);
|
||||
}
|
||||
}
|
||||
|
||||
int main() {
|
||||
char *p, *buf, c;
|
||||
int sum = 0, n = -1;
|
||||
create_reversed_digit_strings();
|
||||
|
||||
buf = (char *)malloc(LINE_MAX_LENGTH);
|
||||
memset(buf, 0, LINE_MAX_LENGTH);
|
||||
p = buf;
|
||||
|
||||
while ((c = getchar()) != EOF) {
|
||||
*p++ = c;
|
||||
if (c == '\n') {
|
||||
// Find last number (p points to the end of line)
|
||||
while ((n = get_num(p, BACKWARD)) == -1) p--;
|
||||
sum += n;
|
||||
// Find first number
|
||||
p = buf;
|
||||
while ((n = get_num(p, FORWARD)) == -1) p++;
|
||||
sum += n * 10;
|
||||
|
||||
memset(buf, 0, LINE_MAX_LENGTH);
|
||||
p = buf;
|
||||
}
|
||||
}
|
||||
|
||||
free(buf);
|
||||
for (int i = 0; i < NUM_OF_DIGITS; i++) {
|
||||
free(english_digit_strings_reversed[i]);
|
||||
}
|
||||
printf("%i\n", sum);
|
||||
}
|
||||
1000
day1/input.txt
Normal file
1000
day1/input.txt
Normal file
File diff suppressed because it is too large
Load Diff
1
day1/rust/.gitignore
vendored
Normal file
1
day1/rust/.gitignore
vendored
Normal file
@@ -0,0 +1 @@
|
||||
target
|
||||
7
day1/rust/Cargo.lock
generated
Normal file
7
day1/rust/Cargo.lock
generated
Normal file
@@ -0,0 +1,7 @@
|
||||
# This file is automatically @generated by Cargo.
|
||||
# It is not intended for manual editing.
|
||||
version = 3
|
||||
|
||||
[[package]]
|
||||
name = "rust"
|
||||
version = "0.1.0"
|
||||
8
day1/rust/Cargo.toml
Normal file
8
day1/rust/Cargo.toml
Normal file
@@ -0,0 +1,8 @@
|
||||
[package]
|
||||
name = "rust"
|
||||
version = "0.1.0"
|
||||
edition = "2021"
|
||||
|
||||
# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html
|
||||
|
||||
[dependencies]
|
||||
44
day1/rust/src/main.rs
Normal file
44
day1/rust/src/main.rs
Normal file
@@ -0,0 +1,44 @@
|
||||
fn main() {
|
||||
let part2 = true;
|
||||
let english_digit_names = ["zero", "one", "two", "three", "four", "five", "six", "seven", "eight", "nine"];
|
||||
|
||||
|
||||
let stdin = std::io::stdin();
|
||||
let mut sum = 0;
|
||||
|
||||
for line in stdin.lines() {
|
||||
let line = line.unwrap();
|
||||
|
||||
let mut first: Option<u32> = None;
|
||||
let mut last = 0;
|
||||
for i in 0..line.chars().count() {
|
||||
let slice = &line[i..];
|
||||
|
||||
let first_char = slice.chars().next().unwrap();
|
||||
if first_char.is_digit(10) {
|
||||
if first == None {
|
||||
first = first_char.to_digit(10);
|
||||
}
|
||||
|
||||
last = first_char.to_digit(10).unwrap();
|
||||
}
|
||||
|
||||
if part2 {
|
||||
for (i, name) in english_digit_names.iter().enumerate() {
|
||||
if slice.starts_with(name) {
|
||||
if first == None {
|
||||
first = Some(i.try_into().unwrap());
|
||||
}
|
||||
|
||||
last = i.try_into().unwrap();
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
sum += first.unwrap() * 10;
|
||||
sum += last;
|
||||
}
|
||||
|
||||
println!("{}", sum);
|
||||
}
|
||||
4
day1/sample.txt
Normal file
4
day1/sample.txt
Normal file
@@ -0,0 +1,4 @@
|
||||
1abc2
|
||||
pqr3stu8vwx
|
||||
a1b2c3d4e5f
|
||||
treb7uchet
|
||||
7
day1/sample2.txt
Normal file
7
day1/sample2.txt
Normal file
@@ -0,0 +1,7 @@
|
||||
two1nine
|
||||
eightwothree
|
||||
abcone2threexyz
|
||||
xtwone3four
|
||||
4nineeightseven2
|
||||
zoneight234
|
||||
7pqrstsixteen
|
||||
BIN
day10/c/day10
Executable file
BIN
day10/c/day10
Executable file
Binary file not shown.
269
day10/c/day10.c
Normal file
269
day10/c/day10.c
Normal file
@@ -0,0 +1,269 @@
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
#include <string.h>
|
||||
|
||||
#define MAX_MAP_SIZE 256
|
||||
|
||||
typedef enum tile_type {
|
||||
GROUND,
|
||||
UP_DOWN,
|
||||
LEFT_RIGHT,
|
||||
UP_RIGHT,
|
||||
UP_LEFT,
|
||||
DOWN_LEFT,
|
||||
DOWN_RIGHT,
|
||||
START
|
||||
} tile_type_t;
|
||||
|
||||
typedef struct tile {
|
||||
tile_type_t type;
|
||||
struct tile *links[2];
|
||||
int part_of_loop;
|
||||
} tile_t;
|
||||
|
||||
int main() {
|
||||
char *p, *buf, c;
|
||||
|
||||
buf = (char *)malloc(MAX_MAP_SIZE);
|
||||
memset(buf, 0, MAX_MAP_SIZE);
|
||||
p = buf;
|
||||
|
||||
tile_t map[MAX_MAP_SIZE][MAX_MAP_SIZE];
|
||||
memset(map, 0, MAX_MAP_SIZE*MAX_MAP_SIZE*sizeof(tile_t));
|
||||
|
||||
int x = 0, y = 0;
|
||||
|
||||
while ((c = getchar()) != EOF) {
|
||||
*p++ = c;
|
||||
if (c == '\n') {
|
||||
x = 0;
|
||||
p = buf;
|
||||
while (*p != '\n') {
|
||||
switch (*p) {
|
||||
case '.':
|
||||
map[x][y].type = GROUND;
|
||||
break;
|
||||
case '|':
|
||||
map[x][y].type = UP_DOWN;
|
||||
// UP
|
||||
if (y != 0) {
|
||||
map[x][y].links[0] = &map[x][y-1];
|
||||
}
|
||||
// DOWN
|
||||
map[x][y].links[1] = &map[x][y+1];
|
||||
break;
|
||||
case '-':
|
||||
map[x][y].type = LEFT_RIGHT;
|
||||
// LEFT
|
||||
if (x != 0) {
|
||||
map[x][y].links[0] = &map[x-1][y];
|
||||
}
|
||||
// RIGHT
|
||||
map[x][y].links[1] = &map[x+1][y];
|
||||
break;
|
||||
case 'L':
|
||||
map[x][y].type = UP_RIGHT;
|
||||
// UP
|
||||
if (y != 0) {
|
||||
map[x][y].links[0] = &map[x][y-1];
|
||||
}
|
||||
// RIGHT
|
||||
map[x][y].links[1] = &map[x+1][y];
|
||||
break;
|
||||
case 'J':
|
||||
map[x][y].type = UP_LEFT;
|
||||
// UP
|
||||
if (y != 0) {
|
||||
map[x][y].links[0] = &map[x][y-1];
|
||||
}
|
||||
// LEFT
|
||||
if (x != 0) {
|
||||
map[x][y].links[1] = &map[x-1][y];
|
||||
}
|
||||
break;
|
||||
case '7':
|
||||
map[x][y].type = DOWN_LEFT;
|
||||
// DOWN
|
||||
map[x][y].links[0] = &map[x][y+1];
|
||||
// LEFT
|
||||
if (x != 0) {
|
||||
map[x][y].links[1] = &map[x-1][y];
|
||||
}
|
||||
break;
|
||||
case 'F':
|
||||
map[x][y].type = DOWN_RIGHT;
|
||||
// DOWN
|
||||
map[x][y].links[0] = &map[x][y+1];
|
||||
// RIGHT
|
||||
map[x][y].links[1] = &map[x+1][y];
|
||||
break;
|
||||
case 'S':
|
||||
map[x][y].type = START;
|
||||
break;
|
||||
}
|
||||
p++;
|
||||
x++;
|
||||
}
|
||||
|
||||
y++;
|
||||
memset(buf, 0, MAX_MAP_SIZE);
|
||||
p = buf;
|
||||
}
|
||||
}
|
||||
|
||||
// Find start
|
||||
tile_t *start, *curr, *prev;
|
||||
|
||||
int found = 0;
|
||||
for (int i = 0; i < y; i++) {
|
||||
for (int j = 0; j < x; j++) {
|
||||
if (map[j][i].type == START) {
|
||||
start = &map[j][i];
|
||||
curr = start;
|
||||
found = 1;
|
||||
int link_num = 0;
|
||||
// Connect up start tile
|
||||
// UP
|
||||
if (i != 0) {
|
||||
for (int k = 0; k < 2; k++) {
|
||||
if (map[j][i-1].links[k] == start) {
|
||||
start->links[link_num] = &map[j][i-1];
|
||||
link_num++;
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
// DOWN
|
||||
for (int k = 0; k < 2; k++) {
|
||||
if (map[j][i+1].links[k] == start) {
|
||||
start->links[link_num] = &map[j][i+1];
|
||||
link_num++;
|
||||
break;
|
||||
}
|
||||
}
|
||||
// LEFT
|
||||
if (j != 0) {
|
||||
for (int k = 0; k < 2; k++) {
|
||||
if (map[j-1][i].links[k] == start) {
|
||||
start->links[link_num] = &map[j-1][i];
|
||||
link_num++;
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
// RIGHT
|
||||
for (int k = 0; k < 2; k++) {
|
||||
if (map[j+1][i].links[k] == start) {
|
||||
start->links[link_num] = &map[j+1][i];
|
||||
link_num++;
|
||||
break;
|
||||
}
|
||||
}
|
||||
// Assign the correct type to the start tile, needed for part2
|
||||
if (start->links[0] == &map[j][i-1] && start->links[1] == &map[j][i+1]) {
|
||||
start->type = UP_DOWN;
|
||||
}
|
||||
if (start->links[0] == &map[j][i-1] && start->links[1] == &map[j+1][i]) {
|
||||
start->type = UP_RIGHT;
|
||||
}
|
||||
if (start->links[0] == &map[j][i-1] && start->links[1] == &map[j-1][i]) {
|
||||
start->type = UP_LEFT;
|
||||
}
|
||||
if (start->links[0] == &map[j-1][i] && start->links[1] == &map[j+1][i]) {
|
||||
start->type = LEFT_RIGHT;
|
||||
}
|
||||
if (start->links[0] == &map[j][i+1] && start->links[1] == &map[j-1][i]) {
|
||||
start->type = DOWN_LEFT;
|
||||
}
|
||||
if (start->links[0] == &map[j][i+1] && start->links[1] == &map[j+1][i]) {
|
||||
start->type = DOWN_RIGHT;
|
||||
}
|
||||
break;
|
||||
}
|
||||
}
|
||||
if (found) {
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
// Count to loop length
|
||||
unsigned long loop_length = 0;
|
||||
curr = start->links[0];
|
||||
prev = start;
|
||||
start->part_of_loop = 1;
|
||||
|
||||
while (curr != start) {
|
||||
curr->part_of_loop = 1;
|
||||
loop_length++;
|
||||
|
||||
for (int i = 0; i < 2; i++) {
|
||||
if (prev != curr->links[i]) {
|
||||
prev = curr;
|
||||
curr = curr->links[i];
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
unsigned long max_distance = loop_length % 2 ? loop_length / 2 + 1 : loop_length / 2;
|
||||
|
||||
printf("%lu\n", max_distance);
|
||||
|
||||
unsigned long inside_tile_count = 0;
|
||||
|
||||
for (int i = 0; i < y; i++) {
|
||||
for (int j = 0; j < x; j++) {
|
||||
if (map[j][i].part_of_loop) {
|
||||
continue;
|
||||
}
|
||||
|
||||
// Start going in a specific direction. (in this case right)
|
||||
// If we are inside the pipes we will cross the pipe an odd number of times
|
||||
int crosses = 0;
|
||||
// If we entered a pipe through F or L we have to keep track whether we cross the pipe when leaving
|
||||
int entry = 0;
|
||||
for (int k = 1; k < x - j; k++) {
|
||||
// We only care about pipes that are part of the loop
|
||||
if (!map[j+k][i].part_of_loop) {
|
||||
continue;
|
||||
}
|
||||
// If we are 'inside a pipe' we are no crossing it
|
||||
tile_type_t tile_type = map[j+k][i].type;
|
||||
if (tile_type == LEFT_RIGHT) {
|
||||
continue;
|
||||
}
|
||||
// Entering the loop. We are not crossing it yet, it depends on the exit tile
|
||||
if (tile_type == DOWN_RIGHT || tile_type == UP_RIGHT) {
|
||||
if (tile_type == DOWN_RIGHT) {
|
||||
entry = 1;
|
||||
} else {
|
||||
entry = 2;
|
||||
}
|
||||
continue;
|
||||
}
|
||||
// Vertical pipe, we are crossing the loop
|
||||
if (tile_type == UP_DOWN) {
|
||||
crosses += 1;
|
||||
entry = 0;
|
||||
continue;
|
||||
}
|
||||
// Exiting loop, check whether we crossed
|
||||
if (tile_type == DOWN_LEFT || tile_type == UP_LEFT) {
|
||||
if ((tile_type == DOWN_LEFT && entry == 2) || (tile_type == UP_LEFT && entry == 1)) {
|
||||
crosses += 1;
|
||||
}
|
||||
entry = 0;
|
||||
continue;
|
||||
}
|
||||
}
|
||||
|
||||
if (crosses % 2) {
|
||||
inside_tile_count++;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
printf("%lu\n", inside_tile_count);
|
||||
|
||||
free(buf);
|
||||
}
|
||||
140
day10/input.txt
Normal file
140
day10/input.txt
Normal file
@@ -0,0 +1,140 @@
|
||||
.L7F--|-77FLF7-F-FLL.FL7|7FL7-7.7-FJ7FJ-F.|7-.F|-|F-JFJFL-J-.F|.7F--77|77F7F|J77|-|7|-F-7.|JFL7-7.J---J.F7--.7F|--LJFL-J.FFFF.-L|---7777F7-|
|
||||
JF-|.|.|-7J.7-F|-JJ7F.J7L-|JLL-7J.JF-7.7|-F7.FFJ--J.L77FJ7J.F--L.LJJFFJLJF-J||JL||.FJ7L-.F7||JL-FFJL.F|FLJLLFL|||J|L|77LF7.|--|||.|LLJLJJ.F7
|
||||
LLJF7F-L.7F-J-LJ|.FF77LLF7||FF--7L-77.J-J7JJ.|.L7FL|.F7JF77F-7.L-7L7JLF7.L7LL7.L|7FFL--J.L7-F-L-FJ7|7FFJJ-FJ|.J77.JF7FL.-JLFJ-L|7FJFJ7FF-7JJ
|
||||
L|-|J|F-7.7|.7-L-7LFJ|7L||JFF|JF7J|L-7J7|||..|7|L|J..||J..F7.|F|.--J7-LL7-JFL|F7.LJ7JJL---J||J|.L7F7--|JLFJ7J7|J|7.7J-|--J..L7F-|LF|JJ||7L-7
|
||||
7.LJ.LJLJ-7JJ-J|-J7||LJF||FJ-L-FL-7LJ77F|.LJ.|-||J.FF.L7L-|.7-|77.|..7JL--JL-|-J.JF--7JFJ|L7JFF-|-||77FF---7F|7--L-L|.|7-F-7FFJLL-J|J.FJ7|FL
|
||||
L7.|-JJ||J|LL|-|7.7J7-FF7L|||--|F|-7JLF-J7..F|.L77F-F7L7L---J-7J|-F7FL||LLF..|F|-JF|FF--7-7J7FJL|F||F7JL7F-J-J.L|J.J.LL--J.L-JJ.|.L-.F|---FJ
|
||||
LL-77..FF-|7|F-F-||F777J|LLFJ|FLJFJ.-7JJLL777|-FLJ.L||-JF|-|77|.F7|L7-77.|F-F77JJ.|F7L7FJ...-F-7JF|LJ|F-JL-7.|F-7.|JF..LF7|-7J.F|.LJF|JJJLF7
|
||||
LL-7-L7LJJJ-F7.JFL|-|L7F|-7L7-F77|LLJ|F||FL77L.L7J7F||L|F--|-LJ-|LJFJL-7L|J-||-J.-FJL7|L-7-F||FJF7L7FJL-7F-J77L7J||F|-7.LJJ.JLF-L7J-F|J..7||
|
||||
..LL.|LF|L|.-J7LL7|||FFJ--|.FF7JL|.F7-JJF|LL|F-.F7-FJ|7LF..LFJFLL7FJJLF-J|F-||J-J7L-7||F-JJ|L|L7||-||F7||L7|L7|F7-FFJ|F-|7J.J7LJL|J.LL-F|FF.
|
||||
F|.|F|7.|.7-|||-.FLJ7L7-|FJ7FLJ|7LJ-L-|F7J7-L|.FFJLL7|-F-77F--||-||77FLJLL|.||..LF--JLJL-7.J|L7|||FJLJL-JFJ7-F7-L77JF|77LFF7LL77.L-F||.FL-JF
|
||||
-FJ77LJ-F.-.7F|LJ7-F|F.FF7JFJF|F|7JF||F||.F.F|-F-7F7||F|FJFJ..F7FJL--7JF7-|F|L7JLL7F7F7F-J.LFFJ|||L--7F--JF7L||J.L7-L.||F-L|.LF-JJ.LL-F|JL7L
|
||||
L|JL|J|FJ7.F.FJFL.FLLJFFJ|7|JFF7F7F-7-FJ|F7F7LLL7|||||FJ|LF.FFJLJF---J.||-LFJFJLF7||LJ|L--77LL7LJL7F7|L-7FJ|FJL-7.||7F|J-|L-7FFJ|L7-FJ|J7.|.
|
||||
7-7-7F-7FJ--7||F|LJLL|JL7L77F7|LJ|L7|LL7|||F7-F7|||||LJFJF--7L--7|F--7F7F-7L7|F7||LJF-JF--JF-7L7F-J|||F-J|FJ|F--J77J7||-L77LFLJF--FFJ.-.FF.-
|
||||
|L7-L7L-JJ7.|-F-777..L7FL7L-JLJF-JFJL7FJ|||||||||LJLJF-JL|F-JF--JLJF-J||L7|7||||||F7L-7L-7.L7|FJL7FJ|||F-J|FJL----7-7777F-7-LJFLJ-|JJ-LJ7|..
|
||||
FL..|JFJJ.J7L7LJ-7J7F7J-.L----7L-7|F-JL7LJ||L-J|L--7FJF-7|L-7L-7F7FJF7||||L7|||LJ||L-7L7FJF7||L-7|L7LJ|L7FJ|F-----JLFJ|-7LJ||-L7..|L7F-L7-.F
|
||||
7.FJ|L7L-LJLFFJJJ.F|.LJLFF----JF-J||F77L-7|L-7FJF7-||.L7||F7L-7||||J|||L7L7|||L-7||F7L-JL-J||L7FJL7|F7|FJL-JL------7JFJ7J|.FJ.LF.F||LJ|LL77|
|
||||
-|--FJFL-JJFLJL-F77|7|L--L----7L-7|LJ|F-7|L-7||FJL7|L7FJ|LJ|F-JLJ|L7||L7|FJLJ|F-J|LJ|F---7FJ|FJL-7LJ||||F----7F----J7-JFF7FJFL--77.F7FFLL-JJ
|
||||
L7|FJJFFL7|.|-7-J|F|7.||.F7F7LL-7||F-J|FJ|F7LJ|L7FJ|FJ|FJF-JL7J-FJFJ|L7||L7F7LJF7|F-JL--7LJFJL7F7L7FJLJ|L-7F7LJF--7-|-FJF-7JJ-FL-|7F|77-|J.F
|
||||
..|L|--LL--7|.L-JF|JLFF7-||||F7L|||L7FJL7LJL-7|FJ|FJ|.|L7L--7|F-JFJ.L7|||FJ|L7FJLJL--7F7L7.L7FJ|L-J|F7-|F-J||F7L7FJF7F-7|FJJ.LFJ.|F-JFJ.|F-7
|
||||
FF7-7J|L|LF-J.F|-7J.F-JL-JLJLJ|FJ|L7||F-J|F7FJ||FJL7L7L7L7F7|LJF-JF7FJLJ|L-J.|L7F7F7FJ|L-JF-JL7L--7LJL-JL7.|||L-J|.||L7||||F-F7FJLJJ7J7FLJ|J
|
||||
J.|.|LJ.-.-7L7FF7.FLL7F------7|L7|FJLJ|F7FJ|L7|||F7|FJ-|FJ||L-7|F-J|L--7L7FF7L7|||||L7|F77L--7|F7FJF-----JFJ||F--JFJL-JLJL-7.||-7FJ...|.JL77
|
||||
.FF7L-|7L|7|JF-|LF7.F||F-----JL7|||F--J|||FJFJLJ||||L-7||J||F7|||F-JF-7L7|FJL-JLJ|||FJ||L7F7FJLJ||FJFF7JF7L7||L7F7L-7F-----JFJ|LJ||.L7LJ-F|7
|
||||
.|L7FF7-F|7|F7-L77L-FLJL----7F7LJ|||F7FJ||L7L7F-J|||F-J||FJ||LJ|||F-JFJL||L--7F--J||L7||FJ||L--7|||-FJL7|L7|||FJ||F7|L-7LF7L|FJ7FFJ.|JF-FJ.|
|
||||
|JF7J|..-FJF7-77|7FLLLFF7F-7||L-7LJ||||FJ|FJFJ|F7|||L7F|||FJL7FJ|LJF-JF7||F--JL-7FJ|FJ||L7|L7F-J||L7|F7LJFJ|||L7|||LJF7L-JL-JL--777-7.F7L.L|
|
||||
L.|||F.7LFJ|LL|FLJJFF7FJ|L7|LJF-JF7LJLJ|.|L7L7||LJ||FJFJ|||F7||FJF7|F-JLJ|L--7F-JL7||FJ|FJ|FJL7FJ|FJLJ|F-JFJ||FJ||L7FJL---------JL-7|7|7L|J.
|
||||
LFL|-77LFF7|.|.||F|F||L7|FJ|F7L--JL--7FJFJFJFJ|L7FJ||FJFJ|||LJLJFJLJL-7F-JF--J|F7FJ|||FJL7||F-JL7|L-7FJ|F7L7||L7||.|L---7F-7FF-7JJ|.-LJ|FLF-
|
||||
.F.LFL--|L7--L---F--J|FJ|L7LJ|F-7F---J|JL7|FL7|FJ|FJ|L7L7||L---7|F7JF7|L-7L--7LJ|L7||||F-J||L-7FJ|F-JL7LJL7||L7LJL-JF---J|FJFJFJF-7-.LFLLJLJ
|
||||
JJ7LL7JFL-7-L|||LL--7LJFJFL-7|L7|L---7L-7|L7|||L7|L7L7L7||L7F7FJLJL7||L-7|-F7L-7L7|LJ||||FJL7|||J|L-7-L7F-J||-|F--7FJ.F--J|J|FJF7--J7FJLL--J
|
||||
FLL.LJ.L7.L|LLJL-|7LL-7|F7F-J|FJ|F7F7|F-J|FJFJ|FJ|FJFJFJLJFJ||L--7FJ|L-7|L7|L-7L7||F-J|L-JF-JFJL7L7FJF7||F7|L7|L-7||F-JF-7L-JL-JL7.7F|--J7||
|
||||
JJL-|-7.J7--7FL-L|-F--J|||L-7|L7|||||||F7||7L7LJFJL7L7L7F-JFJ|F-7||FJF-JL7|L-7|FJ|||F7L--7L7FL7FJFJ|FJ|||||L7||F-JLJ|F-J.L7F7F-7FJ-LJ7JL--7-
|
||||
|.-.FFJ-L77J|-L7F7LL--7|||F-J|FJLJ||LJ|||||F7L-7|F7|FJFJL-7L7||FJ|||FJF7FJL7FJ|L7||LJL--7L7|F7||-L7||FJ|LJL7|||L--7FJL-S7JLJLJF|L-77.--L-J|L
|
||||
F7.7.777FL7FL.FFJL----JLJ||F7|L--7|L-7LJ||||L-7|LJ|||FL7F-JFJLJL-JLJ|FJ||F-JL7|||||F----JFJ||LJL7.||||FJF7FJ|||F--J|F--7L----7FJF-J--|7.F-F7
|
||||
LF-L--FJ7-J777FL7F-7F---7|LJ|||F7||7FJF-J|||F-J|F-J|L7FJ|F7L-7F--7F7LJFJ|L7F7||FJLJ|F7JF7L7||F--JFJ|||L7|LJ||||L-7.|L-7L---7FJ|FJJ7||LJJ.|JL
|
||||
L|7.FLLJLL--7J.LLJ7LJF--JL7FJL-JLJ|FJFJ-FJ||L7FJL7|L7LJFJ||F7LJF7LJL-7L7L7||LJ|L-7FJ|L7||FJ||L7F7L7|||FJL7JFJLJF7L-JF7L---7LJL||J.77.J|L|J.|
|
||||
FFJ7|77L-|..-.|-F7F-7L---7|L-----7|L7|F7L7|L7||F-JF7L-7|-||||F7||7F7F|FJL||L7FJF7||L|FJ||L7||FJ||F||||L-7L-JF7FJL7F-JL--7FJ||L|L7.-77FL7..F|
|
||||
LLFJJL|.|F-F|FF.||L7|LF7.||F7LF7FJL-J||L7||FJ|||F7||F-JL7|||||||L7|L7|L7FJL7|L7|||L7||FJL7||||FJ|FJ|||F7|F--JLJF7LJF---7||F--7|FJFLF-F-77F-7
|
||||
.LJJFF|7F-7|FF--JL7||FJL-JLJL-J|L---7|L7|||L7LJ|||||L-7FJ||||||L7|L7||FJ|JF||FJ|||FJ||L7FJ|||||FJ|.||||LJL-77F7|L--JF7FJLJ|F-JLJ|J.JJLFFFJ||
|
||||
FF.J-L77||7-FL-7F7||LJF-------7|7F7FJL7|LJL7||FJ|LJ|F7|L-J||LJL-JL7|||L7L7FJ|L7||||FJ|FJL7|LJLJL7L7||||F---JFJLJF7F7|||F7FJ|-F7FF.FL---JJ-F7
|
||||
FF7J.FJL---7LJ-LJ||L--JF------JL-JLJLFLJF--JL7L7L-7||LJ|F-JL--7F7FJ||L7L7|L7|FJ||||L7|L7FJL--7F-JFJLJ|||F7F7|F--J|||||LJ||FJFJL-7777|F7J.FFJ
|
||||
LLF--L7FL|..7|F7FJL7F-7L---7F7F7F7F7FF-7|F7F7L7|F-J||F-7L7F7F7|||L7|L7|FJL7||L7|||L7||FJL7F7FJ|F7L-7FJ|LJLJLJL--7LJLJ|F-J|L-JF--JL7--LLJFL|J
|
||||
FF|||LF7-LFFF7||L-7|L7|LF--J|LJLJLJL-JFJLJ||L7||L7FJ|L7L-J|LJ|LJL7|L7||L7FJ||FJ|||||||L7FJ||L7LJL7FJL-JF7F--7F7FJ-F7|LJF-JF-7|7.|F|J|L7F|-|.
|
||||
L|7LJ-7LF7FFJLJ|F-JL7|L-JF7FJF-------7L-7FJL7LJ|FJL7||L7F7L-7L7F-JL-JLJF||FJ|L7|||FJ||FJ|FJ|FJF--J|F--7||L-7LJ|L-7||F7FJF7L7LJ-F7-7FJLL-|JF7
|
||||
|.LJ..7F-FJL--7|L--7LJF--JLJLL---7F7FL7FJL7FJJFJ|F-J|F-J||F-JFJL------7FJ||FJFJ|||L7||L7LJFJL7L7F7|L-7LJL--JF7|F-J|LJLJFJ|FJF7F|J-LFJ|F-J-L7
|
||||
|.|F--J|FF----JL--7L--J.F7F7F--7FLJL-7|L-7|L-7|FJ|F-JL-7||L7FJF--7F7F7|L7||L7L7|||-|||FJF-JF-JFJ|LJF-JF-----J|||F7|F--7L7|L-J|-J|.|.F7FL77|J
|
||||
LF.L|J7|-L-------7|.F7F7||||L-7L--7F-JL--JL7FJ||FJ|FF--J||FJL7L-7||LJ||.|||FJFJ|||FJ|LJFJF7|F7L-JF-JF-JF-----JLJ|LJL-7L-JL---J|--FL|7L7.LLJ7
|
||||
.|L--7F|JL|F7F7F-JL-JLJLJLJ|F7L--7|L7FF7F7.|L7||L7L7L--7||L-7L7FJ|L-7|L7||||FJFJ||L7L-7L-JLJ||F7.L--JF7L------7F|F---JF7F---7LL-7|J.F.-7F|LJ
|
||||
FF7F7FJLF--JLJLJF-7F7F-7F-7||L---JL-JFJLJL7L-JLJFJFJF--J||F7L7||FJF-JL-JLJ||L7|FJL7L7FJF7F--JLJL7.F--JL------7L-JL-7F7|LJF--JJ7JF7.-JF-JF7J|
|
||||
7.LJFJJ.|F7F7F-7|FJ|LJFJ|FJLJF------7L7F--JF--7FJFJ7|F7FJ|||FJ||L7L---7F-7|L7LJ|F7L7||-||L7F7F-7L7L7F-7F----7L-----J|LJF-JFF77J7J|.|JL7LJJL|
|
||||
|7-FFJLF||||LJ|LJL7L7FJFJ|F-7|FF----JFJL--7L7FJ|FJF7|||L7|||L7LJ.|F7F7||FJ|FJF-J|L7|||FJL-J||L7L7L-J|-LJF--7L-------JF7|JF-JL7.L-J7|F-|-L-F-
|
||||
----JLF-LJ||F--7F7L-JL7L7LJFJ|FJF7F--JF7F7L-JL7LJFJLJ|L7|LJL7|F--J||||LJL7|L7|F7|7LJLJ|F-7FJ|FJ7|F7FJF-7L-7|F-----7F7||L7|F--J7.|-|F-7|-F7JL
|
||||
||-|7F7JJLLJL-7|||F7F7L-JF7L-JL-JLJF7FJLJL-7F-JF7L---JFJL--7LJL--7|LJL-7FJL7|||LJF----J|-||-LJF7LJLJ-L7L--J|L-7F-7LJLJL7LJL-----77|F-L-77J.|
|
||||
|7.F7|.|||F7F7|||LJ||L-7FJL--7LF7JFJ|L--7F7LJF-JL----7|F7F-JF----JL-7F-JL-7|||L7FJF-7F7|FJL-7FJL-7F7F7L--7FJF-J|FJ|F777L----7F--J7F-J.|LF777
|
||||
||-J7J.LF-JLJLJ|L-7|L-7|L-7F7L-JL7L7|F--J|L7.|F--7F--JLJ|L7FJF-7F7F-JL7F7FJ|||FJL-J|LJ||L7F-JL7F7LJLJL---JL7L-7|L--JL7F7F7F7LJJJLJJ.FFL-J.|F
|
||||
|F7-J-7||F7F--7L--JL--JL-7LJL---7L-JLJ.F7L7L7|L-7LJ-F7LFJFJ|FJFLJ|L--7|||L7|||L7-F---7||.LJLF7LJL---7F---7JL--J|F---7LJLJLJL7J..777.7JJ.FFLJ
|
||||
F-J7|.LFLJLJF-JF7F----7F-JF----7L7F7F-7||LL7LJF-JJF-JL7L-J|LJF---JF--J|||FJ||L-J.L-7FJLJF-7FJL7|F7F-J|F-7L7F--7|L--7|F-7F7F-JF7FFF7F7-77LJ.F
|
||||
|J--FFJ||J-LL--J||F-7FJL77L--7FJFLJ||FJ||F-JF7L--7|F--J7F--7JL7F-7L7F7||LJ-LJ|F7.F7||F7LL7|L-7L7||L--JL7|FJ|F-J|F--J||7LJLJFFJL--JLJL7J||FJJ
|
||||
|F7JL|.F-7.FF7F7LJL7|L-7|F7LFJL7F-7LJL-JLJF-JL7F7||L----JF7L7FJ|7L7LJ||L--7J-FJL-JLJ||L7J||F7L7|||F7F--JLJFJL7FJL-7.LJF7F7F7|F7F-----J-7F--F
|
||||
.LF7L|7|FJ-FJLJL-7FJL--JLJL7L7FJL7|F--7F--JF-7LJLJ|F-----JL-JL7|F7L7FJ|F--J|.L-7F7F7|L7|FJLJL7||||||L--7F7L-7||F-7L7F7||||||||LJFF77-|.|7FFJ
|
||||
.L|L.|L||F7L-7F-7|L---7F7F7L-J|7FJLJF7LJJF7L7L----JL7F------7-LJ||FJL7|L7J-F77-LJLJ|L-JLJF7F7LJLJ|||F--J|L--JLJL7L7LJ||LJ|||||F7-|L7F77LF--.
|
||||
FF-JF--||||F7LJFJL7F--J|LJL--7L7L---JL7FFJL-JF---7F7LJF7F7F7L7.||||F-J|FJJ7|L7F7F7FJF-7F-JLJL-7F7LJ|L7F7|F--7F7FJJ|F-J|F7LJLJLJL7|FJ||.F|FJ7
|
||||
L-7L7LFJLJLJ|F7L-7|L---JF----JFJF----7L-JF7F-JF7FLJL--JLJLJL7L7FJLJ|F-J|FF-L7LJLJLJFJFJL7F----J||F7L-J|LJL-7|||L-7LJF7||L---7F-7LJL-JL-7JJJL
|
||||
77FF--L7F7F7LJL-7||F-7F7L----7L-JF--7|F7FJ|L--JL-----7F7F7F7L-J|F7FJ|F7L-7FLL----7FJLL7FJL--7F7|||L7F7|F---J|||F-JF7||||F7F7LJ||F7F7F--J-JJL
|
||||
|L--.FFJ|LJL7F-7LJ|L7LJL7F---JF7FJF-JLJ|L7L7F-7F-7F-7LJLJLJL--7LJLJLLJ|F-J-.LLF-7LJLFJLJF---J|LJLJFJ|||L---7||||LFJLJLJLJLJL-7FJ|||LJJFJ7J7J
|
||||
7F|J.FL-JLF7LJFL-7L7|F7FJL---7|LJFL---7L-JFJL7|L7LJFJF7F7F7F7FJJJF|-|.LJJJ-||LL7L7F-7F-7|F--7|F--7L-JLJF---J|||L-JF7F-7F-----JL-JLJJ|.|JJF-7
|
||||
F-.|F7-FFF|L---7JL7LJ||L----7LJFF-----JF7-L--J|FJF7L-JLJLJLJLJ|F--F-F7.|J|-FL7-L7|L7||FJLJF-J|L-7|F7F77L---7||L7F7||L7|L---------------7-|L|
|
||||
|.FF----LFJF--7|F7L--JL7F--7L--7L--7F--JL----7|L-JL-----7F--7F7J|FJJ|-||LJLJLF--JL-J|||F-7L--JF7|||||L7F7F-JLJ-LJ||L7||F7F7F----7F--7F-JJL-L
|
||||
LFL.|F7JLL-JF7|LJL----7LJF-JF-7L---J|F-----7FJL-7F7F7F--JL7FJ||.L7LF7F|FF|F|FL-7F7F7LJ||FJF-7FJLJLJ|L7LJLJLF---7|LJFJ|LJLJ|L---7|L-7|||.F.||
|
||||
||L.-7L7|FF7||L------7L-7L--J-L7F--7|L---7-LJFF7LJLJ|L--7FJL-J|-||.LJ-77||F-FF7LJLJ|F7LJL7|FJL--7F7L7L7F-7FJF-7L7F7L-JF--7L---7||F7|LJ-LJ.--
|
||||
.|7LJJ|L-FJLJL-----7-L-7|7F----JL7LLJF7F-JF---JL7JF7L---J|F--7L-7J-F|J.|||..FJL7F7FJ|L7F7||L7F-7LJL7|F||FJ|FJ.L7LJL---JF7L---7LJLJLJJ.L|LFLJ
|
||||
L-||.--7LL--7F7F--7|F7FJL7L--7F7FJF--JLJF7L-7F-7L7||F7.F-JL7.L--J|F||JFL-F-LL-7LJ|L7||LJ|||FJL7|F--JL7LJL-JL--7L---7F--JL----JL|J7|JFFFL.|.|
|
||||
|7L-77LL7.F-J|LJF-JLJ|L7FJF7JLJLJ|L---7FJL7FJL7L-J|||L7|F-7L---7JLJ|F.|..LFJ|J|F7L-J|F--JLJL--JLJF--7||F7F----JF--7|L7F---------7-7L7-F7FJLL
|
||||
LJJ--7-||F|F7|F-JF--7L-JL7||F7F7F7JF7FJ|F-JL-7L7F7|||FJ||7L7F--J.LLLJ-LF--F.LFJ|L7F7|L-7F---7F---JF-JL-JLJF7F7FJF-JL-J|F7F------J77FL.|F7JL|
|
||||
|7-F.|-|-FLJLJL-7|JFJF7F7LJLJLJ||L-JLJFJ|F-7.L7LJ||LJL-JL-7|L-7.F.|LLFJJ|7|7|L-JFJ|LJF7LJF--J|F---JF7F7F--JLJLJFJF-7|FJ|||F7F7F7F777-JJFJF-7
|
||||
|7-J-7LLLF--7.F7LJFJFJLJL--7F-7LJF-7F7|FJ|FJF7|F-J|F------JL--JF7-|FFF7F7-JF-F7JL-JJFJL--JF7FJ|F7F7|LJLJF------JFJFJFJFJLJ|||LJLJL77L||.|--J
|
||||
FJLJ.L7.|L-7|FJL--JFJF-----J|FJF7L7LJ||L7|L7|||L--J|F7F--------J|7LF|LLFJLFJJ||F7F-7L----7|LJLLJLJLJF7F7L7F7|F77L7|-|FJF7FJLJF7F--J-J.|-F.FJ
|
||||
L7LF7.LF---JLJF7F7FJFL7F7F7FJL-JL-JF7LJFJ|FJ|LJF---J|||F7F----7FJ7-F7L||.||FF||||L7L-7F7FJL7F7F7F---JLJL-J||FJL7L|L-JL7||L7F-J|L--77||JL|7FJ
|
||||
LLJ.L7-L--7F7FJLJ|L7F7LJLJ||F------JL-7L-JL-JF7L--7FJLJ||L---7LJJ-FJ|-F7F7J-FJLJL7L7FJ||L-7||LJLJF7F------JLJF7L7|F---J|L-J|F7|F--J77L7.LJ|7
|
||||
77FJ.|.J.FJ|LJF7JL-J||F--7LJL--------7|F-7F7FJL7F7LJF--JL7F7FJJJ|JL7|-|LJ|LFL---7L-JL-JL--J||F7F7|LJF-------7|L7LJL----JF-7LJ|LJJJJ|7FF||LF7
|
||||
L|JJFFJJFL7|F-JL----J||F-JF7F--------J|L7LJ|L-7||L--JF--7LJLJFLF--7||FJF7|7JF7JFJF--7F7F-7FJLJLJLJF7L------7||||F---7F--JF|F-JF77|J|F-LL7|||
|
||||
.||.7J7.LFLJL-------7|||F7|LJF-7F----7L7L-7L-7||L----JF7L77F-77L-7LJLJFJLJJFJL-JFJF-J||L7LJF7F7F--JL-------JLJFJL--7|L---7|L--JL77F7J.|LFL-J
|
||||
-|7-F.FJ|F----------JLJLJ|L7FJFJ|F7F7|FJF7L7FJ|L7F7F--JL7L7|FJF7|L--7FJF7F7L-7F7|FL-7|L7|F-JLJ|L--7F7F7F-----7|F7F-J|F7F-JL---7FJLF7.F7--JJJ
|
||||
..|LLJ77FL7F--------7F--7L-J|FL7||LJLJ|FJL-JL7L7|||L7|F7L7LJL7|L7F-7|L-JLJL7-LJ||F--J|L|||F7F7L--7LJLJLJ|F---JLJ|L7LLJ|L-----7LJF7||F-7|JF--
|
||||
|FL-J||FJ-LJF-------J|F-JF--JF7LJL---7|L---77L-J||L7L-JL7|F7FJ|FJL7||F----7|F--J|L7F7L7LJLJLJL7F7L-------JF7F--7L7|F7FL-7F7F-JF-JLJ||FJ7-LJ7
|
||||
-L-7F7.L7..|L-7F7F7F7||F-JF--JL7LF7F7||F7F7L---7||7|F-7FJLJLJ7||F7|LJL7|F7LJL--7|LLJL7|F---7F7LJL---------JLJF-JFJ||L--7LJLJF7|F---J||F7.FFJ
|
||||
LLL-7||7LLFFF7LJLJ||||LJF7L--7FJFJLJLJLJLJL7F--J|L7||FJL-7F7F-J|||L-7FJFJL7F7.||L-7F7||L--7LJL----7F77F---7F7|F7L-J|F--JF---JLJL7F7FJLJL77||
|
||||
||JL7-FLJLF7|L---7LJLJ-FJ|F7FJL-JF-7|F7F-7FJL--7L-J||L--7|||L-7||L7||L7L7FJ||F7L-7|||LJF-7L-7F7F-7LJ|FJF-7|||LJL7F-JL---JF7F7F-7LJLJF-7FJ|L7
|
||||
F7---F-.LL||L---7|LF--7L7||LJF---J7L-JLJFJ|F---JF-7|L--7LJ||LFJ||FJFJFJFJ|7|LJL7|LJ||F-JFJF-J|LJJL-7|L-JFJLJL--7LJF7F7F-7|LJ|L7L-7F7L7|L-777
|
||||
||F-|LFJJ-||F7F-J|FJF7L-JLJF7|F--------7L7LJF77FJFJL---JLFJL7L7||L7L7L7L7|FJF--JF7FJ|L7FJ|L--JF----JL--7L-----7L--JLJLJ.|L-7|FJF-J||FJ|F-J-F
|
||||
LLJL|-JJ.FJ|||L-7||FJL7F---JLJL----7FF7L-JF7|L7|FJFF----7L-7L7|||FJ-L7L7||L7L7F7||L7|FJL7F-7F7|F--7F--7L--7F-7L---7FF7FFJF7|LJ|L7FJ||FJL7J-7
|
||||
L|-.F7.|FL7LJ|F7||LJF7LJF--7|F-7F7FL-JL7JFJ||FJ||F7|F---JF7L7||||||F7L7LJL7L7LJ|||FJLJF-J|FJ||LJF-J|F-JF-7LJ-|F7F7L-JL7L-J||J.F-JL7||L--J|F|
|
||||
F||.LLF--7L-7LJLJ|F7||F-JF7L7L7LJL----7L7|FJ|L-JLJ|||F-7|||FJ||LJ|FJ|-|F-7L7|F-J||L--7|F7||FJ|F-JF-J|F7L7L7F7LJ|||F7F7L--7||JFJF7FJ||JJ|.F-7
|
||||
FJFF7.L-7|F7L7F-7LJ|||L7FJL7L-JF7F---7L7LJL-JF-7F7||LJFJFJ|L7||F-J|FJFJL7L-J|L-7|L---JLJLJLJFJL--JF-J|L-JFJ||F7LJLJLJ|F7FJLJLL7|LJ7LJ7JL---L
|
||||
|.||7F|F|LJL-J|FJF7LJL-JL-7L--7|LJ|F-J-L-7F7FJ|LJLJ|F7L7L7|FJLJL-7|L7L7FJF-7|F-JL------7F---JJF--7L--JLF-JL|LJL-7|F7.LJLJF7||-LJJ-L7-L-|F|L|
|
||||
FLLLF-7FJF--7FJL-JL-7F----JF--J|F7FJF--7JLJLJF7F7JFJ|L-J-||L---7FJL7|FJL7L7|||F7F7F----J|FF--7L7FJF7F7FJF--JF---JFJL7F7F7||F7-|.|-J|||FL|JF-
|
||||
JJL|L7LJFJLFJ|F-7F-7||F7F7FJF--J||L-JF-JF7F7-|||L7|FJ7F7FJ|F7F7|L7FJLJF7|FJLJ|||||L----7L7L-7L-J|FJLJLJFJF--JF--7|F-J|LJ|||||F7F77F|-L|.L--J
|
||||
|77|JL7FJF-JFJL7|L7|LJ|LJ|L7L-7FJL--7L--JLJ|FJ|L7|||F7||L7||LJ||FJL-7FJ||L-7FJ|LJ|F7F7.|FJF7L--7|L--7F-J.L---JF-J||-FJF-J|LJLJLJL7JL7.|.JLJJ
|
||||
-7-J|FJ|FJF7|F-JL-JL77L-7L-JF-JL-7F7|F7F7F7|L7L7|LJ||LJ|FJ|L-7LJL7-FJL7LJF-JL7|F-J||||FJ|FJL7F-JL7F7LJF------7L77|L-JFJF7|F---7F7L7F7FF77LJ.
|
||||
.7L|-L-JL7|LJ|F7F-7FJF-7L--7L7F-7LJ|LJLJLJLJ.|FJL-7||F-JL7|F7L7F7L7|F-JF7L--7|||F7||||L7|L7FJL--7LJ|F7|F----7L7L-JF--JFJLJL--7||L7L7J-FF7|F|
|
||||
7LFJ-|JJFLJF-J|||FJ|FL7|F7FJFJL7|F7L-7F7|F7F7||F7FJ||L7F7|||||LJL7LJL7FJL7F-J|||||||||FJ|FJ|.F77L-7LJ|||-F--J7L7F-JFF7|F7F---J||7L-JJ||J|-|J
|
||||
|FJ7L|FFFF-JF-JLJL7L--JLJLJFJF-JLJ|F7||L7|LJ||LJ||FJ|FJ|LJ|||F7F-JF--JL7FJL-7||||||LJ|L7LJFJFJ|F--JF7|LJFJF7F7F|L--7||||LJF--7LJF7F7FL-FF-LF
|
||||
77LF.|7LLL--JF--7FL7F7F-7F-JLL7F-7LJLJ|FJ|F7|L-7||L7|L7|F7|||||L-7||F-7||F7FJ|||||L7FJFJF7L-JFJL-7FJLJF7L7|LJL7L7F7LJLJL-7L-7L--JLJL7LFJ|7FJ
|
||||
LJF|7L-7|L7F-JF7|F7LJLJJLJF---J|FJF77FJL7LJ||JFJ|L7LJFJLJ|||||L7FJL7|FJ||||L7|||||FJL7|FJL--7|F7FJ|F7FJL-J|F7FJFLJ|F7F-7FJF7L7F-7F7FJ|J-L77J
|
||||
-|-L.7J|F|FL--J||||F77F---JF--7|L7|L7L-7L7FJL7|FJFL7FJF7FJLJ||FJ|F-J|L7||||FJ||||||F-JLJF7F7|LJ||FJ||L----J|||F7F7LJ|L7|L-JL-JL7LJLJ.-.F.77.
|
||||
.|F|.-.FF77F--7|LJLJL-JF7F7L-7LJLLJFJF7|FJL-7||L7F7|L7|||F-7||L7|L7LL7LJ|||L7|||||||F7F-J||||F7||L7|L7F----J|LJLJL-7|FJ|F7F7F-7|LFL|-|F-7JF7
|
||||
F7-|7-F-JL7L-7|L---7F-7|LJL7FJF----J|||||F7F|||FJ|||FJ||LJJ||L7||FJF7L7FJ||-||||||||||L-7|||||LJL7||FJL----7|F7F---JLJFJ||||L7|L77L-7LL.|.77
|
||||
J--77|L7F7L--JL-7F-J|FJ|F-7LJ7L-7F7F-J|||||FJ|||FJ|||FJL7F-J|FJ||L7||FJL7|L7|||||||||L7FJLJ|||F-7||||F-7F--J||LJF7F--7L-JLJL-JL7L77|77F-|7LJ
|
||||
FJ-FL-.|||F----7|L-7|L7|L7L--7F-J||L7FJ|||||FJ||L7|||L7FJL-7|L7|L7||LJ7FJ|FJ|||LJ||||FJL-7FJ|LJFJ|||||FJL--7|L--JLJF-JF7F-----7L7|JJ.LFFL|.|
|
||||
JJF-J7FLJLJF---JL-7LJFJL7L7F7|L7FJL7|L7|LJLJL7||FJLJ|FJL-7FJL7|L-J|L--7|FJL7||L-7|||||F--JL7L7FJFJ||LJ|F---JL7F7F-7L--JLJF7F-7|-||J|J-FJF---
|
||||
LF7--7JFF77L7F---7L-7L--J.LJ|L-J|F-J|FJL-7F--J|||F--JL--7||FL||F--JF7FJ|L-7||L-7|LJLJ||F---JFJL7L7LJFFJL----7LJ||-L-7F7F-J||.LJLLJFJJ.7FJ-|.
|
||||
.|J7|J.FJL-7LJF--JF7|F7F7.F7L7F7||F7|L7F-JL--7|||L7F7F-7||L7FJ||F7FJ|L7|F7|||F-JL7FF-J|L7F7FJJ|L7|F--JF7F7F7L7L|L-7J||||F7LJF7F7F7J|FFF7JFFF
|
||||
F|||L--L--7|F7L-7FJ|LJLJL-JL-J|||||LJFJL---7J||LJFJ|LJFJ|L7||FJLJ|L7L7|||LJ||L7F7L7|F7|FJ||L-7F-J|L--7|||||L-JFJF7L7|||LJL--JLJ|||7F|JJ|7|J|
|
||||
--LJLJJFF-JLJL--J|FJF7F7F7F7F7|||LJF-JF7F--JFJ|F7|FJF7L7L7||||F--JFJ|||||F-JL7||L-JLJ||L-J|F7|L-7L7F-J|LJ||F-7L-JL7|||L7F7F--7FJ|L-7-.---F-7
|
||||
F|FJ|-F-L7F7F7F-7|L7|||||||LJ|||L7LL7FJ|L--7L7||LJ|.|L-JFJ||||L7F7L7FJ|||L7F7||L-7F--JL7F-J||L7.L7||F7L7FJLJFJF7F7LJLJ-LJ|L-7|L-JF7|J77FJLJ|
|
||||
FLJ7F.LJ|||||LJFJ|FJ|||LJ||F-J||FJF-JL7|F-7L7|||F7L7|F7FJ|||||FJ||FJL7||L7||||L7FJ|F7F7|L7FJ|FJF-J|||L7||F-7L-JLJL7F7-F-7|F-JL7F7|LJLLFJFJ.-
|
||||
|F|FFF.F-LJ|L7FJFJL7||L7JLJL--J||7|F-7|LJFJFJ||LJ|FJLJ|L-7LJ||L7|||F-J|L-J||LJFJL7LJ||||FJ|7LJ-L-7||L7LJLJFJF7F7F7LJL7|FJ|L--7|||L--7.--L-7L
|
||||
L7-F-JFFJF-JFJL7|F-J|L7L7F-----J|FJ|FJL-7L7|.||F-JL7F7L7FJF7LJFJ||||F7L--7|L7FJF7L-7||||L7L-7F7JFJ|L7L-7F-JFJLJ|||F-7LJL7|F7FJ||L7F-J7JLFJF7
|
||||
||7J|FJ-7L-7L-7||L--JFJFJ|F-7F-7|L7|L7F-JFJL7LJL7F7LJL7|L-JL-7L7|||||L7F7||FJL7||F-J||LJFJF7LJL7L-JFJF7||F7L--7LJ|L7|F--JLJLJJ||J|L7--.7|-|F
|
||||
-LJ-F7FL-LJL7FJ||F---JFJFJ|FJ|FJ|FJL7|L7FJF7L7F-J||F-7|L---7FJFJ|||LJFJ||||L-7LJ|L7FJ|F-JFJL7F7|F7FJFJLJ||L7F7L-7|FJ|L-------7LJ7L7|-77JF7FL
|
||||
FJJ|.L|FFL7F||-LJL7F-7L7L-J|FJL-JL7FJL-JL7||FJ|F7|||FJL---7|L7L7|||F-JFJ|||F7|F-JFJ|FJL-7|7FJ|LJ|LJFJ7F-J|L||L7FJ||F|F7F-----JJFJJLJ|L7F7-7J
|
||||
7..|-7LJ-L|-LJ7FLFJ|-|FJ7F-JL7F---JL----7LJ||FJ|||LJL-7F--JL-JFJ|||L-7||||LJ||L-7|JLJF--JL7L7L-7L-7|F7L-7L7|L7||FJL7LJ|L-----77F.FL|7JL-F-JJ
|
||||
F.F|LJ77-|LL|7L7|L7L7||.FJF-7|L7F-7F7F-7|F7LJL7|||F---JL7LF7F7L-J|||FJL7||F-JL7FJL--7|F-7FJFJF7|F-JLJL-7|FJL-JLJ|F7L-7L7F-7F-J7|--7.J.F.JJLJ
|
||||
JFL.|7FL7J7LFJFLJ-|FJ||FJFJFJL7LJ7|||L7|LJL7F7||||L7F7F7L-JLJL--7LJFJF7|LJL7F7|L-7F7|LJ7|L7L7||||F7F--7||L---7F-J||F-JFJ|J||7.L|-|--|7|L..|.
|
||||
.7|FL-|7LL7.F.F7JFJ|FJ||FJ7L7FJ-F-J||FJ|F7FJ|LJ||L7LJ|||F7F7F7F7|F-JFJ|L-7FJ||L7.||||F--JFJ-LJ||LJ|L-7LJL7F--J|F-J|L-7L-J-|L7-LJ.JL-L7-7F--7
|
||||
.L-FJ|LJ7F-7J-F-7L-J|FJLJLF-J|F-JF7||||||LJFJF7|L-JF-J|||LJLJLJ|||F7L7|F-JL7|L7|FJ||||F-7L---7LJ.FJF7L7F7LJLF7LJF-JF-J-JJ-L-J.FL7J.|.L.LJ.||
|
||||
7-|..--J|J.---|FJ-L7LJ7|7|L7FJ|F7|||||FJL-7|FJ||.F7L-7||L-----7||LJL7|LJ7F7LJFJ|L7|LJLJ-L7F--JF-7L7|L7LJL7JFJL-7|F7L--7J|FLJ-7-||L7F.J--|FF|
|
||||
L-7-|J7FJ||F|.LJ7||7FL|J-LJ||LLJLJ||LJL7F-J|L7LJFJ|F7LJ|F-----J||F--JL---JL7-L-JFJL7F---7|L--7L7L-J|J|F-7L7L7F-JLJ|F7FJFF|7LF..L-.FF-JJFL7L-
|
||||
L|L|LJ7L.F---J7L|7--LLJFL--LJ|LF--JL-7FJ|F7L7|F7L7LJ|LFJL----7JLJL-7F7F-7F-JF---JF7|L7F7LJF-7|FJF-7L7|L7L7L-JL---7||||L-F|JJL7.LJFF-.-F|-F7.
|
||||
F--FL--JFJLJ--JJ||F-7L|7JFL|JJ.L7F7F-JL7LJL7|LJL7|F7L-JF-7F-7L----7||||7LJJFL-7F-J||7LJL-7||LJL-JFJFJ|FJ.|F-7F-7FJ|||L7.F|FF7J.LF-F77LFL.LF7
|
||||
LL7JJFLFFJ.|F77.L|-.J|FL77||.|F7LJ|L-7FJF7FJ|F7FJLJL--7|||L7|F--7FJLJ|L7LJ|LJ.LJLFJL7F7-FJL-7LF--JFJFJL-7||FJ|.LJLLJL7L--7-LJFJFF7LF-7||J-L7
|
||||
..LJLJ7|L|-F7FFF-J.L77|-L|7J.F|L--JF7||FJ|L7|||L7.F---JL7|FJ|L-7LJ|JL|FJJ.F||.F|FL--J||FJF--JFJF7FJFL-7FJ||L7L-----7LL7F-J-7|F.JL|-JFJ-F.7J.
|
||||
7.|-|LLJF--||-.J7.F--7.|.L|.J7L-7F7||||L7|FJLJL-J-L-7F7FJ|L7L7FJJLL-FJL7J.J-|-7FL.F-7|LJFJ|F7L7||L--7L||FJL7|F-7F--J-FJ|JLFLJ|.|-L-L7J.|7.-J
|
||||
F77-7L|7F|7FJJ-JJ--JLFF7-L||7|LLLJLJ|||FJ||J.J|L.FF-J||L7L7|FJL-7L|FL--J-7|F-.J|.FL7LJF7L-7|L7LJ|F7FJFJ|L-7|||FJ|7|JL|FJ|-JJ.F-|JL7F7L777-F|
|
||||
LLJ-|F7F-J|.L-J..|F-FJ.L7L-.FJ7.LJ|-LJLJLLJLF-F|--L7FJL7|F||L7F-JFLJFJ||J|7JJF-L7|LL7FJL7FJL7L--J|||-L7L-7||||L-J7|--LJLL7J.F|.J7.LJJLJ--7L-
|
||||
7F7FLJ--J.|7...FLJF||FJ7F.|7LLL.LF|.LJ7|JL|J||LJ|LFJL7.||FJL7|||-F-LJJF|.JLFF|-7F-LFJ|F-JL7FJF7F7|||F-JF-JLJLJ-J.L||L|JJJ|.FL-7L-777..|.||J.
|
||||
LJJ7JLL7LFLL7F|7|FL-7.F-J-LJ|LL-F|JF|FJ--..FLJ7FJ7L7FJFLJL7FJ|L7-L-LL-LJ.FFF777L77.L7|L7F7|L-JLJ||LJL-7L--7J|..|FLJ|J.|J7L77.L7.F||7FF777L..
|
||||
L.J7|FFJJJ|||7L-7||LJ-|FF-|L|||FLFJF-FJ77|-7JJFL7JJLJ-|7LLLJLL-J7J.F|||L-|F7|LF|J7.FJ|FJ||L-7F--JL7-F-JF-7|LJ-7-J.F|-JJ.7FLF7--J-JJ.F.|LL-77
|
||||
|-|-L7L7FFL|7-7L|L--J.7----J||-F-|J-||FJ7JF-JF7J||-|J.|7..L|..|-|.FL-L7J.|7||.FJ-FFL7|L-J|F-JL--7FJ-|F7|FJ|-J7.FJ7FJJ|J-JJ7J|L7-|LL-J7.F.L|J
|
||||
|-F7--777F|||LJ7|L|.F-|F-7JLLLFJ-|F7|FF-7-FJF7L7L|JL-|-7-7L7-FJ|L7---LJL-FJFF.|J.LLJLJ7L|LJJ-LJ7|L7-||LJL-J.L|-|.7LL-JJFFJL--LJ.F--7FL|.F--7
|
||||
77|J.FF|-F|J--LF|FL--7L77JL--L7.F|J|F---J|L-JJ.|7F7|7|L.LL-|--L|7J|.FL7|7L-F|-JFJ77LL-L7|.|JFLFFL7L7LJ.F|J||F-.LJJFF|--F-JFJJLF-F7|-JLL7|-|L
|
||||
L7JLL7.7-J.L|.L7L7JJL--LL.LJ7-LLJL.-7J.FJ7.F--F|7.L-7---JJ.J..J.7-JFFJ|-F-LFJJ-7-LF--LJ|J-J.L--JLL-JJL-F|--.FJ.FJ.FF7J-L|-J--LJ-L-J-J.L7J.|J
|
||||
5
day10/sample.txt
Normal file
5
day10/sample.txt
Normal file
@@ -0,0 +1,5 @@
|
||||
.....
|
||||
.S-7.
|
||||
.|.|.
|
||||
.L-J.
|
||||
.....
|
||||
5
day10/sample2.txt
Normal file
5
day10/sample2.txt
Normal file
@@ -0,0 +1,5 @@
|
||||
..F7.
|
||||
.FJ|.
|
||||
SJ.L7
|
||||
|F--J
|
||||
LJ...
|
||||
9
day10/sample3.txt
Normal file
9
day10/sample3.txt
Normal file
@@ -0,0 +1,9 @@
|
||||
...........
|
||||
.S-------7.
|
||||
.|F-----7|.
|
||||
.||.....||.
|
||||
.||.....||.
|
||||
.|L-7.F-J|.
|
||||
.|..|.|..|.
|
||||
.L--J.L--J.
|
||||
...........
|
||||
10
day10/sample4.txt
Normal file
10
day10/sample4.txt
Normal file
@@ -0,0 +1,10 @@
|
||||
.F----7F7F7F7F-7....
|
||||
.|F--7||||||||FJ....
|
||||
.||.FJ||||||||L7....
|
||||
FJL7L7LJLJ||LJ.L-7..
|
||||
L--J.L7...LJS7F-7L7.
|
||||
....F-J..F7FJ|L7L7L7
|
||||
....L7.F7||L7|.L7L7|
|
||||
.....|FJLJ|FJ|F7|.LJ
|
||||
....FJL-7.||.||||...
|
||||
....L---J.LJ.LJLJ...
|
||||
10
day10/sample5.txt
Normal file
10
day10/sample5.txt
Normal file
@@ -0,0 +1,10 @@
|
||||
FF7FSF7F7F7F7F7F---7
|
||||
L|LJ||||||||||||F--J
|
||||
FL-7LJLJ||||||LJL-77
|
||||
F--JF--7||LJLJ7F7FJ-
|
||||
L---JF-JLJ.||-FJLJJ7
|
||||
|F|F-JF---7F7-L7L|7|
|
||||
|FFJF7L7F-JF7|JL---7
|
||||
7-L-JL7||F7|L7F-7F7|
|
||||
L.L7LFJ|||||FJL7||LJ
|
||||
L7JLJL-JLJLJL--JLJ.L
|
||||
BIN
day11/c/day11
Executable file
BIN
day11/c/day11
Executable file
Binary file not shown.
131
day11/c/day11.c
Normal file
131
day11/c/day11.c
Normal file
@@ -0,0 +1,131 @@
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
#include <string.h>
|
||||
|
||||
#define LINE_MAX_LENGTH 256
|
||||
#define MAX_GALAXIES 1024
|
||||
#define abs(a) ((a) > 0 ? (a) : -(a))
|
||||
#define PART2 1
|
||||
#define EXPANSION_RATE (PART2 ? 999999 : 1)
|
||||
|
||||
typedef enum tile {
|
||||
EMPTY,
|
||||
GALAXY
|
||||
} tile_t;
|
||||
|
||||
typedef struct position {
|
||||
int x;
|
||||
int y;
|
||||
} position_t;
|
||||
|
||||
void expand_universe(int universe_x, int universe_y, tile_t universe[LINE_MAX_LENGTH][LINE_MAX_LENGTH], position_t galaxies[], int galaxies_num, int expansion_rate);
|
||||
|
||||
int main() {
|
||||
char *p, *buf, c;
|
||||
|
||||
buf = (char *)malloc(LINE_MAX_LENGTH);
|
||||
memset(buf, 0, LINE_MAX_LENGTH);
|
||||
p = buf;
|
||||
|
||||
tile_t universe[LINE_MAX_LENGTH][LINE_MAX_LENGTH];
|
||||
memset(universe, 0, LINE_MAX_LENGTH*LINE_MAX_LENGTH*sizeof(tile_t));
|
||||
|
||||
position_t galaxies[MAX_GALAXIES];
|
||||
memset(galaxies, 0, MAX_GALAXIES*sizeof(position_t));
|
||||
|
||||
int x = 0, y = 0, galaxies_num = 0;
|
||||
|
||||
while ((c = getchar()) != EOF) {
|
||||
*p++ = c;
|
||||
if (c == '\n') {
|
||||
x = 0;
|
||||
|
||||
p = buf;
|
||||
while (*p != '\n') {
|
||||
switch (*p) {
|
||||
case '.':
|
||||
universe[x][y] = EMPTY;
|
||||
break;
|
||||
case '#':
|
||||
universe[x][y] = GALAXY;
|
||||
galaxies[galaxies_num].x = x;
|
||||
galaxies[galaxies_num].y = y;
|
||||
galaxies_num++;
|
||||
break;
|
||||
}
|
||||
x++;
|
||||
p++;
|
||||
}
|
||||
|
||||
|
||||
y++;
|
||||
memset(buf, 0, LINE_MAX_LENGTH);
|
||||
p = buf;
|
||||
}
|
||||
}
|
||||
|
||||
expand_universe(x, y, universe, galaxies, galaxies_num, EXPANSION_RATE);
|
||||
|
||||
unsigned long part1 = 0;
|
||||
|
||||
for (int i = 0; i < galaxies_num; i++) {
|
||||
for (int j = i; j < galaxies_num; j++) {
|
||||
part1 += abs(galaxies[i].x - galaxies[j].x);
|
||||
part1 += abs(galaxies[i].y - galaxies[j].y);
|
||||
}
|
||||
}
|
||||
|
||||
printf("%lu\n", part1);
|
||||
|
||||
free(buf);
|
||||
}
|
||||
|
||||
void expand_universe(int universe_x, int universe_y, tile_t universe[LINE_MAX_LENGTH][LINE_MAX_LENGTH], position_t galaxies[], int galaxies_num, int expansion_rate) {
|
||||
int empty;
|
||||
position_t galaxy_offsets[MAX_GALAXIES];
|
||||
memset(galaxy_offsets, 0, MAX_GALAXIES*sizeof(position_t));
|
||||
// Empty rows
|
||||
for (int i = 0; i < universe_y; i++) {
|
||||
empty = 1;
|
||||
for (int j = 0; j < universe_x; j++) {
|
||||
if (universe[j][i] != EMPTY) {
|
||||
empty = 0;
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
if (empty) {
|
||||
// Shift existing galaxies
|
||||
for (int k = 0; k < galaxies_num; k++) {
|
||||
if (galaxies[k].y > i) {
|
||||
galaxy_offsets[k].y += expansion_rate;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
// Empty columns
|
||||
for (int i = 0; i < universe_x; i++) {
|
||||
empty = 1;
|
||||
for (int j = 0; j < universe_y; j++) {
|
||||
if (universe[i][j] != EMPTY) {
|
||||
empty = 0;
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
if (empty) {
|
||||
// Shift existing galaxies
|
||||
for (int k = 0; k < galaxies_num; k++) {
|
||||
if (galaxies[k].x > i) {
|
||||
galaxy_offsets[k].x += expansion_rate;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
for (int i = 0; i < galaxies_num; i++) {
|
||||
galaxies[i].x += galaxy_offsets[i].x;
|
||||
galaxies[i].y += galaxy_offsets[i].y;
|
||||
}
|
||||
}
|
||||
140
day11/input.txt
Normal file
140
day11/input.txt
Normal file
@@ -0,0 +1,140 @@
|
||||
.....#.....#......#.............................#........#.......................#...........#..............................................
|
||||
#......................................#....................................................................#........................#......
|
||||
.................................................................................................#...........................#..............
|
||||
............................#......#.................................................................................#......................
|
||||
..............#.............................................#..............................................................................#
|
||||
....................................................#....................#..................................................................
|
||||
..........................................................................................................#.................................
|
||||
...#...............#.............#...................................#.........#..................#...............................#.........
|
||||
........#................................#...................................................................................#..............
|
||||
..........................................................#................#................................................................
|
||||
....................................................................................................................#.......................
|
||||
.....................................#......................................................................................................
|
||||
.....................#.......................................#...........................#..........................................#.......
|
||||
.............#.........................................................#........#...........................................................
|
||||
......#.......................#..................#...................................#..............#........................#..............
|
||||
.................#........................#..........................................................................#.....................#
|
||||
............................................................................................................................................
|
||||
..........#....................................................#...........#................#..............#................................
|
||||
...........................#....................................................................................................#...........
|
||||
............................................................................................................................................
|
||||
...#...................#..............#........#...................#..................................................#.....................
|
||||
..........................................................#.....................................#...........................................
|
||||
...............................................................................#........................#.............................#.....
|
||||
.............#.................#............................................................................................................
|
||||
...................................................................................#................#.......................................
|
||||
............................................#...........................#................#...........................#......................
|
||||
.................#..........................................#............................................................................#..
|
||||
......#............................................................#.............................................#..........................
|
||||
.........................#...........#..........#...............................................#.........................#.................
|
||||
..#...................................................#...........................#.....................#...................................
|
||||
............................................................................................................................................
|
||||
.........#....................#...........................................#.........................................#...........#...........
|
||||
.......................................#....................#.............................#.................................................
|
||||
..............#...................................................#.......................................#.................................
|
||||
............................................................................................................................................
|
||||
...#................#....................................................................................................................#..
|
||||
............................................#...........................................#...................................................
|
||||
......................................................#...............................................#.....................................
|
||||
.................#...............#.........................#........#..........................#......................#.....#...............
|
||||
......#....................#.............#.....#...........................................................#................................
|
||||
...........#.........#...........................................................#..............................#...........................
|
||||
.......................................................................................................................................#....
|
||||
............................................#.......................................................#.........................#.............
|
||||
.......................................................................#.................................................#..................
|
||||
...#.......................................................#......#.........................#.............................................#.
|
||||
...............................#.................#..........................................................................................
|
||||
..................#.....#...........#........................................#.....................................#........................
|
||||
......................................................................................................................................#.....
|
||||
..........#..............................................................#..................................................................
|
||||
.............................................................................................#...................................#..........
|
||||
#....................#..................#..............#....................................................................................
|
||||
...................................#............................#.....#.....................................................#...........#...
|
||||
..........................................................................................#.........#..............#........................
|
||||
.....#.........................................#............................................................#...............................
|
||||
.............#.......................................................................................................................#......
|
||||
...........................................................#..............#...............................................................#.
|
||||
......................................................................................................#.....................................
|
||||
........................#........#..................#.................................#.....#...............................................
|
||||
.........#...............................#.....................................#............................................................
|
||||
..............................................................#...............................................#............#................
|
||||
............................................................................................................................................
|
||||
#............#...............................#..............................................................................................
|
||||
......................#......#...........................#.............................................................#....................
|
||||
............................................................................................................................................
|
||||
....#..............................#.........................#.....................#...............#........................................
|
||||
.............................................................................#....................................#.........................
|
||||
........#........#.......#.............................................................#..................................................#.
|
||||
........................................................................................................................#...................
|
||||
.#..............................#................#..............#......#....................................................................
|
||||
.........................................................................................................#......#...........................
|
||||
...............#...........#...........#....................#..............................................................#.....#..........
|
||||
....#..............................................................................#.....#..................................................
|
||||
............................................................................................................................................
|
||||
..........#.......................#..........#.............................#................................................................
|
||||
.............................................................................................................#.......#......................
|
||||
............................................................................................................................................
|
||||
......................................................#.........#...........................................................................
|
||||
...........................................#................................................#.................................#.............
|
||||
.........................#...........#...........#..........#................#..................................#...................#.....#.
|
||||
............#.......................................................#................#..................#...................................
|
||||
.....#...............#.........#.........................................#..................................................................
|
||||
.........................................................#..................................................................................
|
||||
..............................................#.............................................................................................
|
||||
..........#.................................................................................................#...............#...............
|
||||
.......................................#.......................#........................#........................#..........................
|
||||
..............#.........#......................................................#............................................................
|
||||
.............................#..............#.........#.......................................#......#...............................#......
|
||||
......................................................................#...................................................................#.
|
||||
....#.......................................................................................................................................
|
||||
.........#.............................................................................................................#....................
|
||||
...................................#....................#........................#............................................#.............
|
||||
.....................#.....................................................#................................................................
|
||||
......#.............................................................#...................#...............#...........................#.......
|
||||
...............#.............................#.................#..........................................................#.................
|
||||
.................................#......#.........................................................#.........................................
|
||||
................................................................................#.................................#............#.........#..
|
||||
.......................................................#..............#.....................................................................
|
||||
...#......#..........#......#................................#............................................#.................................
|
||||
..................................................#...................................................................#.....................
|
||||
......................................................................................................#.....................................
|
||||
...................................................................#..........................................................#.............
|
||||
...................#....................#................#...............#..................................................................
|
||||
#..........................#..................................#......................#......................#......................#.......#
|
||||
.................................................#..........................................................................................
|
||||
...............................#....................................................................#............#..........................
|
||||
.............................................................................................#............................#.................
|
||||
..........#.............#.................................................#.............................................................#...
|
||||
.#................#........................#...................................#............................................................
|
||||
................................................#...........................................................................................
|
||||
...........................................................#............................................#...................................
|
||||
.......#.......#....................................#...................................#...................................................
|
||||
.................................#.............................#...................................#..........#........#....................
|
||||
...........................#...........#......#...............................................#..................................#..........
|
||||
..#.....................................................#.................#......#..........................................................
|
||||
..................#................................................#....................................................................#...
|
||||
............................................................................................................................................
|
||||
...........................................................#.................#........#.....................................................
|
||||
#...............................#..........#.............................................................................#..................
|
||||
.......#.................#............................................#.........................#...........#.......................#.......
|
||||
............................................................................................................................................
|
||||
.............#...................................#..........................................................................................
|
||||
................................................................................#...........................................................
|
||||
.#...............#.............#..............................................................#...................................#.......#.
|
||||
.......................................................................................#..............................#.....................
|
||||
......................................#................................................................#.....#........................#.....
|
||||
...........................#..........................#.....................................................................................
|
||||
........#...................................#.............................................................................#.................
|
||||
..............#............................................#....................................#...........................................
|
||||
......................#...................................................................#.................................................
|
||||
..................................#..................................#......#...............................................................
|
||||
.............................................................................................................................#..............
|
||||
.#...............................................#....................................................#............#................#.......
|
||||
............#..........................#.........................#..........................................................................
|
||||
........................#....................#.............................................................................................#
|
||||
........................................................................................#.................#..............#..................
|
||||
............................................................................................................................................
|
||||
..............................................................#.......#..............................................#......................
|
||||
........#.....................#.....#.............................................................#....................................#....
|
||||
......................#...................................#.......#.........................................................................
|
||||
..#.............#...........................#.....................................#...........................#.............#...............
|
||||
1
day11/rust/.gitignore
vendored
Normal file
1
day11/rust/.gitignore
vendored
Normal file
@@ -0,0 +1 @@
|
||||
target
|
||||
7
day11/rust/Cargo.lock
generated
Normal file
7
day11/rust/Cargo.lock
generated
Normal file
@@ -0,0 +1,7 @@
|
||||
# This file is automatically @generated by Cargo.
|
||||
# It is not intended for manual editing.
|
||||
version = 3
|
||||
|
||||
[[package]]
|
||||
name = "rust"
|
||||
version = "0.1.0"
|
||||
8
day11/rust/Cargo.toml
Normal file
8
day11/rust/Cargo.toml
Normal file
@@ -0,0 +1,8 @@
|
||||
[package]
|
||||
name = "rust"
|
||||
version = "0.1.0"
|
||||
edition = "2021"
|
||||
|
||||
# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html
|
||||
|
||||
[dependencies]
|
||||
126
day11/rust/src/main.rs
Normal file
126
day11/rust/src/main.rs
Normal file
@@ -0,0 +1,126 @@
|
||||
enum Tile {
|
||||
Empty,
|
||||
Galaxy,
|
||||
}
|
||||
|
||||
#[derive(Clone)]
|
||||
#[derive(Debug)]
|
||||
struct Position {
|
||||
x: usize,
|
||||
y: usize,
|
||||
}
|
||||
|
||||
fn main() {
|
||||
let stdin = std::io::stdin();
|
||||
|
||||
let mut universe = Vec::new();
|
||||
|
||||
for line in stdin.lines() {
|
||||
let line = line.unwrap();
|
||||
|
||||
let row: Vec<_> = line
|
||||
.chars()
|
||||
.map(|e| match e {
|
||||
'.' => Tile::Empty,
|
||||
'#' => Tile::Galaxy,
|
||||
_ => unreachable!(),
|
||||
})
|
||||
.collect();
|
||||
|
||||
universe.push(row);
|
||||
}
|
||||
|
||||
let mut original_galaxies = Vec::new();
|
||||
|
||||
for i in 0..universe.len() {
|
||||
for j in 0..universe[i].len() {
|
||||
if let Tile::Galaxy = universe[i][j] {
|
||||
original_galaxies.push(Position { x: j, y: i })
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
let mut galaxies = original_galaxies.clone();
|
||||
|
||||
expand_universe(&universe, &mut galaxies, 2);
|
||||
|
||||
let mut part1 = 0;
|
||||
|
||||
for i in 0..galaxies.len() {
|
||||
for j in i..galaxies.len() {
|
||||
part1 += galaxies[i].x.abs_diff(galaxies[j].x);
|
||||
part1 += galaxies[i].y.abs_diff(galaxies[j].y);
|
||||
}
|
||||
}
|
||||
|
||||
println!("{}", part1);
|
||||
|
||||
let mut galaxies = original_galaxies.clone();
|
||||
|
||||
expand_universe(&universe, &mut galaxies, 1_000_000);
|
||||
|
||||
let mut part2 = 0;
|
||||
|
||||
for i in 0..galaxies.len() {
|
||||
for j in i..galaxies.len() {
|
||||
part2 += galaxies[i].x.abs_diff(galaxies[j].x);
|
||||
part2 += galaxies[i].y.abs_diff(galaxies[j].y);
|
||||
}
|
||||
}
|
||||
|
||||
println!("{}", part2);
|
||||
}
|
||||
|
||||
fn expand_universe(
|
||||
universe: &Vec<Vec<Tile>>,
|
||||
galaxies: &mut Vec<Position>,
|
||||
expansion_rate: usize,
|
||||
) -> () {
|
||||
let mut galaxy_offsets = Vec::new();
|
||||
|
||||
for _ in 0..galaxies.len() {
|
||||
galaxy_offsets.push(Position { x: 0, y: 0 });
|
||||
}
|
||||
|
||||
for i in 0..universe.len() {
|
||||
if universe[i].iter().all(|e| match e {
|
||||
Tile::Empty => true,
|
||||
_ => false,
|
||||
}) {
|
||||
for (j, galaxy) in galaxies.iter().enumerate() {
|
||||
if galaxy.y > i {
|
||||
galaxy_offsets[j].y += expansion_rate - 1;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
let mut columns = Vec::new();
|
||||
|
||||
for i in 0..universe[0].len() {
|
||||
let mut column = Vec::new();
|
||||
for j in 0..universe.len() {
|
||||
column.push(&universe[j][i]);
|
||||
}
|
||||
columns.push(column);
|
||||
}
|
||||
|
||||
for i in 0..columns.len() {
|
||||
if columns[i].iter().all(|e| match e {
|
||||
Tile::Empty => true,
|
||||
_ => false,
|
||||
}) {
|
||||
for (j, galaxy) in galaxies.iter().enumerate() {
|
||||
if galaxy.x > i {
|
||||
galaxy_offsets[j].x += expansion_rate - 1;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
for (i, galaxy) in galaxies.iter_mut().enumerate() {
|
||||
galaxy.x += galaxy_offsets[i].x;
|
||||
galaxy.y += galaxy_offsets[i].y;
|
||||
}
|
||||
}
|
||||
10
day11/sample.txt
Normal file
10
day11/sample.txt
Normal file
@@ -0,0 +1,10 @@
|
||||
...#......
|
||||
.......#..
|
||||
#.........
|
||||
..........
|
||||
......#...
|
||||
.#........
|
||||
.........#
|
||||
..........
|
||||
.......#..
|
||||
#...#.....
|
||||
BIN
day13/c/day13
Executable file
BIN
day13/c/day13
Executable file
Binary file not shown.
171
day13/c/day13.c
Normal file
171
day13/c/day13.c
Normal file
@@ -0,0 +1,171 @@
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
#include <string.h>
|
||||
|
||||
#define LINE_MAX_LENGTH 256
|
||||
#define MAX_PATTERNS 256
|
||||
#define min(a,b) ((a) < (b) ? (a) : (b))
|
||||
|
||||
typedef enum tile {
|
||||
ASH,
|
||||
ROCK,
|
||||
} tile_t;
|
||||
|
||||
typedef struct pattern {
|
||||
tile_t map[LINE_MAX_LENGTH][LINE_MAX_LENGTH];
|
||||
int x;
|
||||
int y;
|
||||
} pattern_t;
|
||||
|
||||
int symmetric(pattern_t *patterns, int patterns_num);
|
||||
|
||||
int main() {
|
||||
char *p, *buf, c;
|
||||
|
||||
buf = (char *)malloc(LINE_MAX_LENGTH);
|
||||
memset(buf, 0, LINE_MAX_LENGTH);
|
||||
p = buf;
|
||||
|
||||
pattern_t *patterns;
|
||||
patterns = (pattern_t*)malloc(MAX_PATTERNS * sizeof(pattern_t));
|
||||
memset(patterns, 0, MAX_PATTERNS * sizeof(pattern_t));
|
||||
int x = 0, y = 0, patterns_num = 0;
|
||||
|
||||
while ((c = getchar()) != EOF) {
|
||||
*p++ = c;
|
||||
if (c == '\n') {
|
||||
p = buf;
|
||||
|
||||
if (*p == '\n') {
|
||||
patterns[patterns_num].x = x;
|
||||
patterns[patterns_num].y = y;
|
||||
patterns_num++;
|
||||
y = 0;
|
||||
memset(buf, 0, LINE_MAX_LENGTH);
|
||||
continue;
|
||||
}
|
||||
|
||||
x = 0;
|
||||
while (*p != '\n') {
|
||||
switch (*p) {
|
||||
case '.':
|
||||
patterns[patterns_num].map[x][y] = ASH;
|
||||
break;
|
||||
case '#':
|
||||
patterns[patterns_num].map[x][y] = ROCK;
|
||||
break;
|
||||
}
|
||||
x++;
|
||||
p++;
|
||||
}
|
||||
y++;
|
||||
memset(buf, 0, LINE_MAX_LENGTH);
|
||||
p = buf;
|
||||
}
|
||||
}
|
||||
|
||||
int part1 = symmetric(patterns, patterns_num);
|
||||
printf("%i\n", part1);
|
||||
|
||||
int part2 = 0;
|
||||
int symmetric_offset = 0;
|
||||
for (int i = 0; i < patterns_num; i++) {
|
||||
for (int j = 1; j < patterns[i].x; j++) {
|
||||
int mind = min(j, patterns[i].x - j);
|
||||
symmetric_offset = 0;
|
||||
for (int k = 0; k < mind; k++) {
|
||||
for (int l = 0; l < patterns[i].y; l++) {
|
||||
if (patterns[i].map[j - k - 1][l] != patterns[i].map[j + k][l]) {
|
||||
symmetric_offset++;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if (symmetric_offset == 1) {
|
||||
part2 += j;
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
if (symmetric_offset == 1) {
|
||||
continue;
|
||||
}
|
||||
|
||||
for (int j = 1; j < patterns[i].y; j++) {
|
||||
int mind = min(j, patterns[i].y - j);
|
||||
symmetric_offset = 0;
|
||||
for (int k = 0; k < mind; k++) {
|
||||
for (int l = 0; l < patterns[i].x; l++) {
|
||||
if (patterns[i].map[l][j - k - 1] != patterns[i].map[l][j + k]) {
|
||||
symmetric_offset++;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if (symmetric_offset == 1) {
|
||||
part2 += 100 * j;
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
printf("%i\n", part2);
|
||||
|
||||
free(buf);
|
||||
free(patterns);
|
||||
}
|
||||
|
||||
int symmetric(pattern_t *patterns, int patterns_num) {
|
||||
int sum = 0;
|
||||
int symmetric = 1;
|
||||
for (int i = 0; i < patterns_num; i++) {
|
||||
for (int j = 1; j < patterns[i].x; j++) {
|
||||
int mind = min(j, patterns[i].x - j);
|
||||
symmetric = 1;
|
||||
for (int k = 0; k < mind; k++) {
|
||||
for (int l = 0; l < patterns[i].y; l++) {
|
||||
if (patterns[i].map[j - k - 1][l] != patterns[i].map[j + k][l]) {
|
||||
symmetric = 0;
|
||||
break;
|
||||
}
|
||||
}
|
||||
if (!symmetric) {
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
if (symmetric) {
|
||||
sum += j;
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
if (symmetric) {
|
||||
continue;
|
||||
}
|
||||
|
||||
for (int j = 1; j < patterns[i].y; j++) {
|
||||
int mind = min(j, patterns[i].y - j);
|
||||
symmetric = 1;
|
||||
|
||||
for (int k = 0; k < mind; k++) {
|
||||
for (int l = 0; l < patterns[i].x; l++) {
|
||||
if (patterns[i].map[l][j - k - 1] != patterns[i].map[l][j + k]) {
|
||||
symmetric = 0;
|
||||
break;
|
||||
}
|
||||
}
|
||||
if (!symmetric) {
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
if (symmetric) {
|
||||
sum += 100 * j;
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return sum;
|
||||
}
|
||||
1326
day13/input.txt
Normal file
1326
day13/input.txt
Normal file
File diff suppressed because it is too large
Load Diff
16
day13/sample.txt
Normal file
16
day13/sample.txt
Normal file
@@ -0,0 +1,16 @@
|
||||
#.##..##.
|
||||
..#.##.#.
|
||||
##......#
|
||||
##......#
|
||||
..#.##.#.
|
||||
..##..##.
|
||||
#.#.##.#.
|
||||
|
||||
#...##..#
|
||||
#....#..#
|
||||
..##..###
|
||||
#####.##.
|
||||
#####.##.
|
||||
..##..###
|
||||
#....#..#
|
||||
|
||||
BIN
day14/c/day14
Executable file
BIN
day14/c/day14
Executable file
Binary file not shown.
204
day14/c/day14.c
Normal file
204
day14/c/day14.c
Normal file
@@ -0,0 +1,204 @@
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
#include <string.h>
|
||||
|
||||
#define LINE_MAX_LENGTH 256
|
||||
#define MAX_ROUNDED_ROCKS 8*1024
|
||||
#define MAX_HISTORY_SIZE 2048
|
||||
#define abs(a) ((a) > 0 ? (a) : -(a))
|
||||
#define CYCLES 1000000000
|
||||
|
||||
typedef enum tile {
|
||||
EMPTY,
|
||||
ROUNDED_ROCK,
|
||||
CUBE_ROCK,
|
||||
} tile_t;
|
||||
|
||||
typedef struct position {
|
||||
int x;
|
||||
int y;
|
||||
} position_t;
|
||||
|
||||
void tilt(tile_t map[LINE_MAX_LENGTH][LINE_MAX_LENGTH], int x, int y, int dir[2]);
|
||||
|
||||
int main() {
|
||||
char *p, *buf, c;
|
||||
|
||||
buf = (char *)malloc(LINE_MAX_LENGTH);
|
||||
memset(buf, 0, LINE_MAX_LENGTH);
|
||||
p = buf;
|
||||
|
||||
position_t rocks[MAX_ROUNDED_ROCKS];
|
||||
int rocks_num = 0, x = 0, y = 0;
|
||||
|
||||
tile_t map[LINE_MAX_LENGTH][LINE_MAX_LENGTH];
|
||||
|
||||
while ((c = getchar()) != EOF) {
|
||||
*p++ = c;
|
||||
if (c == '\n') {
|
||||
x = 0;
|
||||
p = buf;
|
||||
while (*p != '\n') {
|
||||
switch (*p) {
|
||||
case '.':
|
||||
map[x][y] = EMPTY;
|
||||
break;
|
||||
case '#':
|
||||
map[x][y] = CUBE_ROCK;
|
||||
break;
|
||||
case 'O':
|
||||
map[x][y] = ROUNDED_ROCK;
|
||||
rocks[rocks_num].x = x;
|
||||
rocks[rocks_num].y = y;
|
||||
rocks_num++;
|
||||
break;
|
||||
}
|
||||
p++;
|
||||
x++;
|
||||
}
|
||||
|
||||
y++;
|
||||
memset(buf, 0, LINE_MAX_LENGTH);
|
||||
p = buf;
|
||||
}
|
||||
}
|
||||
|
||||
int dir[2] = {0, -1};
|
||||
tilt(map, x, y, dir);
|
||||
|
||||
|
||||
int part1 = 0;
|
||||
for (int i = 0; i < y; i++) {
|
||||
for (int j = 0; j < x; j++) {
|
||||
if (map[j][i] == ROUNDED_ROCK) {
|
||||
part1 += y - i;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
printf("%i\n", part1);
|
||||
|
||||
tile_t ***history = (tile_t***)malloc(MAX_HISTORY_SIZE * sizeof(tile_t**));
|
||||
for (int i = 0; i < MAX_HISTORY_SIZE; i++) {
|
||||
history[i] = malloc(LINE_MAX_LENGTH * LINE_MAX_LENGTH * sizeof(tile_t));
|
||||
}
|
||||
int history_num = 0;
|
||||
|
||||
int offset = 0, period = 0;
|
||||
for (int i = 0; i < CYCLES; i++) {
|
||||
int found = 0;
|
||||
for (int j = 0; j < history_num; j++) {
|
||||
if (!memcmp(map, history[j], LINE_MAX_LENGTH * LINE_MAX_LENGTH * sizeof(tile_t))) {
|
||||
offset = j;
|
||||
period = history_num - j;
|
||||
found = 1;
|
||||
break;
|
||||
}
|
||||
}
|
||||
if (!found) {
|
||||
memcpy(history[history_num], map, LINE_MAX_LENGTH * LINE_MAX_LENGTH * sizeof(tile_t));
|
||||
history_num++;
|
||||
}
|
||||
if (found) {
|
||||
break;
|
||||
}
|
||||
if (i != 0) {
|
||||
dir[0] = 0;
|
||||
dir[1] = -1;
|
||||
tilt(map, x, y, dir);
|
||||
}
|
||||
dir[0] = -1;
|
||||
dir[1] = 0;
|
||||
tilt(map, x, y, dir);
|
||||
dir[0] = 0;
|
||||
dir[1] = 1;
|
||||
tilt(map, x, y, dir);
|
||||
dir[0] = 1;
|
||||
dir[1] = 0;
|
||||
tilt(map, x, y, dir);
|
||||
}
|
||||
|
||||
for (int i = 0; i < (CYCLES - history_num) % period; i++) {
|
||||
dir[0] = 0;
|
||||
dir[1] = -1;
|
||||
tilt(map, x, y, dir);
|
||||
dir[0] = -1;
|
||||
dir[1] = 0;
|
||||
tilt(map, x, y, dir);
|
||||
dir[0] = 0;
|
||||
dir[1] = 1;
|
||||
tilt(map, x, y, dir);
|
||||
dir[0] = 1;
|
||||
dir[1] = 0;
|
||||
tilt(map, x, y, dir);
|
||||
}
|
||||
|
||||
int part2 = 0;
|
||||
for (int i = 0; i < y; i++) {
|
||||
for (int j = 0; j < x; j++) {
|
||||
if (map[j][i] == ROUNDED_ROCK) {
|
||||
part2 += y - i;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
printf("%i\n", part2);
|
||||
|
||||
for (int i = 0; i < MAX_HISTORY_SIZE; i++) {
|
||||
free(history[i]);
|
||||
}
|
||||
free(history);
|
||||
free(buf);
|
||||
}
|
||||
|
||||
void tilt(tile_t map[LINE_MAX_LENGTH][LINE_MAX_LENGTH], int x, int y, int dir[2]) {
|
||||
position_t start;
|
||||
int *iterate, iter_length;
|
||||
if (dir[0] == 1) {
|
||||
start.x = x - 1;
|
||||
start.y = 0;
|
||||
iterate = &start.y;
|
||||
iter_length = y;
|
||||
} else if (dir[0] == -1) {
|
||||
start.x = 0;
|
||||
start.y = 0;
|
||||
iterate = &start.y;
|
||||
iter_length = y;
|
||||
} else if (dir[1] == 1) {
|
||||
start.x = 0;
|
||||
start.y = y - 1;
|
||||
iterate = &start.x;
|
||||
iter_length = x;
|
||||
} else if (dir[1] == -1) {
|
||||
start.x = 0;
|
||||
start.y = 0;
|
||||
iterate = &start.x;
|
||||
iter_length = x;
|
||||
}
|
||||
|
||||
position_t to_put;
|
||||
for (int i = 0; i < iter_length; i++) {
|
||||
*iterate = i;
|
||||
memcpy(&to_put, &start, sizeof(position_t));
|
||||
int *iterate_secondary = iter_length == x ? &to_put.y : &to_put.x, iter_length_secondary = iter_length == x ? y : x;
|
||||
for (int j = 0; j < iter_length_secondary; j++) {
|
||||
int cx = start.x - dir[0] * j;
|
||||
int cy = start.y - dir[1] * j;
|
||||
tile_t current_tile = map[cx][cy];
|
||||
switch (current_tile) {
|
||||
case EMPTY:
|
||||
break;
|
||||
case ROUNDED_ROCK:
|
||||
map[cx][cy] = EMPTY;
|
||||
map[to_put.x][to_put.y] = ROUNDED_ROCK;
|
||||
to_put.x -= dir[0];
|
||||
to_put.y -= dir[1];
|
||||
break;
|
||||
case CUBE_ROCK:
|
||||
to_put.x = cx - dir[0];
|
||||
to_put.y = cy - dir[1];
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
100
day14/input.txt
Normal file
100
day14/input.txt
Normal file
@@ -0,0 +1,100 @@
|
||||
...#.#.O....#.#.OO.OOO.O..O.......O#OO#.#..#....O...#.....O.O#..O..OO..O.#...#O..#...O...##O...OO...
|
||||
#O....O#..O.#.#..O#...#O.O....#O.#.#O#........O...O..#.OOO#O#.......OO##O.#.OO.O.#...##.##....O#..O#
|
||||
.O.......O.O.O.O..O.O.....#....O#..#.#O.#OO...#O.O#.O#..#O...#...O.O.......#.O....O.#..#.O##O#..O...
|
||||
...O....#.OO..#..OO#..##....#O.......OOOOOO...OO..#...#.O..O....#O..OO.#O...#O#...O..O#..OO....#....
|
||||
..O...##OOO....#..OO.OO#O##..#.#........O#.#.....#OO...#............#.###..#.#O...#..O.#O#.O#O.....#
|
||||
...............O.....##..O...O#.O#........#.O.#..#...#..O..O.#...#......#......O.OO.OOO.#.O.....O##.
|
||||
......#..#..###.OO.#......O..O.O##O..O.....OO.#.OO....O.....OO#O..O....#.....#.#.O#..O..O.OO.O#O.O.#
|
||||
##O.....O.#.#O...#.#O###....#.O#.#..#..O.#O........O.OO..#..#O#.O#..OO..#.O.##O....#.##O.O.......##.
|
||||
O#...###...O..#...#......O#.OO.....#...OOO...#.#O.#...##..OO#.......#OO.....#...O...#.#O.........O.O
|
||||
..O....O....OO..O.O.O........#.O#..O.#..#..OO#.OO..#.O...O..#...O..##..O........O##..........OOO..OO
|
||||
....##......#.#.O.O#O##.#....#..O#............#..#...#......#O.OO#....O.......O###....O...........OO
|
||||
.O.OOO..O#....O...O..#.O#.#O.O...#.O..O#...OO#.#....#OO.#........#O.......O...#O......O...O....#...#
|
||||
.#....#O...##..#.#..........O..#O........OOO.......O.OO.##...#..........#......#.O##.#O#OO#OO..#..O.
|
||||
......#O...#.#.......O........#O....#O..##....O......O.#.O..#OO............O##O....#O.OO#..O#..O#...
|
||||
..OO.....O#O..#OOOO#O.##.........O..#OO#......O.OO.....O......OO..O...O..O....O..O#O.......O..O.O#..
|
||||
....O...OO....##.....OOO...O#O.#.O...O.....#........#.#O#.....O.O.OO.###.#.OO#OO....O.....O..#.#O...
|
||||
.OO#..O#O#O...#..O.O....O#.O.#........O.O..O....#O#....#.#.O#.#...O.O..O..#..#...OO#O......#O.O..O.#
|
||||
OO...O.O.#..#....#...#O.O##O#...#............##.O..OOO....O..OO....#OO....O.#....O#.O........OO..#..
|
||||
..O#.OO#.#O#..O.......O.##.O.#....OO#.#O#.##.O..O#..####....#..#......#...##.O##...O....O..#.#......
|
||||
#O.O#.....#....O...O.O..O.O.O#O.O#....#..O...#.O.#O...#..#.#O.....#O..##...O.......O.....O..OO#OO##.
|
||||
..O.#..#...O....#.##.#.O......#.#.##.......#.O..##O#.#O.OOO..O...#O......#..O.....O.OO...O#.O.#OO#.O
|
||||
.#..OO#.......OO....O.##...O......O.OO#.O......#O..O#..#..O.O..O.#..OO.O.#O..O..#......O...O....O#..
|
||||
O....#.#O..O#...#..##..##.O.O.O..O.O#...O#..#O.O......#O.......O..O.O...#.#O..OO#.#.....#O#...O..#.O
|
||||
...O...O.O.O.OO..O....O..O..O##..O.........O#O..O.#...#.O..O.#........#...O........O#.#.O..O.....#..
|
||||
OO....O#...........#OO......O.....O...#...OO....OO..O.........O.#......##O....#...O##....O.#...#...#
|
||||
#OO#....#......OO.O....O...#..O...#.OOOO..OOO.O.O...O#.......O....#O#O.O#O......#...#...OO#.O...#..#
|
||||
....O#.#...O..#.................#.#...O...O...O.O#.##..O.#.#....####..OO....O.......#.OO.O....#...#.
|
||||
.....O.#.#O..#O...#OO....OO...O#..O...O..#O..O....#.#O..#.......O...O.O.....#.##.#O.OO..#.#....###..
|
||||
.#O..#...#...#.#.O.#O.#OO..#.#..#O#.#.#O#.O#O#..##..#...#O#.#..#.OO#..#..#..O...O...O..O...#.O....O.
|
||||
..O.....#....#O#OO#O.....O.....O...OO.O......OO..O....O...#....O....#...OO....O..O...#...###O.....#.
|
||||
##..##...#OOO...#.OO...#.#.O#.O.........O.O.#.O..O.OO#.O......#.###...#..#O.#....#...#.O..##...#O...
|
||||
.O.#...O.O....O.......O...#O.....O......OO..OOO##.#...##OO.O......#....O..#..#.##.OO.......#O...#OO.
|
||||
...#...O#..O.#.OO.#.OO..O.#O.#.O.#...O#....O#.O#......OO.#....#..#..#..#....O.#....##...............
|
||||
.O.O#....#.#.....O...#.O#O#.......#.#O..OO.O...#....#.....O.#.#.#..#...#...##..O.O...#O..O.#..#O....
|
||||
.#......O..O#...O.O.##O..#.OOOO.O#O....O#...#O..OO.#.#O......#..O..O.OO#OOO#O#.O.......OO.....O...#O
|
||||
O##.O..OOO.#..O......#...#O#.O.O#..O.OO..#......O.O.O..O.O.OO..#....O.#O...O#.#..#..O.#...##O.O.....
|
||||
.#OO#....#.....#..OO.OO...##.O......OOO.#O..O#.O.O.........O#.O.#.#...#..##...#O.O..OO.O#.#..O..O.O.
|
||||
.O.....#.O#....O#.....#.O..O..O#..#..OOO#O....#OOOOO.#.#.........O#..O.#....#.#....O.#..##..#.......
|
||||
..O.#OO....#O.#...#O...#.O#..#.O....O.#..O....O#.....O.OO..OO.OO#.#..#..#O.O.#...O....OO...O.#..O..O
|
||||
.O.OO#...O#.OO....#.O....O.###...#..O.....O....#.O..O.#O.O.....#....#O#O...#..O...O........O...#....
|
||||
#...#...#..O..#.##.#.....O#..#O.##.O...O...#....O.O.O..O.O........O.O.O.....O..#.......#...O..O.#.#O
|
||||
#O...#...O.#....#.O.....OOO..O...OO#OO#.......#O.##...#.O#O#....#.....O#..OO.#.#.O.O..O.#OO.O.#..O..
|
||||
......O.......O.#.O.#.O...........O.O.OO#....#OO........O#.......OO.O..#O...#....O#..O....OO..O##...
|
||||
.##..O..#O...O.O....#O#..OO#O.#....#O.OO#O....#.....#...#.#OO#.OO.#.O.O.O.OO.#O.O.#.O....#O.O.O..O..
|
||||
O#..O#O##.O....O..#......O....#..O##O.O#...O...O...OO#..#OO...O##.#....O#.O..O.......#..#......#O..#
|
||||
O.OO..O..#.O..O#OO#O.....#O..O..#...#.OO.O..O...........O...O...OO##.#..O..#.#.OO.#.#...O.O......O.O
|
||||
.O.O##.O....#O.O...O#.#..O....#O.....O..O#OO....OO##.#.O..#O.O...O..O.O...#O.OO.........#.##OO#..#..
|
||||
..OO....O.....#....O.....O...OOO#...#.O.........O.O..OOO.###O.#.......#.#...O.OO.#..O.....#O.....#..
|
||||
O...##O...O..##..#.#...#.#O#.O...#.#.O..O....##......#...#.O..O...OO.#...OOO#OO...O.O#O..OO.O##O..O.
|
||||
..#.OO.#.##..O....#...OO.#O.......O.O#...O..#.#O..O.###O#.#.O.O...O.#O.#..#.O..O#O#..O.........#.#..
|
||||
O.#.O##.......OO#....O#.......O..O.....#.........O.O.....#O.......#O..#.O...#....O.#....#......O.O.#
|
||||
.OO.O...O.......#O#....#O#...#.........O..O.#.OO#.OO.O#...#O...O..#..O##O.#...O#..O.OO.O...#OO.##.#.
|
||||
...O.O...OOO.O......#..O...#.##.O..O..#...O.O...#.O.O..OO..OO..#....O.O#..#...O.OO.#.....#...OO#...#
|
||||
.#............#O.OO..O#.....O..#O.#O.##O....O.O....O..O#..O..O.#..O.#.O.#.O.#..#O.#.OO.O......##...O
|
||||
#.....O.#..O.O........O#O#OO..OO.....#.#....OO##......O.O.##..##.#.O...O.#.#O......O..##.#.#.#..#O..
|
||||
##.#.O..O...O..OO...O....O.O..O#...OO....OO#.#...#.#....OO#..........O..O...O...O........#..O##.#.#.
|
||||
..OO.#..#.OO..#O..#.O...OO.O...O....#..OO....#OO..#........#...O..........#..O...OO.O.......#.#..##.
|
||||
.#.#...#O.O.#.O..O.OO.OO#..OO#OOO#O....O..O#..OO.O..##..#.#....OOOOO#....OO..O....#..O..............
|
||||
...O#.OO......O.#.O.#.#O.OOO...#OO..#....#.O.O.O.......#...##...O...OOO..##...O....O...O.#...O.O...O
|
||||
..O...O..#.O.....#.#..##.......####...##.......O...O#.##....O.#..OO....#.#.O...##O.#O.###.OO#....O.O
|
||||
.O#..#....OO...O.O.......O#OO..O#.O.O..#......#..O.#..#O......OO.O...O.....O........O#.#O.#.#.##.O#.
|
||||
..O....O.#...#..##..O...#.O#..OO...O.......#OOO......#O..OO...O...#..O...##O.#...#.#.##...O...#.OO..
|
||||
O.#..#...O#OO.O#.O..O.....O.O..#.#.##....O.O..O......OO.O.#.....#....#.##...#...O..O........#......#
|
||||
.OO.OO.........#...#.#O...#..#..#.###O....#...OO#......#O.O..........#O...#.#.#O#..........#.O#...OO
|
||||
##.#..#O#OO.#.....O......#....O..#.O#..#.OO.........#.......#.#..#..O.O#OO.###.O.#.#O..##....O.O..O#
|
||||
#...O...O.......O#.O.#..#O#.O...O...O...O.O.#.O....O###..#.O..O.....O..OO#...O.#...#....O.#O..OO.O..
|
||||
#O...O...O.##..#.#OO.....#O.#..O....#O.O....O.....#.O.....#.O.O....#.......O.#.O..#.O.##....O..O..O#
|
||||
O..O.....#O..O...O........O..#.#..........##O#..#..O.#.#OOO..#..O...O..O..#.O....O...O...#...#...O..
|
||||
#...O.......O#..#.O#.O.....#....O#O......O..O.....#.....O...#...O...#O..#.O..#..#....O....##O#.....#
|
||||
O...O..#O#.OO..##..#.......O.........#......#...#..O.O..#..#O..O..O.OO......O#OO.#..O#....#.O.#.....
|
||||
.....#.OOO..OOO....O...#O....O.#.O.#.#O..#O.......O#..O.#O.#.#..#......O#O###..#.#.O..OO.O#.##.OO#.#
|
||||
O...#..O#.##O..#...#.....O...O.O............O#.....#.O....O#....O#.#O#O..O#.OO..........#.O.#OOO.O..
|
||||
......#..#...O..O....OO#.O...OO..O....O..##O#..O#..O..##.O..#....##OO.....#..O#.O....#O.#....##.O...
|
||||
.#..O.O..#..........O...O...O.#..O.#......O.O.....OO#..#...O.....O##..O.O..#.OO.#O.O....O...O..#..#.
|
||||
.OO.#..O......#........#.#.O...#..........O..O.O.......OO..##O.....#...O...#..#O###..O..O.OOOOO.#.O.
|
||||
.O..#..O..O...O..#O......OOO.O#..O#.#O...O#O.#...O....O..OO.#....#...O#................O.#O..O.#O..#
|
||||
......O..O...##..O..##.O.####..OO.O.......#.#O..O#..O#O.......#..O.....##........#..O..O.#...O....OO
|
||||
.....O.O.O.....O..OO..#O..O#.#OO....#O...#O#.#.OO.#..O...O.#.....#.#O#..O#...OO##.........##...##..#
|
||||
....O..OOOO..O.O...#.....#.#..OOO...#OO.O#..O..O....#O.......#.O..OOO......OO...#.O#............O#.O
|
||||
......O....#...#.#..O.O#.#...O..O.OO##.O..O#OO##...#.#..O.OO.........#..##O#...O.#..O.#OO.#O#...##O.
|
||||
O..##.O...O..#.O.O.O..O.........#..O...#..O.O.##O#.O..#.#.....#..#O#..#.OOO#.O..O...OO#.O...O#......
|
||||
.O.....O......O.......O#..O.OOOO..O..OO.O#.##.OO#O#.O......#...#.........O..O#...#O..#..#.O...O.#OO.
|
||||
#O.O...#..OO.#...O.O#....#..#...#OOO##.O.OO#.....#.O#.O..O.#O#O.O.O..........O#.O#.#O###O..#..#.#OO#
|
||||
#O###.O..O..O......#.O#.#....OO..O.O#....#...#...#.##...OO..O.#OO........O....O..O....OO......O..O.#
|
||||
.O#O..O...#OOO...O.O...#.O#......#......#O.....O.#.#.O.#....O#.#O..#...#..#...OO#.....OOO....OO.....
|
||||
..O.#.O....OO......O...O..##.O........#.O.#O.#...O...O.#.##OO.#O......O...O..O.O.O.##..O#.##.#.#O...
|
||||
.#OO#.#.O#O....O.O....OO#....##.....#.##O..O...OO.....#..O.#....O#.......O....OO.OOO.#...#..O.O.#.OO
|
||||
.O...O....#.O..O.#..#.........O.#O#.#...O..#O.O.O..O##.....OO..O.O..OO..O..#..#.#.O..#O..O.OO##....O
|
||||
.##...#O.O..OO..O..#.#O.O.OO.#..#.OOOO.....O...O.O.O#...O#.#.O.............O..O...#.#..........OO#.#
|
||||
.#....##O....##O..#.O.O..#..O##....#.#.OO........O.O#..#........#OO........O...#.OO..#.........#....
|
||||
.##OO..#O.#.O..OO.#...#O#.....O....O.#....#O..O#O.#.O..##.O.O.....#.#...#.O..OO....O....#.#.#.......
|
||||
O.O.O.#....#.OO.#...#...O..#.OO..#..O..#...O.OO.O...##...OO.O#O..O.OO.O##.....#..O#..#O....O.O#OO.#.
|
||||
.#.O....#.#....#..O.O....OO......O......O.#...O...#.O.O..#.#.....O..#O.O.O..OOO#.O#..O...O#..OO.....
|
||||
#.#O..#....#.....O.#....#......O.O..O.O.OO.O#...O.#.O.O...#....O...#..#...O.#.O..#.O...OO.#.#O###.OO
|
||||
..#..O..#O##..#.....O...#..O...OO..#.#.O.#.O.O.....O..O#O#..O......#...#O.O.OO..O............#....#.
|
||||
....O#....O#O###O.O..#.#..O.#.O.#.O....O........#O.OOO......O.OO....O.O.O.....##.O#....##O.#.OO..O.#
|
||||
..#.O...OO.#O.#..OO.##..#...O#..O#..#O.O..#......O.....##....O...O.O#OO#O.......O##OOO.OO.O...O.#..#
|
||||
O......#.O.....OO.OO.O...O.#O..O...O.#.#...#...O...#.OO.O.#.#OO.....#.O.#....OOO........##...##.##O.
|
||||
#O...#....#...##O.#......O#...#O..........##O..#.O.#O#..#...OO.O....O..##..#...#...#..O..O....O..O#.
|
||||
...OO....O#..O..#....O.#.#.....OO.#..#O..OO.#.#.#.#......O...O..#.#..##.....#...O.##.....O#.#..O#O..
|
||||
10
day14/sample.txt
Normal file
10
day14/sample.txt
Normal file
@@ -0,0 +1,10 @@
|
||||
O....#....
|
||||
O.OO#....#
|
||||
.....##...
|
||||
OO.#O....O
|
||||
.O.....O#.
|
||||
O.#..O.#.#
|
||||
..O..#O..O
|
||||
.......O..
|
||||
#....###..
|
||||
#OO..#....
|
||||
BIN
day15/c/day15
Executable file
BIN
day15/c/day15
Executable file
Binary file not shown.
112
day15/c/day15.c
Normal file
112
day15/c/day15.c
Normal file
@@ -0,0 +1,112 @@
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
#include <string.h>
|
||||
|
||||
#define LINE_MAX_LENGTH 32*1024
|
||||
#define STRBUF_SIZE 64
|
||||
#define NUM_BOXES 256
|
||||
#define MAX_LENS_PER_BOX 32
|
||||
#define NUM_0_CHARCODE 48
|
||||
|
||||
typedef struct lens {
|
||||
char label[STRBUF_SIZE];
|
||||
int label_len;
|
||||
int focal_length;
|
||||
} lens_t;
|
||||
|
||||
typedef struct box {
|
||||
lens_t lenses[MAX_LENS_PER_BOX];
|
||||
int lenses_num;
|
||||
} box_t;
|
||||
|
||||
int hash(char*, int);
|
||||
|
||||
int main() {
|
||||
char *p, *buf, c, *start;
|
||||
|
||||
buf = (char *)malloc(LINE_MAX_LENGTH);
|
||||
memset(buf, 0, LINE_MAX_LENGTH);
|
||||
p = buf;
|
||||
char strbuf[STRBUF_SIZE];
|
||||
memset(strbuf, 0, STRBUF_SIZE * sizeof(char));
|
||||
|
||||
box_t boxes[NUM_BOXES];
|
||||
memset(boxes, 0, NUM_BOXES * sizeof(box_t));
|
||||
|
||||
int sum = 0;
|
||||
while ((c = getchar()) != EOF) {
|
||||
*p++ = c;
|
||||
if (c == '\n') {
|
||||
p = buf;
|
||||
start = p;
|
||||
while (*p != '\0') {
|
||||
while (*p != ',' && *p != '\n') p++;
|
||||
strncpy(strbuf, start, p - start);
|
||||
sum += hash(strbuf, p - start);
|
||||
// Find = or -
|
||||
while (*p != '-' && *p != '=') p--;
|
||||
int box_num = hash(strbuf, p - start);
|
||||
if (*p == '-') {
|
||||
for (int i = 0; i < boxes[box_num].lenses_num; i++) {
|
||||
if (boxes[box_num].lenses[i].label_len == p - start && !strncmp(boxes[box_num].lenses[i].label, strbuf, p - start)) {
|
||||
for (int j = i; j < boxes[box_num].lenses_num - 1; j++) {
|
||||
memcpy(&boxes[box_num].lenses[j], &boxes[box_num].lenses[j + 1], sizeof(lens_t));
|
||||
}
|
||||
boxes[box_num].lenses_num--;
|
||||
break;
|
||||
}
|
||||
}
|
||||
p++;
|
||||
} else if (*p == '=') {
|
||||
int found = 0;
|
||||
int focal_length = *(p+1) - NUM_0_CHARCODE;
|
||||
for (int i = 0; i < boxes[box_num].lenses_num; i++) {
|
||||
if (boxes[box_num].lenses[i].label_len == p - start && !strncmp(boxes[box_num].lenses[i].label, strbuf, p - start)) {
|
||||
boxes[box_num].lenses[i].focal_length = focal_length;
|
||||
found = 1;
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
if (!found) {
|
||||
boxes[box_num].lenses[boxes[box_num].lenses_num].label_len = p - start;
|
||||
boxes[box_num].lenses[boxes[box_num].lenses_num].focal_length = focal_length;
|
||||
strncpy(boxes[box_num].lenses[boxes[box_num].lenses_num].label, strbuf, p - start);
|
||||
boxes[box_num].lenses_num++;
|
||||
}
|
||||
p++;
|
||||
p++;
|
||||
}
|
||||
|
||||
p++;
|
||||
start = p;
|
||||
memset(strbuf, 0, STRBUF_SIZE * sizeof(char));
|
||||
}
|
||||
memset(buf, 0, LINE_MAX_LENGTH);
|
||||
p = buf;
|
||||
}
|
||||
}
|
||||
|
||||
int part2 = 0;
|
||||
for (int i = 0; i < NUM_BOXES; i++) {
|
||||
for (int j = 0; j < boxes[i].lenses_num; j++) {
|
||||
part2 += (i+1) * (j+1) * boxes[i].lenses[j].focal_length;
|
||||
}
|
||||
}
|
||||
|
||||
printf("%i\n", sum);
|
||||
printf("%i\n", part2);
|
||||
free(buf);
|
||||
}
|
||||
|
||||
int hash(char *str, int len) {
|
||||
int current_value = 0;
|
||||
|
||||
for (int i = 0; i < len; i++) {
|
||||
current_value += str[i];
|
||||
current_value *= 17;
|
||||
current_value %= 256;
|
||||
}
|
||||
|
||||
return current_value;
|
||||
}
|
||||
1
day15/input.txt
Normal file
1
day15/input.txt
Normal file
File diff suppressed because one or more lines are too long
1
day15/sample.txt
Normal file
1
day15/sample.txt
Normal file
@@ -0,0 +1 @@
|
||||
rn=1,cm-,qp=3,cm=2,qp-,pc=4,ot=9,ab=5,pc-,pc=6,ot=7
|
||||
BIN
day16/c/day16
Executable file
BIN
day16/c/day16
Executable file
Binary file not shown.
208
day16/c/day16.c
Normal file
208
day16/c/day16.c
Normal file
@@ -0,0 +1,208 @@
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
#include <string.h>
|
||||
|
||||
#define LINE_MAX_LENGTH 256
|
||||
|
||||
typedef enum tile_type {
|
||||
EMPTY,
|
||||
MIRROR_LEFT_TO_UP,
|
||||
MIRROR_LEFT_TO_DOWN,
|
||||
SPLITTER_VERTICAL,
|
||||
SPLITTER_HORIZONTAL,
|
||||
} tile_type_t;
|
||||
|
||||
typedef enum light_direction {
|
||||
LEFT_TO_RIGHT,
|
||||
RIGHT_TO_LEFT,
|
||||
UP_TO_DOWN,
|
||||
DOWN_TO_UP,
|
||||
} light_direction_t;
|
||||
|
||||
typedef struct tile {
|
||||
tile_type_t type;
|
||||
light_direction_t lights[4];
|
||||
int lights_num;
|
||||
} tile_t;
|
||||
|
||||
void traverse_light(tile_t map[LINE_MAX_LENGTH][LINE_MAX_LENGTH], int x, int y, int entry_x, int entry_y, int dir[2]);
|
||||
int has_light(tile_t map[LINE_MAX_LENGTH][LINE_MAX_LENGTH], int x, int y, light_direction_t direction, int max_x, int max_y);
|
||||
light_direction_t dir_to_direction(int dir[2]);
|
||||
int count_energized(tile_t map[LINE_MAX_LENGTH][LINE_MAX_LENGTH], int x, int y);
|
||||
|
||||
int main() {
|
||||
char *p, *buf, c;
|
||||
|
||||
buf = (char *)malloc(LINE_MAX_LENGTH);
|
||||
memset(buf, 0, LINE_MAX_LENGTH);
|
||||
p = buf;
|
||||
|
||||
tile_t map[LINE_MAX_LENGTH][LINE_MAX_LENGTH];
|
||||
memset(map, 0, LINE_MAX_LENGTH * LINE_MAX_LENGTH * sizeof(tile_t));
|
||||
int x = 0, y = 0;
|
||||
|
||||
while ((c = getchar()) != EOF) {
|
||||
*p++ = c;
|
||||
if (c == '\n') {
|
||||
p = buf;
|
||||
x = 0;
|
||||
|
||||
while (*p != '\n') {
|
||||
switch (*p) {
|
||||
case '.':
|
||||
map[x][y].type = EMPTY;
|
||||
break;
|
||||
case '/':
|
||||
map[x][y].type = MIRROR_LEFT_TO_UP;
|
||||
break;
|
||||
case '\\':
|
||||
map[x][y].type = MIRROR_LEFT_TO_DOWN;
|
||||
break;
|
||||
case '|':
|
||||
map[x][y].type = SPLITTER_VERTICAL;
|
||||
break;
|
||||
case '-':
|
||||
map[x][y].type = SPLITTER_HORIZONTAL;
|
||||
break;
|
||||
}
|
||||
x++;
|
||||
p++;
|
||||
}
|
||||
y++;
|
||||
memset(buf, 0, LINE_MAX_LENGTH);
|
||||
p = buf;
|
||||
}
|
||||
}
|
||||
|
||||
tile_t map_cpy[LINE_MAX_LENGTH][LINE_MAX_LENGTH];
|
||||
memcpy(map_cpy, map, LINE_MAX_LENGTH * LINE_MAX_LENGTH * sizeof(tile_t));
|
||||
|
||||
int dir[2] = {1, 0};
|
||||
traverse_light(map_cpy, x, y, -1, 0, dir);
|
||||
int part1 = count_energized(map_cpy, x, y);
|
||||
|
||||
int max_energized = 0, energized;
|
||||
// LEFT COLUMN
|
||||
for (int i = 0; i < y; i++) {
|
||||
dir[0] = 1;
|
||||
dir[1] = 0;
|
||||
memcpy(map_cpy, map, LINE_MAX_LENGTH * LINE_MAX_LENGTH * sizeof(tile_t));
|
||||
traverse_light(map_cpy, x, y, -1, i, dir);
|
||||
energized = count_energized(map_cpy, x, y);
|
||||
|
||||
if (energized > max_energized) {
|
||||
max_energized = energized;
|
||||
}
|
||||
}
|
||||
// RIGHT COLUMN
|
||||
for (int i = 0; i < y; i++) {
|
||||
dir[0] = -1;
|
||||
dir[1] = 0;
|
||||
memcpy(map_cpy, map, LINE_MAX_LENGTH * LINE_MAX_LENGTH * sizeof(tile_t));
|
||||
traverse_light(map_cpy, x, y, x, i, dir);
|
||||
energized = count_energized(map_cpy, x, y);
|
||||
|
||||
if (energized > max_energized) {
|
||||
max_energized = energized;
|
||||
}
|
||||
}
|
||||
// TOP ROW
|
||||
for (int i = 0; i < x; i++) {
|
||||
dir[0] = 0;
|
||||
dir[1] = 1;
|
||||
memcpy(map_cpy, map, LINE_MAX_LENGTH * LINE_MAX_LENGTH * sizeof(tile_t));
|
||||
traverse_light(map_cpy, x, y, i, -1, dir);
|
||||
energized = count_energized(map_cpy, x, y);
|
||||
|
||||
if (energized > max_energized) {
|
||||
max_energized = energized;
|
||||
}
|
||||
}
|
||||
// BOTTOM ROW
|
||||
for (int i = 0; i < x; i++) {
|
||||
dir[0] = 0;
|
||||
dir[1] = -1;
|
||||
memcpy(map_cpy, map, LINE_MAX_LENGTH * LINE_MAX_LENGTH * sizeof(tile_t));
|
||||
traverse_light(map_cpy, x, y, i, y, dir);
|
||||
energized = count_energized(map_cpy, x, y);
|
||||
|
||||
if (energized > max_energized) {
|
||||
max_energized = energized;
|
||||
}
|
||||
}
|
||||
|
||||
printf("%i\n", part1);
|
||||
printf("%i\n", max_energized);
|
||||
free(buf);
|
||||
}
|
||||
|
||||
void traverse_light(tile_t map[LINE_MAX_LENGTH][LINE_MAX_LENGTH], int x, int y, int entry_x, int entry_y, int dir[2]) {
|
||||
light_direction_t curr_direction = dir_to_direction(dir);
|
||||
|
||||
int curr_x = entry_x, curr_y = entry_y;
|
||||
|
||||
while (!has_light(map, curr_x + dir[0], curr_y + dir[1], curr_direction, x - 1, y - 1)) {
|
||||
curr_x += dir[0];
|
||||
curr_y += dir[1];
|
||||
map[curr_x][curr_y].lights[map[curr_x][curr_y].lights_num] = curr_direction;
|
||||
map[curr_x][curr_y].lights_num++;
|
||||
|
||||
if (map[curr_x][curr_y].type == MIRROR_LEFT_TO_UP) {
|
||||
int tmp = dir[0];
|
||||
dir[0] = -dir[1];
|
||||
dir[1] = -tmp;
|
||||
} else if (map[curr_x][curr_y].type == MIRROR_LEFT_TO_DOWN) {
|
||||
int tmp = dir[0];
|
||||
dir[0] = dir[1];
|
||||
dir[1] = tmp;
|
||||
} else if (map[curr_x][curr_y].type == SPLITTER_HORIZONTAL && dir[1] != 0) {
|
||||
dir[0] = 1;
|
||||
dir[1] = 0;
|
||||
int recurse_dir[2] = {-1, 0};
|
||||
traverse_light(map, x, y, curr_x, curr_y, recurse_dir);
|
||||
} else if (map[curr_x][curr_y].type == SPLITTER_VERTICAL && dir[0] != 0) {
|
||||
dir[0] = 0;
|
||||
dir[1] = 1;
|
||||
int recurse_dir[2] = {0, -1};
|
||||
traverse_light(map, x, y, curr_x, curr_y, recurse_dir);
|
||||
}
|
||||
curr_direction = dir_to_direction(dir);
|
||||
}
|
||||
}
|
||||
|
||||
int has_light(tile_t map[LINE_MAX_LENGTH][LINE_MAX_LENGTH], int x, int y, light_direction_t direction, int max_x, int max_y) {
|
||||
if (x < 0 || y < 0 || x > max_x || y > max_y) {
|
||||
return 1;
|
||||
}
|
||||
for (int i = 0; i < map[x][y].lights_num; i++) {
|
||||
if (map[x][y].lights[i] == direction) {
|
||||
return 1;
|
||||
}
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
light_direction_t dir_to_direction(int dir[2]) {
|
||||
if (dir[0] == 1) {
|
||||
return LEFT_TO_RIGHT;
|
||||
} else if (dir[0] == -1) {
|
||||
return RIGHT_TO_LEFT;
|
||||
} else if (dir[1] == 1) {
|
||||
return UP_TO_DOWN;
|
||||
}
|
||||
return DOWN_TO_UP;
|
||||
}
|
||||
|
||||
int count_energized(tile_t map[LINE_MAX_LENGTH][LINE_MAX_LENGTH], int x, int y) {
|
||||
int sum = 0;
|
||||
for (int i = 0; i < y; i++) {
|
||||
for (int j = 0; j < x; j++) {
|
||||
if (map[j][i].lights_num > 0) {
|
||||
sum++;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return sum;
|
||||
}
|
||||
110
day16/input.txt
Normal file
110
day16/input.txt
Normal file
@@ -0,0 +1,110 @@
|
||||
\.............\................\....\..../....\/...............................\...-..........-.\.-....../....
|
||||
|\......../|....\..............-\............./...........................-..........-......\........\........
|
||||
.......||......../....-./.../-...|.|..-......-.|....../................\............|...................-..|..
|
||||
........./......-.............-\......................|.\./.......|........./......-......../..-.........|....
|
||||
....../....................-............................................../...../...|.........................
|
||||
....................\....|/............................./.......-....|......../..........................\....
|
||||
.|....../|.........-......|.............\..|..................|......../.................|.|............-.|...
|
||||
.....-............\\............\................/......-.........\................\..|../....................
|
||||
............|..|.......|......../................\.......................|../....../......./.....|............
|
||||
.\...........\..\.............../.........-/....|......................./.....-./-.........../-........-......
|
||||
|................\.\-.............../..-............./........./.................\.............|...-.....-....
|
||||
.........-....|..|......................................\.||...-../..|............../...../.../.........-.....
|
||||
.....-....-\.................|...........|../.....\...............................|...../../|.................
|
||||
.\......\......................\....../.../.....-.../.........................../..|...........|..\...........
|
||||
-............|.........-.-........-.........................|...\...-...........\.|...-....../..........|.....
|
||||
.........-.......|......\.....\..-...../..../.....\.../............/..........-......./....../...........\.../
|
||||
..............\........................|.............................-../......-..-...../..................\..
|
||||
.....\......-.......-.......-......../../../........\.......-..........|......./........................../...
|
||||
.\...\...................|./\|.-..\...............................\..\.....-....|......................./.....
|
||||
.................-...|....|.../...../.|.||.....-.|............................-..............\................
|
||||
........................................../.......................|........\......../.../..............|.....\
|
||||
.......\......./............................./........../../..........................-\..................|...
|
||||
...........-...|..\..........-.........\.................././................|./.......|............../.......
|
||||
......./..................................\...-.........\........\....../............................\......\-
|
||||
-.|..-|...............|..........................\..........|.-.........\............-.|.............\.....|..
|
||||
.............................../..............-.....-.......-........................|.......-................
|
||||
.........\.........-.........|...../......../......./....-...\...................\........\...................
|
||||
..........\.........\........../...|.................|./...\.......\..........-...............................
|
||||
./...................|........../\......../....................|..-...........\...\...........|..............|
|
||||
.....|...........\-.\.......-..........................-....-...................|....|.|...............-......
|
||||
.|.././......................|.......|.......|..............\...../.................../.\...-.................
|
||||
...........-........./....|.................|..-.....-............./...................................-..../.
|
||||
...................\/..|.....-............../-......-..........|........................./...\....-|....|-....
|
||||
........................./..-..|.\-...............-......-/...../.......\..|................-...\.|.....\.....
|
||||
\...../.........................../....................-..........|........../..-..-.......\........../.././|.
|
||||
........................../...\|..................................................../...|.-........-.....|..\.
|
||||
....\.............................|./.....|...../....\.............\...../.......-...............\..-..../....
|
||||
.........-.........................|................|........\/.\-...................\..-......./../..........
|
||||
...-.../............/.................-..........\....../............../...../..........|.....................
|
||||
..........\...\..................|...-......\\......./...-.............-\.................|...../......\......
|
||||
/..\/.............\....\.............\.......................................|.....\....-............\........
|
||||
....../..\.|................................\.........../.......-.......-/.....|...................-.....-....
|
||||
........-....|.............................|....../...............\.......................--..................
|
||||
................/......|.........-....................-..............|.......................................|
|
||||
.........\........|...........................\.............|.............................../.................
|
||||
...|..\....-......../.\...-............................................................/....-...../...........
|
||||
.............\\\.../...../.../..........\..............\...........\........................|....../.........\
|
||||
......-..............|..-..|....-\..\..-...-............\.................\...-.\/.....\......-.\....--.../...
|
||||
........./...................../...../..|...\.\/.........\.../........................................\.../-..
|
||||
........\.......|.......|\..|........../..../\........../........\..../..............././..../.............-.\
|
||||
........................|-............|............................./.-.|...|............../....-\............
|
||||
../........-.../....................|....................-/.............../.....-...........-....\......||....
|
||||
.....\..|.....-|../....|./....-|.......-...../..-..\..............\...................../.................|...
|
||||
...-......../.\...........\.........\../.....|............\..................../.........\................/.\/
|
||||
...../...|............-..\.../............/............-..............--.-..........././............-........|
|
||||
.....|...........\.....-...\..../.....-........-.....\.|..............\....-............./...../..............
|
||||
....\.....-.|....\..../..............\|../.........../......|....\/.......................|............|....-.
|
||||
........|..--..............|..............-........|.......|.-.........\.............-...........\............
|
||||
./.||....\......./....\./........../...........././....\.................../..................\...../.........
|
||||
.......|..\...-.\..\..|.........../..................................-....|........\......|....|..............
|
||||
...|..........|.........-...............|...............................-.......|...........-..\.......\......
|
||||
.\.........../../............................-..|...\.....-.........../......-|.../.....|.................-...
|
||||
........|....../..\..\|..|......|.........|...............................\../.....\....-/........-...........
|
||||
.................................................\.......|........|.\.-....../.......|.......|............\...
|
||||
.......|.......\.......|.........|......-......|...|...\.............\.............|/.........................
|
||||
..........|....................|..........\..........-......./................................................
|
||||
...../.......|....................|......................././.................................................
|
||||
........\.............|........--..........\.............../......|...................../............|..\.....
|
||||
....-............|.........|....|.-.\../-...\....-...-................\|..\-.......|........-............../..
|
||||
................/........\.....\.....././....|....................-...............\...........-......\........
|
||||
.\.....|......|...|\......\.\/....\.............-............\.....\.......-...-........-....//..../.....|..-.
|
||||
..................|..|.-.................../\...........|..../..........\|.....-..|.../.......................
|
||||
-......-......./........./../.............../..................-..\.......\............|...../../....../......
|
||||
....../............/...........\.............\............./.........../.......\......|....|.........../......
|
||||
...\........|..................|............-............-.....-..\..-................/........../........||..
|
||||
......../..|..-../..../......................../.........\./.-................../...................-.........
|
||||
.../....|....\.......-..\..........-....\.............|\........../...............-........|..................
|
||||
..............\.............\|.........-......................-........\|......./.......-.................|...
|
||||
/..../...-||\-...|\...............................\.......................\.............-................-....
|
||||
.......-..-....|..................|..............................................................///...-.../.|
|
||||
......|.......-/........-.-......|....\..-...|...........\...........\.....................-..../.........../.
|
||||
......-...........|-..\.......|...|.\|.................-....\...................\.\........\.\./.........\....
|
||||
....../............../.........|...|.......|..../.............................................................
|
||||
.........../...................-./...\..........\-............./...........\.../.....|......................-.
|
||||
/..../..../........................................|.\......-/......./....\.........................-......|..
|
||||
.\./.|.-..........................|...|...........|....../....-....../|...............\..............\...-....
|
||||
....|...\..........|......-..................|........../..|.-...\........./........|................|........
|
||||
...\....\........../........../.........\..............-...........................-.|...../..........\.......
|
||||
...|...........-...........................\........-.........................\...-..-.....\.......|........-.
|
||||
......\|...........................\.....................................-............/....\...........|......
|
||||
................../............-........................\.................................................-...
|
||||
.../....|...............|....................../\.........|....................\....|............\.........|-.
|
||||
.......................................|....-.........../....\-........|......./............-..|.............\
|
||||
/.........\..\.........|...............\.......\........./................\....................|.....|........
|
||||
..................................|.....|.-..|.../......................../-\......|..........................
|
||||
.................|.....................................................-............|.....|..../.\/..........|
|
||||
.......\....\....-........|.|..../......-......\...../....................-...........\............-..........
|
||||
....-.................................-..........-......-................................../.........-\...|...
|
||||
.....................|......................|.........-............../.../.....-........\.....................
|
||||
.\./..........-.\...\||................./../........\.........|...\........\....\.\...............-|......|...
|
||||
..\......//.........../.\........\......|......|........\......\.....-..........|.-..|...../|.................
|
||||
/.....................\.................-........|...................\.....-..............-/.....\..|../../...
|
||||
...|..-.../............./.|.................../............/..\...........-....|-............\.......--.......
|
||||
..............\..\/.....\.........|.\.........................|............|........./................./-..|-.
|
||||
...........................-.................../...................|\..........\/..|.-........................
|
||||
.....-.............................../....................\.........|......................|..................
|
||||
..................\.........../...........\..\/.........|...........|..-........|....\..........-...../.|.....
|
||||
..........|.......\..\...........\.../......................-...........-.....-........../\|..................
|
||||
....../.......-........................\|...//...\..-......\.......|..\....................-..........\..-....
|
||||
|./....|........-./........../.\...\.....|../..../.......-........../.\.....-.................................
|
||||
10
day16/sample.txt
Normal file
10
day16/sample.txt
Normal file
@@ -0,0 +1,10 @@
|
||||
.|...\....
|
||||
|.-.\.....
|
||||
.....|-...
|
||||
........|.
|
||||
..........
|
||||
.........\
|
||||
..../.\\..
|
||||
.-.-/..|..
|
||||
.|....-|.\
|
||||
..//.|....
|
||||
BIN
day17/c/day17
Executable file
BIN
day17/c/day17
Executable file
Binary file not shown.
185
day17/c/day17.c
Normal file
185
day17/c/day17.c
Normal file
@@ -0,0 +1,185 @@
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
#include <string.h>
|
||||
#include <stdint.h>
|
||||
|
||||
#define LINE_MAX_LENGTH 256
|
||||
#define NUM_0_CHARCODE 48
|
||||
#define equal(a,b) ((a)[0] == (b)[0] && (a)[1] == (b)[1])
|
||||
#define MAX_NODES 128*1024
|
||||
#define MAX_PATH 1024
|
||||
#define BIT_0 0x0000001
|
||||
#define BIT_1 0x0000002
|
||||
#define BIT_2 0x0000004
|
||||
#define BIT_3 0x0000008
|
||||
|
||||
typedef struct node {
|
||||
int position[2];
|
||||
int weight;
|
||||
int dir[2];
|
||||
int forward_count;
|
||||
} node_t;
|
||||
|
||||
void insert_to_queue(node_t *nodes, int *nodes_num, node_t node);
|
||||
long dir_to_bit(int dir[2]);
|
||||
void set_tmp(node_t *tmp, int next_x, int next_y, uint8_t map[LINE_MAX_LENGTH][LINE_MAX_LENGTH], node_t curr, int next_dir[2], int fwd);
|
||||
void find_path(node_t *curr, int start[2], int finish[2], uint8_t map[LINE_MAX_LENGTH][LINE_MAX_LENGTH], int x, int y, int min_fwd, int max_fwd);
|
||||
|
||||
int main() {
|
||||
char *p, *buf, c;
|
||||
|
||||
buf = (char *)malloc(LINE_MAX_LENGTH);
|
||||
memset(buf, 0, LINE_MAX_LENGTH);
|
||||
p = buf;
|
||||
|
||||
uint8_t map[LINE_MAX_LENGTH][LINE_MAX_LENGTH];
|
||||
memset(map, 0, LINE_MAX_LENGTH * LINE_MAX_LENGTH * sizeof(uint8_t));
|
||||
int x = 0, y = 0;
|
||||
|
||||
while ((c = getchar()) != EOF) {
|
||||
*p++ = c;
|
||||
if (c == '\n') {
|
||||
p = buf;
|
||||
x = 0;
|
||||
|
||||
while (*p != '\n') {
|
||||
map[x][y] = *p - NUM_0_CHARCODE;
|
||||
p++;
|
||||
x++;
|
||||
}
|
||||
y++;
|
||||
memset(buf, 0, LINE_MAX_LENGTH);
|
||||
p = buf;
|
||||
}
|
||||
}
|
||||
|
||||
int start[2] = {0, 0};
|
||||
int finish[2] = {x - 1, y - 1};
|
||||
node_t curr;
|
||||
|
||||
find_path(&curr, start, finish, map, x, y, 0, 3);
|
||||
|
||||
printf("%i\n", curr.weight);
|
||||
|
||||
find_path(&curr, start, finish, map, x, y, 4, 10);
|
||||
|
||||
printf("%i\n", curr.weight);
|
||||
|
||||
free(buf);
|
||||
}
|
||||
|
||||
void insert_to_queue(node_t *nodes, int *nodes_num, node_t node) {
|
||||
int inserted = 0;
|
||||
for (int i = 0; i < *nodes_num; i++) {
|
||||
if (node.weight < nodes[i].weight) {
|
||||
// Shift to the right
|
||||
for (int j = *nodes_num; j > i; j--) {
|
||||
memcpy(&nodes[j], &nodes[j-1], sizeof(node_t));
|
||||
}
|
||||
memcpy(&nodes[i], &node, sizeof(node_t));
|
||||
inserted = 1;
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
if (!inserted) {
|
||||
memcpy(&nodes[*nodes_num], &node, sizeof(node_t));
|
||||
}
|
||||
(*nodes_num)++;
|
||||
}
|
||||
|
||||
long dir_to_bit(int dir[2]) {
|
||||
if (dir[0] == 1) {
|
||||
return BIT_0;
|
||||
}
|
||||
|
||||
if (dir[0] == -1) {
|
||||
return BIT_1;
|
||||
}
|
||||
|
||||
if (dir[1] == 1) {
|
||||
return BIT_2;
|
||||
}
|
||||
|
||||
return BIT_3;
|
||||
}
|
||||
|
||||
void set_tmp(node_t *tmp, int next_x, int next_y, uint8_t map[LINE_MAX_LENGTH][LINE_MAX_LENGTH], node_t curr, int next_dir[2], int fwd) {
|
||||
tmp->position[0] = next_x;
|
||||
tmp->position[1] = next_y;
|
||||
tmp->weight = curr.weight + map[next_x][next_y];
|
||||
tmp->dir[0] = next_dir[0];
|
||||
tmp->dir[1] = next_dir[1];
|
||||
tmp->forward_count = fwd ? curr.forward_count + 1 : 1;
|
||||
}
|
||||
|
||||
void find_path(node_t *curr, int start[2], int finish[2], uint8_t map[LINE_MAX_LENGTH][LINE_MAX_LENGTH], int x, int y, int min_fwd, int max_fwd) {
|
||||
node_t tmp;
|
||||
tmp.position[0] = start[0];
|
||||
tmp.position[1] = start[1];
|
||||
tmp.weight = 0;
|
||||
tmp.dir[0] = 1;
|
||||
tmp.dir[1] = 0;
|
||||
tmp.forward_count = 1;
|
||||
long visited[LINE_MAX_LENGTH][LINE_MAX_LENGTH];
|
||||
memset(visited, 0, LINE_MAX_LENGTH * LINE_MAX_LENGTH * sizeof(long));
|
||||
|
||||
node_t *nodes = (node_t*)malloc(MAX_NODES * sizeof(node_t));
|
||||
memset(nodes, 0, MAX_NODES * sizeof(node_t));
|
||||
int nodes_num = 1;
|
||||
memcpy(&nodes[0], &tmp, sizeof(node_t));
|
||||
int next_x, next_y, next_dir[2];
|
||||
for (;;) {
|
||||
// Pop first node
|
||||
memcpy(curr, &nodes[0], sizeof(node_t));
|
||||
|
||||
if (equal(curr->position, finish) && curr->forward_count >= min_fwd) {
|
||||
break;
|
||||
}
|
||||
// Shift entries
|
||||
for (int i = 0; i < nodes_num - 1; i++) {
|
||||
memcpy(&nodes[i], &nodes[i+1], sizeof(node_t));
|
||||
}
|
||||
nodes_num--;
|
||||
|
||||
// Check forward direction
|
||||
if (curr->forward_count != max_fwd) {
|
||||
next_dir[0] = curr->dir[0];
|
||||
next_dir[1] = curr->dir[1];
|
||||
next_x = curr->position[0] + next_dir[0];
|
||||
next_y = curr->position[1] + next_dir[1];
|
||||
|
||||
if (next_x >= 0 && next_x < x && next_y >= 0 && next_y < y && !(visited[next_x][next_y] & (dir_to_bit(next_dir) << (curr->forward_count * 4)))) {
|
||||
visited[next_x][next_y] |= (dir_to_bit(next_dir) << (curr->forward_count * 4));
|
||||
set_tmp(&tmp, next_x, next_y, map, *curr, next_dir, 1);
|
||||
insert_to_queue(nodes, &nodes_num, tmp);
|
||||
}
|
||||
}
|
||||
|
||||
next_dir[0] = curr->dir[0] == 0 ? 1 : 0;
|
||||
next_dir[1] = curr->dir[1] == 0 ? 1 : 0;
|
||||
next_x = curr->position[0] + next_dir[0];
|
||||
next_y = curr->position[1] + next_dir[1];
|
||||
if (curr->forward_count >= min_fwd && next_x >= 0 && next_x < x && next_y >= 0 && next_y < y && !(visited[next_x][next_y] & (dir_to_bit(next_dir) << (max_fwd * 4)))) {
|
||||
visited[next_x][next_y] |= (dir_to_bit(next_dir) << (max_fwd * 4));
|
||||
set_tmp(&tmp, next_x, next_y, map, *curr, next_dir, 0);
|
||||
insert_to_queue(nodes, &nodes_num, tmp);
|
||||
}
|
||||
|
||||
next_dir[0] = curr->dir[0] == 0 ? -1 : 0;
|
||||
next_dir[1] = curr->dir[1] == 0 ? -1 : 0;
|
||||
next_x = curr->position[0] + next_dir[0];
|
||||
next_y = curr->position[1] + next_dir[1];
|
||||
if (curr->forward_count >= min_fwd && next_x >= 0 && next_x < x && next_y >= 0 && next_y < y && !(visited[next_x][next_y] & (dir_to_bit(next_dir) << (max_fwd * 4)))) {
|
||||
visited[next_x][next_y] |= (dir_to_bit(next_dir) << (max_fwd * 4));
|
||||
set_tmp(&tmp, next_x, next_y, map, *curr, next_dir, 0);
|
||||
insert_to_queue(nodes, &nodes_num, tmp);
|
||||
}
|
||||
|
||||
if (nodes_num == 0) {
|
||||
printf("No path to end\n");
|
||||
break;
|
||||
}
|
||||
}
|
||||
free(nodes);
|
||||
}
|
||||
141
day17/input.txt
Normal file
141
day17/input.txt
Normal file
@@ -0,0 +1,141 @@
|
||||
322222331232132221112333141131141421432535111315454231154425333445331325214334352425212345343422113421533234333342231121312224211232132331311
|
||||
112222221132312141233334323313423341313142332514144441221332524235451353431144233453551355535521415123254413343222433142441412131232231122221
|
||||
233311211132123132221413413342313144254415324345245135411343525533355513313524342444244552154352343444341241224233132212231434412321112213132
|
||||
122121222123133442422242231341123325225213254443245241522123133531323555532233151534115233215142445532322342151213321214342313432231323113123
|
||||
333221122312222411121442113241232534233432521555121441223215535431542235361313542254543322532531154144522513554533443441341444111111321121333
|
||||
211331211214432233123223424223124532151344214214542223331353264642443432464436224423224313223252125355413525423152224342423114131411112111123
|
||||
321223112344113433231424123325532125514251543332123251155363265243452334535223565553644354421552113311325513113444511443343413432243231313333
|
||||
331112133142443233432421114422112423521245553211111523242563534534562453423253433464252355615233351324133352335421242442142134213132421212232
|
||||
123123132324211421233414412211533554345522213452545454536356224246525264445422262363524343225625252212421135334423251133211443213214112122122
|
||||
121221241431433223122131445353552233142144512443252243362553462252633665622344555425653436444465214112414411121121114514124141222324134111222
|
||||
133112144124112314211245532541231542542135512356236336563252252643564354434566234566342436235632443531431233413141321355444213214223322423332
|
||||
322132441311211324331354355511325535454343332336355243323534546646445434666434356245233443234355464421551444314452551232413312111222342422132
|
||||
332112144311441331145235233355512421155156656566655324663456462643234333652442646456526324524435666264354525124554151514344111232333123121232
|
||||
112322143122443321255444531524442254522435344466544446225563232454254336646644453432456442265426224633364413545552141231232342443134312424322
|
||||
211112433314214414121554231413313431264645245424625662356556356363526434463335423263455622432234243652233651124423324145351422433444413233242
|
||||
123412313414223441541432354411133533264565324623356522334552452232222235346254322544256225266444465563624663145242355442225325131344441434431
|
||||
122232241113233344414343445245334526626224652262554436326624425654546753366453737333434566325324232256666566465541522125315544113322131424313
|
||||
441131142343322224354232433122154334244453262644636226432735355445376336457435675653434424226226554263663436634131141121112212521241142321232
|
||||
444124213331242524531555541123263435226643536536425642566335447454777555373634744664333634623364456664254352535441433522414143232432133312141
|
||||
142323312314135231332412115353444646325624242262433637566663535477543343575346673575566463756653266553236665325236325123231544443414221443432
|
||||
133332214211214512511334522363626634345432634234666347475673545334567454333665333576563637635363565362524656455244455214423524135332241112343
|
||||
114332313215243122212252352362462564564232565327436544463373743636663353454736374665776566476746432522662336422255461425241315315553244323324
|
||||
244113213443433453312254442326242365253345446477645575746733344546446356353436466556776654557445633664365364254554262454122333435243234441244
|
||||
123133241351413144322431436253253364555363566547664357364763645337356755445663333755367347437736645644534466442424465622335515552345223114132
|
||||
141313223214133413535525225635234556344253774463564757456364334433557373347466336733657334573673434763453634355653256221125514413333512421413
|
||||
211121435455322131411522253334522524622544466575377334767736555357537733536675363657467556556673734365355346223246664252445312521512143341213
|
||||
332112111553531125445446523366463445537367445346365446335537556536434636555356675375456337733736757365346555654534526656553112414115442343431
|
||||
334323341513433241114523442435633456453436453567566443375366734684585655664865675435643534674434744767767333656223563665331323153212455312432
|
||||
214314422254423141124253362526654246747334664673454533366676454748888877776756674465474764467464765335636744663634563446233514225243123132134
|
||||
221422142552342124425653343364465434643664433546553363355685647884564674785885575486566465774563367363755763646622533526434545511232231432332
|
||||
131433153555224431352333622333525534653646537757446733746685664657876486887856687457474885575443346475434476536426665533526555423525114543143
|
||||
414241342153331114533342663553345453557573336633565378468874774454686655858846664676674578677565646434577735336422624662264235213343545134142
|
||||
422244331152252533356444644642455653634367437537666758685886576658586455555774455576784768545547457776764576377324655644335242441215542311123
|
||||
224514311332324242565636562655637475653434634444657476468485645887444747545566846648888555466687367765343444634536335554435446552553424521452
|
||||
324235324155152356524453432522667443344757556358656654687574754764658686465764884887485465874455475445346554773356334265444255333253343144414
|
||||
422155422455233453265254553566435573557344535678585454448445848876874775857565648577744784557686584733547637647666563335352253255433145143325
|
||||
433522423543246253243562266265653675734363374788654878446558787775868774745648585768584467654645865464634776476743662656334634244532254554223
|
||||
112345432553324646256344452563676533734565448486848444474866678688445746558464865554564485485545584764747547774754536532455325263313454154144
|
||||
421331512554232363542455634433545333654378757764885664588484868588998998685995846766466678454557847578576466763755573652655565366235332454123
|
||||
134154422313262464256254654773353533337648867775767446685857787668566778565568657556848888464545675546643744436744557236545455522654511214542
|
||||
112411314514523646326445544635655366776764888547846646744467988655959979885758577589657656577576456686655353733563633344446625362364333345133
|
||||
211512544551565256423432474775576664545654687446758847488965895996789986579865686776897658554775844545786545467636655664426546522431523233541
|
||||
254121351444222654563456537446766653446447844486786747879967767776888966755788565956589746644586858548478855347636455665553425352625443222352
|
||||
451334343256326255354425675633565746775544566747785759695789698868776866668598597658557566666774884648467566677366444334355264652355223454352
|
||||
155151522152425333432626354533656634555844757447476698598879888959659585587795857588675958656788578667867657566633733344526545352652553311352
|
||||
323311225332555322334644436665373337767457786854668867567985596968898656885687676977785665879777747478584778573345654757554562666335411321112
|
||||
142444221335424244536656477453464455744887865446887787855585777685796976868758586897765699887954868887755464763476753644534362545225642333444
|
||||
311125151633663542456465333376767765786657565778767955557876559955689578586576585797986779967698764667848668665747635664435235222536423442522
|
||||
144554313565643664236735676567364486685774468847969997585567999667988979868896977566559989556677745448577455763634475546563246245333642251442
|
||||
124214126256353433325473676455454666788856858698575977697766599669866999879567996989966899797576864675847466646747644765443545446645464154342
|
||||
234124226225525534535674553355765857686864865767897575989977768778898969976676695899888665967559967644586575564767537765734326524333465354225
|
||||
111551143364233333665643467766438664557567678787898866578797588868798779999699767655579989956698785867665846684775346733737464263262223423535
|
||||
421142363333253664544635635565747785478446775558697785969987878967866898678977898767665798797676555777844866875437565537556343535323245315143
|
||||
345451135266466434675467566347387784585488857975558655988686966879969689867987676689658669555877886654554844677874374375647452532563465323312
|
||||
242344235526446225574577365666857586685844858595768997599866987776696969789998767977998688696585596748446874845767546643477356665366322243513
|
||||
532115353236434346534634733555468887444458798785586687666896797669699668879888678989789975575797967797446777787773765636465353253444235324124
|
||||
235252242332246463467535455567845748488877859896995668669999977886978787798967787789697986965568759965575866767684446575767766556534632223343
|
||||
143343325563554625676677466736585746688768796796597668897988677999977687767877778687688699596756555977655786864458675757535765244622653564445
|
||||
545315646456655266556653677767587445855588796556985766998667888899887979788686979978889977557598975555844475855845377463446464555262342631255
|
||||
225323565454336424365556773756857467464878759576599956696878999969999898888968786667778988659878759657948786484475467365633534655233653353235
|
||||
224456254554422567564536775664546477547496965696857878869687787688788689898868798866776677786775879975586787856564673365735573535355336643124
|
||||
543456555444426224545554573586765657466559558587778966798787896889889977799898886898997977867687585566966546665755565446657556435234526266454
|
||||
315536325363343234433576335774558558648696679779999987876899698688897777878779896786769797695668779777566586765854453534633757444253423625124
|
||||
151216343662665453744746445345584547677965779558577699779886978978777897877977999699897967999896857857567477554548633463477463436533242564425
|
||||
543355354446632363335673367868545465458855986855886769967868668887898997997779797889797789986979895575796847754484547453753543325425346663312
|
||||
535322533226325265767647536855854855778979965879769897779967969888779887797988788766667777977689986668684474868785466476357456665654234465422
|
||||
231556524524226674547774473577586775489576795799987997979988777988878798898979988779998877686665678579598888858487544564677765355264626364355
|
||||
354215356635232277535766636447878578669956779799558778996768979798988889979889779967876877966557957959587447848557557543533356453246253366234
|
||||
544153364554564456764536556464688677765858958656696869678987689977798987889888897977876867798796895759888764846576743454376377365453456435242
|
||||
525152435566645637336466733788745548648698786968877688677769779987978987789788999968789887968656659668895788467868645643335453444225226564223
|
||||
554456254232442545777435733656455785856855968689797989978989998979989887797777797976786767789995886788998575456486644647567746642446655425652
|
||||
552564443563356465645755534444484775746676866969686899686988899789877798797987988877867977966776888778685645444876565554734346554535452535642
|
||||
532426532465544566736373337854774776469589868759887699866868799987778898988888988986999888977689658558785555676674563743364767746445624552333
|
||||
224355342623332446467776757776465567785866775787976966967786797879987977979887897769767669698676797997899887656865744456675564542545425242511
|
||||
423424563462454366676567475856764458447599968889989679788788997777777789778778978869897867878976867889765758656648566746737475334465564536233
|
||||
454354245243524276633735643586686864846687557668997987876996879788778787797997888887866789999996989598656747776576584434473565343422544655523
|
||||
134213565432233465576366665487445544577887868868667869978999789878777988888787798679687997698658996767868685676666886753643377763624563546545
|
||||
532526426424453576553556543646845455884766968656687677789798797787887887799978988987868899889988659759595786484466747636434764443634222623112
|
||||
542124434443543643563654343446677677865867697586879688897676867878998898978989799997897676878989798989894674848855564375747446466225322665122
|
||||
255252546255422477374435674555867867846875859668568976669679866687988897888887767987676867685686896869984666465866436477476453332334245662542
|
||||
521356225624562566737635377668646645674597898979975767987777986999779797979787989767687876969858658797875578475575844544575376744663524426112
|
||||
445433354652342445476743633654745688748585786556759599669677668868787887798779686867799996687885695767966766658677433575764544533355666466235
|
||||
233545323366363443337334575665656688465679988569788899696799768867686879798678896669999999678786979799758457575467834667547446422625542453532
|
||||
324551224454322244447567665378587865658577789765599566876768689788999686766989687679969779997585677767748848548857743346556535524656256542114
|
||||
351542435666443534653733675577668888446688685688566896889967698777767679879699797968969696779957888876558466675655337434566444452232256353141
|
||||
311234446553626523657447336368764547755445787587888656797968979698698679799878676799677787958798569698645864667884564337475477634264343454123
|
||||
115512526244454342364454343545675548487884588995597578869968989986689887798879779679776976775797956658748777646557343436344353622662465244111
|
||||
122211552645355262744655766376755587575864856558998666687987677799978987698878777798777775786979767587568477585747657336557735534625335232455
|
||||
425345443424245433375455547633778546574776765755765855888797968989997799876668999797669979886787688876547677654773776745434562333653263224523
|
||||
555251326362654363237546435473346468884476467796588875986769677679987979967879988869668699867555669955445674845675654745564655365665446543555
|
||||
251445423464566444547337744665776567644578465769676786559588667977677786989966798688666778655767877684666874657464563343775666634426234234531
|
||||
341355143244643626455357536755754585648456787595697879688996577986866979878868977979659969966867565678667484454756454375754462663543452534243
|
||||
411222154254544422667433433675666457848545545989798668975957675887979988699687798967697968568959784658856455566644673776554336545643436145141
|
||||
111122522642643455345565565336453847775464574889689865766896866699599898777567755897685679777856958657445858653767456364347624464332533335154
|
||||
524241542223363646625344447455676474586754455669665886589999589768559775556599589956665988786989478684546555454663534636576332446266461343514
|
||||
113533134433523524446375667645566447688876847855859957979767989878967979789999855959685696789985867764675664874634464336565224222646642321321
|
||||
245124345333555642252444454546376467867578884786479978989977659769956667868756689966765555985878864575655545774476473456565366462243363441453
|
||||
325354232436363363425333443734637667468756576648479988858967756758868779757888957989878668976654457564455648465766544656664643642266233352414
|
||||
451353323252436433336444757666564636547545444868484855686795879665895669878698685666795967568575477757788876676753437756326524635444422233212
|
||||
314251335526245463465344464664557574685576548854568759856996687769699776867988576768857557867678466888568855544765437763432222442344311351454
|
||||
221343454312356446253652533564454347687864847866685854878977995585678858876868579559676767585687778868678774743747547636565333442562245414433
|
||||
153334455244353565443262456744343467578487478747457785674998657698766957675569587698964765845684864574444667455745635532662234653645215513531
|
||||
323253541413342552245663443343675376543647876878458575556559588599988855669797967599547868547544658877584635537465644556623626662242233113253
|
||||
534434414252452225355655323757543566777567687485754846887585887865899558767759999578775754644485876644443336476447545444244442464511524114225
|
||||
142314213444164544544553446364555576745367646487857876847657447545869776658985875747755667746444686784736465576454773642446666332553312311413
|
||||
214112112255155462442242365344557773467374544846466557747448576848476667446464875867465456748844657557337475753345766254556234333342332325121
|
||||
244153353221226223323534344244636436774454367767748485587468775458546674855876677774876558575784878757743364775773736226355466624115153114123
|
||||
441232413554323455446346354233666374764645356675485547668775864485587868865755854785774464468786577433435436446443526356433456631223524422345
|
||||
143221413241342433544645523533734733466374434458654454486545647675776478466854875865487576784867635667346353555374563663532446535324324323523
|
||||
323131242415143225354352262324364766355466653533775477687544766487866677554777558458758787667587564446675477346743353245263356544252335112343
|
||||
421335544413315446545626342233335667476654573777557766545848667557886768867758486784545665457636443337735636345564533262244236355135432322131
|
||||
312244554415442331522246453334533637436756764474737765568656744654876674686547644877844868736646336544336346545536354445556333222132135454443
|
||||
321333454221512143442325262626664335573736534565367744484775854448556587586646887786475476467666656577334434366334646444445335553141543541233
|
||||
341133211142213555542466322563256567337574674733364756537584587757866448657755774474664364453535637443745353553456662464533532454235524451123
|
||||
421223541232113225443246365633626264757357575466645334557538454665677655677477786664433654335355636634647763565546635663546221155245241142144
|
||||
323422431143311254424526246335546255453335743347554637636473547445746785666646745773655646565733765464747364365366655543643333425255152231113
|
||||
433444113153233523221332663653526543537447366535353747643746373675543536536676575675536557447354456764537266436522466222351315532533422224334
|
||||
124222124142422434345123524266324224352356353365644745467673444747464463633433737347353333763357453336762446354252356335425421133544211144442
|
||||
412231321555333442353123332362425543424533553573666735637763454533745366765376746433756447475333356464464222432332345352341525223324314223324
|
||||
331312433213455231253313366665632226633556433475477753337363656373433773757536533656447774556433367326623645656523564215343224513551431132223
|
||||
224112234222241332225213354662554264323422253344474667333733456554564565467557537447534475756667355536646365532333536213215244225153322244412
|
||||
244113243235224213541532412425436353634323524524735645546553763765557473655733554645336476657756623642432424252542344521515245415325122342431
|
||||
333421331131543452331544433322665453665253334334233336445435345646447373734355537674545543737663646626335655635662215142322433242354342243112
|
||||
133313231314112552244245534355643622352352432342233334476466373555376336634767555645553454753662546264266543564554134444222253115423131221131
|
||||
131231412441413152554252155332345653224645365352224252676774544675574675674375465365754635336426223222236455655231354243412255433333333111224
|
||||
332324343332244323555523343522424636242334346443522643425664563557445657753663433433742554644552342556462255264545525242315522431444111241243
|
||||
242131114222434333535315551155432535643423333423326353532254255655746367555476375465645466663246524345534363325342524554524235232124123342242
|
||||
213443214424214122543235113333321125533542665643265452423232525225353624456522652323524352424663342645352244451451351414355352332211232222141
|
||||
331324322142214311244251224225412153666422233553532445352342364235225362266256253442662643454463636563552424333135251344313153142323433132323
|
||||
133324412321343111133453143214253353444663336233236323356323263332552632535244356555555246466334633636434214335153524233455513241242143233331
|
||||
112312232341121314233341331125215255233566334652552425242266535646254524434335664425346234266623244222224122425211534551415411323432223422431
|
||||
111221111132441212123422453234455112532453426625322352463453654552623534226653432234662654524636336532544221415524444135141242433424422341213
|
||||
132112142443434332213144334542214243531213325566463422625562222442645236252323332463366466355454556441122343223223544533444444111223232343312
|
||||
123132114141224134221142521153123435354553455566553265365362456544335254345555663536355522235262422254555111123424125513443122342334241423213
|
||||
222111222213331423242143325343351111342555413323153635663634225423236363264256253225335432323241313143325535154411221431341241322112213222333
|
||||
233133121221424112412441244521151213235233325252323226243435524643246242326265222442643346314111554114124523453333352131423344424422332112111
|
||||
313223121314322131323232111313433421514531352544111512123656226536435625655252522552646223335233154132134344324541142331432322433213231333223
|
||||
122323311123331314242221442331134445133211444341324335245235554244244535654565323631324113113435231541311524113422324131342433243442233332323
|
||||
131232121222413342213424423134225553425223335324412235455552131523111656231531242452533234455554145512342144111144431122223424423333132222113
|
||||
111322123121134213313111224233414112541332235125122353234451522411134512122545415145522212213525144152312255153143114113221323132422321321122
|
||||
212133123312121131311312443214311325443433324425455124152235512334253433334522144532143435341332543332153335423423341414241221311221213123233
|
||||
13
day17/sample.txt
Normal file
13
day17/sample.txt
Normal file
@@ -0,0 +1,13 @@
|
||||
2413432311323
|
||||
3215453535623
|
||||
3255245654254
|
||||
3446585845452
|
||||
4546657867536
|
||||
1438598798454
|
||||
4457876987766
|
||||
3637877979653
|
||||
4654967986887
|
||||
4564679986453
|
||||
1224686865563
|
||||
2546548887735
|
||||
4322674655533
|
||||
BIN
day18/c/day18
Executable file
BIN
day18/c/day18
Executable file
Binary file not shown.
369
day18/c/day18.c
Normal file
369
day18/c/day18.c
Normal file
@@ -0,0 +1,369 @@
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
#include <string.h>
|
||||
#include <stdint.h>
|
||||
#include <limits.h>
|
||||
|
||||
#define LINE_MAX_LENGTH 256
|
||||
#define MAX_ENTRIES 2048
|
||||
#define MAX_QUEUE_LEN 256
|
||||
#define MAX_EDGES 1024
|
||||
#define MAX_BREAKPOINTS 512
|
||||
#define min(a,b) ((a) < (b) ? (a) : (b))
|
||||
#define max(a,b) ((a) > (b) ? (a) : (b))
|
||||
|
||||
typedef struct entry {
|
||||
char direction;
|
||||
long long count;
|
||||
char rgb_string[10];
|
||||
} entry_t;
|
||||
|
||||
typedef struct zone {
|
||||
long long upper_left_corner[2];
|
||||
long long lower_right_corner[2];
|
||||
uint8_t outside;
|
||||
} zone_t;
|
||||
|
||||
int cmp(const void* a, const void* b);
|
||||
int on_edge(long long edges[MAX_EDGES][2][2], int edges_num, long long side[2][2]);
|
||||
unsigned long long lake_volume(entry_t entries[], int entries_num);
|
||||
void decode_rgbs(entry_t entries[], int entries_num);
|
||||
|
||||
int main() {
|
||||
char *p, *buf, c;
|
||||
|
||||
buf = (char *)malloc(LINE_MAX_LENGTH);
|
||||
memset(buf, 0, LINE_MAX_LENGTH);
|
||||
p = buf;
|
||||
|
||||
entry_t entries[MAX_ENTRIES];
|
||||
memset(entries, 0, MAX_ENTRIES * sizeof(entry_t));
|
||||
int entries_num = 0;
|
||||
|
||||
while ((c = getchar()) != EOF) {
|
||||
*p++ = c;
|
||||
if (c == '\n') {
|
||||
sscanf(buf, "%c %lli %s", &entries[entries_num].direction, &entries[entries_num].count, entries[entries_num].rgb_string);
|
||||
entries_num++;
|
||||
memset(buf, 0, LINE_MAX_LENGTH);
|
||||
p = buf;
|
||||
}
|
||||
}
|
||||
|
||||
unsigned long long part1 = lake_volume(entries, entries_num);
|
||||
|
||||
decode_rgbs(entries, entries_num);
|
||||
|
||||
unsigned long long part2 = lake_volume(entries, entries_num);
|
||||
|
||||
printf("%llu\n", part1);
|
||||
printf("%llu\n", part2);
|
||||
|
||||
free(buf);
|
||||
}
|
||||
|
||||
int cmp(const void* a, const void* b) {
|
||||
return *(long long*)a - *(long long*)b;
|
||||
}
|
||||
|
||||
int on_edge(long long edges[MAX_EDGES][2][2], int edges_num, long long side[2][2]) {
|
||||
for (int i = 0; i < edges_num; i++) {
|
||||
if (edges[i][0][0] == side[0][0] && edges[i][0][0] == edges[i][1][0] && side[0][0] == side[1][0] && edges[i][0][1] <= side[0][1] && edges[i][1][1] >= side[1][1]) {
|
||||
return 1;
|
||||
}
|
||||
if (edges[i][0][1] == side[0][1] && edges[i][0][1] == edges[i][1][1] && side[0][1] == side[1][1] && edges[i][0][0] <= side[0][0] && edges[i][1][0] >= side[1][0]) {
|
||||
return 1;
|
||||
}
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
unsigned long long lake_volume(entry_t entries[], int entries_num) {
|
||||
long long x = 0, y = 0, dir[2];
|
||||
|
||||
long long edges[MAX_EDGES][2][2];
|
||||
memset(edges, 0, MAX_EDGES * 2 * 2 * sizeof(long long));
|
||||
int edges_num = 0;
|
||||
|
||||
for (int i = 0; i < entries_num; i++) {
|
||||
switch (entries[i].direction) {
|
||||
case 'R':
|
||||
dir[0] = 1;
|
||||
dir[1] = 0;
|
||||
edges[edges_num][0][0] = x;
|
||||
edges[edges_num][0][1] = y;
|
||||
edges[edges_num][1][0] = x + entries[i].count * dir[0];
|
||||
edges[edges_num][1][1] = y + entries[i].count * dir[1];
|
||||
edges_num++;
|
||||
break;
|
||||
case 'L':
|
||||
dir[0] = -1;
|
||||
dir[1] = 0;
|
||||
edges[edges_num][1][0] = x;
|
||||
edges[edges_num][1][1] = y;
|
||||
edges[edges_num][0][0] = x + entries[i].count * dir[0];
|
||||
edges[edges_num][0][1] = y + entries[i].count * dir[1];
|
||||
edges_num++;
|
||||
break;
|
||||
case 'U':
|
||||
dir[0] = 0;
|
||||
dir[1] = -1;
|
||||
edges[edges_num][1][0] = x;
|
||||
edges[edges_num][1][1] = y;
|
||||
edges[edges_num][0][0] = x + entries[i].count * dir[0];
|
||||
edges[edges_num][0][1] = y + entries[i].count * dir[1];
|
||||
edges_num++;
|
||||
break;
|
||||
case 'D':
|
||||
dir[0] = 0;
|
||||
dir[1] = 1;
|
||||
edges[edges_num][0][0] = x;
|
||||
edges[edges_num][0][1] = y;
|
||||
edges[edges_num][1][0] = x + entries[i].count * dir[0];
|
||||
edges[edges_num][1][1] = y + entries[i].count * dir[1];
|
||||
edges_num++;
|
||||
break;
|
||||
}
|
||||
|
||||
x += entries[i].count * dir[0];
|
||||
y += entries[i].count * dir[1];
|
||||
}
|
||||
|
||||
// Find smallest and largest x and y
|
||||
long long min_x = LLONG_MAX, max_x = LLONG_MIN, min_y = LLONG_MAX, max_y = LLONG_MIN;
|
||||
for (int i = 0; i < edges_num; i++) {
|
||||
if (edges[i][0][0] < min_x) {
|
||||
min_x = edges[i][0][0];
|
||||
}
|
||||
if (edges[i][1][0] > max_x) {
|
||||
max_x = edges[i][1][0];
|
||||
}
|
||||
if (edges[i][0][1] < min_y) {
|
||||
min_y = edges[i][0][1];
|
||||
}
|
||||
if (edges[i][1][1] > max_y) {
|
||||
max_y = edges[i][1][1];
|
||||
}
|
||||
}
|
||||
|
||||
// X breakpoints
|
||||
long long x_breakpoints[MAX_BREAKPOINTS], x_breakpoints_num = 0;
|
||||
for (int i = 0; i < edges_num; i++) {
|
||||
int found = 0;
|
||||
for (int j = 0; j < x_breakpoints_num; j++) {
|
||||
if (edges[i][0][0] == x_breakpoints[j]) {
|
||||
found = 1;
|
||||
break;
|
||||
}
|
||||
}
|
||||
if (!found) {
|
||||
x_breakpoints[x_breakpoints_num] = edges[i][0][0];
|
||||
x_breakpoints_num++;
|
||||
}
|
||||
found = 0;
|
||||
for (int j = 0; j < x_breakpoints_num; j++) {
|
||||
if (edges[i][1][0] == x_breakpoints[j]) {
|
||||
found = 1;
|
||||
break;
|
||||
}
|
||||
}
|
||||
if (!found) {
|
||||
x_breakpoints[x_breakpoints_num] = edges[i][1][0];
|
||||
x_breakpoints_num++;
|
||||
}
|
||||
}
|
||||
qsort(x_breakpoints, x_breakpoints_num, sizeof(x_breakpoints[0]), &cmp);
|
||||
|
||||
// Y breakpoints
|
||||
long long y_breakpoints[MAX_BREAKPOINTS], y_breakpoints_num = 0;
|
||||
for (int i = 0; i < edges_num; i++) {
|
||||
int found = 0;
|
||||
for (int j = 0; j < y_breakpoints_num; j++) {
|
||||
if (edges[i][0][1] == y_breakpoints[j]) {
|
||||
found = 1;
|
||||
break;
|
||||
}
|
||||
}
|
||||
if (!found) {
|
||||
y_breakpoints[y_breakpoints_num] = edges[i][0][1];
|
||||
y_breakpoints_num++;
|
||||
}
|
||||
found = 0;
|
||||
for (int j = 0; j < y_breakpoints_num; j++) {
|
||||
if (edges[i][1][1] == y_breakpoints[j]) {
|
||||
found = 1;
|
||||
break;
|
||||
}
|
||||
}
|
||||
if (!found) {
|
||||
y_breakpoints[y_breakpoints_num] = edges[i][1][1];
|
||||
y_breakpoints_num++;
|
||||
}
|
||||
}
|
||||
qsort(y_breakpoints, y_breakpoints_num, sizeof(y_breakpoints[0]), &cmp);
|
||||
|
||||
zone_t **zones = (zone_t**)malloc((x_breakpoints_num - 1) * sizeof(zone_t*));
|
||||
for (int i = 0; i < x_breakpoints_num - 1; i++) {
|
||||
zones[i] = (zone_t*)malloc((y_breakpoints_num - 1) * sizeof(zone_t));
|
||||
memset(zones[i], 0, (y_breakpoints_num - 1) * sizeof(zone_t));
|
||||
}
|
||||
zone_t *curr;
|
||||
|
||||
for (int i = 0; i < y_breakpoints_num - 1; i++) {
|
||||
for (int j = 0; j < x_breakpoints_num - 1; j++) {
|
||||
curr = &zones[j][i];
|
||||
curr->upper_left_corner[0] = x_breakpoints[j];
|
||||
curr->upper_left_corner[1] = y_breakpoints[i];
|
||||
curr->lower_right_corner[0] = x_breakpoints[j + 1];
|
||||
curr->lower_right_corner[1] = y_breakpoints[i + 1];
|
||||
}
|
||||
}
|
||||
|
||||
// Mark zones as outside
|
||||
int found = 1;
|
||||
while (found) {
|
||||
found = 0;
|
||||
for (int i = 0; i < y_breakpoints_num - 1; i++) {
|
||||
for (int j = 0; j < x_breakpoints_num - 1; j++) {
|
||||
if (zones[j][i].outside) {
|
||||
continue;
|
||||
}
|
||||
// LEFT
|
||||
long long side[2][2];
|
||||
side[0][0] = zones[j][i].upper_left_corner[0];
|
||||
side[0][1] = zones[j][i].upper_left_corner[1];
|
||||
side[1][0] = zones[j][i].upper_left_corner[0];
|
||||
side[1][1] = zones[j][i].lower_right_corner[1];
|
||||
if (j == 0 && !on_edge(edges, edges_num, side)) {
|
||||
zones[j][i].outside = 1;
|
||||
found = 1;
|
||||
}
|
||||
if (j > 0 && zones[j-1][i].outside && !on_edge(edges, edges_num, side)) {
|
||||
zones[j][i].outside = 1;
|
||||
found = 1;
|
||||
}
|
||||
// RIGHT
|
||||
side[0][0] = zones[j][i].lower_right_corner[0];
|
||||
side[0][1] = zones[j][i].upper_left_corner[1];
|
||||
side[1][0] = zones[j][i].lower_right_corner[0];
|
||||
side[1][1] = zones[j][i].lower_right_corner[1];
|
||||
if (j == x_breakpoints_num - 2 && !on_edge(edges, edges_num, side)) {
|
||||
zones[j][i].outside = 1;
|
||||
found = 1;
|
||||
}
|
||||
if (j < x_breakpoints_num - 2 && zones[j+1][i].outside && !on_edge(edges, edges_num, side)) {
|
||||
zones[j][i].outside = 1;
|
||||
found = 1;
|
||||
}
|
||||
// UP
|
||||
side[0][0] = zones[j][i].upper_left_corner[0];
|
||||
side[0][1] = zones[j][i].upper_left_corner[1];
|
||||
side[1][0] = zones[j][i].lower_right_corner[0];
|
||||
side[1][1] = zones[j][i].upper_left_corner[1];
|
||||
if (i == 0 && !on_edge(edges, edges_num, side)) {
|
||||
zones[j][i].outside = 1;
|
||||
found = 1;
|
||||
}
|
||||
if (i > 0 && zones[j][i-1].outside && !on_edge(edges, edges_num, side)) {
|
||||
zones[j][i].outside = 1;
|
||||
found = 1;
|
||||
}
|
||||
// DOWN
|
||||
side[0][0] = zones[j][i].upper_left_corner[0];
|
||||
side[0][1] = zones[j][i].lower_right_corner[1];
|
||||
side[1][0] = zones[j][i].lower_right_corner[0];
|
||||
side[1][1] = zones[j][i].lower_right_corner[1];
|
||||
if (i == y_breakpoints_num - 2 && !on_edge(edges, edges_num, side)) {
|
||||
zones[j][i].outside = 1;
|
||||
found = 1;
|
||||
}
|
||||
if (i < y_breakpoints_num - 2 && zones[j][i+1].outside && !on_edge(edges, edges_num, side)) {
|
||||
zones[j][i].outside = 1;
|
||||
found = 1;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
unsigned long long sum = 0;
|
||||
unsigned long long out = 0;
|
||||
for (int i = 0; i < y_breakpoints_num - 1; i++) {
|
||||
for (int j = 0; j < x_breakpoints_num - 1; j++) {
|
||||
if (zones[j][i].outside) {
|
||||
out++;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
for (int i = 0; i < y_breakpoints_num - 1; i++) {
|
||||
for (int j = 0; j < x_breakpoints_num - 1; j++) {
|
||||
if (zones[j][i].outside) {
|
||||
continue;
|
||||
}
|
||||
sum += (zones[j][i].lower_right_corner[0] - zones[j][i].upper_left_corner[0] - 1) * (zones[j][i].lower_right_corner[1] - zones[j][i].upper_left_corner[1] - 1);
|
||||
// RIGHT
|
||||
long long side[2][2];
|
||||
side[0][0] = zones[j][i].lower_right_corner[0];
|
||||
side[0][1] = zones[j][i].upper_left_corner[1];
|
||||
side[1][0] = zones[j][i].lower_right_corner[0];
|
||||
side[1][1] = zones[j][i].lower_right_corner[1];
|
||||
if (!on_edge(edges, edges_num, side)) {
|
||||
sum += side[1][1] - side[0][1] - 1;
|
||||
}
|
||||
// DOWN
|
||||
side[0][1] = zones[j][i].lower_right_corner[1];
|
||||
side[0][0] = zones[j][i].upper_left_corner[0];
|
||||
side[1][0] = zones[j][i].lower_right_corner[0];
|
||||
side[1][1] = zones[j][i].lower_right_corner[1];
|
||||
if (!on_edge(edges, edges_num, side)) {
|
||||
sum += side[1][0] - side[0][0] - 1;
|
||||
}
|
||||
// CORNER
|
||||
side[0][1] = zones[j][i].lower_right_corner[1];
|
||||
side[0][0] = zones[j][i].lower_right_corner[0];
|
||||
side[1][0] = zones[j][i].lower_right_corner[0];
|
||||
side[1][1] = zones[j][i].lower_right_corner[1];
|
||||
if (!on_edge(edges, edges_num, side)) {
|
||||
sum++;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
for (int i = 0; i < edges_num; i++) {
|
||||
sum += (edges[i][1][0] - edges[i][0][0]) + (edges[i][1][1] - edges[i][0][1]);
|
||||
}
|
||||
|
||||
for (int i = 0; i < x_breakpoints_num - 1; i++) {
|
||||
free(zones[i]);
|
||||
}
|
||||
free(zones);
|
||||
|
||||
return sum;
|
||||
}
|
||||
|
||||
void decode_rgbs(entry_t entries[], int entries_num) {
|
||||
for (int i = 0; i < entries_num; i++) {
|
||||
char value[6], *p;
|
||||
memset(value, 0, 6);
|
||||
p = entries[i].rgb_string;
|
||||
while(*p != '#') p++;
|
||||
p++;
|
||||
strncpy(value, p, 5);
|
||||
sscanf(value, "%llx", &entries[i].count);
|
||||
switch(entries[i].rgb_string[7]) {
|
||||
case '0':
|
||||
entries[i].direction = 'R';
|
||||
break;
|
||||
case '1':
|
||||
entries[i].direction = 'D';
|
||||
break;
|
||||
case '2':
|
||||
entries[i].direction = 'L';
|
||||
break;
|
||||
case '3':
|
||||
entries[i].direction = 'U';
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
660
day18/input.txt
Normal file
660
day18/input.txt
Normal file
@@ -0,0 +1,660 @@
|
||||
L 3 (#07b412)
|
||||
D 5 (#713ad1)
|
||||
L 2 (#11e6d2)
|
||||
D 4 (#6ba7d3)
|
||||
L 3 (#7cfca2)
|
||||
U 5 (#0a85c3)
|
||||
L 2 (#3a5282)
|
||||
U 4 (#6f91a3)
|
||||
L 3 (#32c2f0)
|
||||
U 6 (#2dd7b3)
|
||||
L 6 (#848c30)
|
||||
U 7 (#077a43)
|
||||
R 5 (#ba4692)
|
||||
U 6 (#49b551)
|
||||
R 3 (#14d162)
|
||||
U 8 (#397871)
|
||||
R 5 (#1c73f2)
|
||||
D 8 (#7130e1)
|
||||
R 4 (#c84852)
|
||||
U 2 (#203b91)
|
||||
R 3 (#288e30)
|
||||
U 5 (#91ba91)
|
||||
R 4 (#5dda70)
|
||||
U 3 (#91ba93)
|
||||
R 4 (#732500)
|
||||
U 4 (#0676f1)
|
||||
L 9 (#6701a2)
|
||||
U 4 (#5c38c1)
|
||||
L 7 (#0f7480)
|
||||
U 4 (#921b21)
|
||||
L 6 (#83d9e0)
|
||||
U 2 (#28c691)
|
||||
L 7 (#1b6de0)
|
||||
U 2 (#02cee1)
|
||||
L 4 (#5b66b0)
|
||||
U 4 (#bdb093)
|
||||
L 6 (#75eb20)
|
||||
U 4 (#928251)
|
||||
L 4 (#6bb430)
|
||||
D 7 (#44ad91)
|
||||
L 2 (#806b50)
|
||||
U 7 (#7d1391)
|
||||
L 4 (#7a3652)
|
||||
U 5 (#9cbf41)
|
||||
L 5 (#905712)
|
||||
U 2 (#70beb3)
|
||||
L 2 (#bede02)
|
||||
U 7 (#70beb1)
|
||||
R 3 (#a2c232)
|
||||
U 5 (#7b0ad1)
|
||||
R 5 (#01d012)
|
||||
U 5 (#2b1901)
|
||||
R 7 (#698c32)
|
||||
U 4 (#a19d91)
|
||||
R 4 (#7dbb92)
|
||||
U 3 (#8feb41)
|
||||
R 5 (#021ab2)
|
||||
U 3 (#42a773)
|
||||
R 6 (#99c6c2)
|
||||
D 7 (#8f7b33)
|
||||
R 5 (#01fd82)
|
||||
D 5 (#8e7263)
|
||||
R 2 (#37e492)
|
||||
U 5 (#10bff3)
|
||||
R 5 (#a09242)
|
||||
U 7 (#126723)
|
||||
R 3 (#864230)
|
||||
D 8 (#70bc43)
|
||||
R 5 (#7cf4a0)
|
||||
D 2 (#8135d3)
|
||||
R 6 (#144b70)
|
||||
U 5 (#0c51e3)
|
||||
L 6 (#00e590)
|
||||
U 4 (#44ba73)
|
||||
L 2 (#4177e2)
|
||||
U 4 (#a4c5b1)
|
||||
L 6 (#6f2f12)
|
||||
U 3 (#9a4ce1)
|
||||
L 4 (#979402)
|
||||
D 7 (#2a0ce1)
|
||||
L 3 (#0c1b70)
|
||||
U 7 (#58ca71)
|
||||
L 3 (#95d640)
|
||||
U 4 (#549241)
|
||||
R 10 (#a1f1b2)
|
||||
U 3 (#1753b1)
|
||||
L 5 (#1d32d2)
|
||||
U 5 (#9a58d3)
|
||||
L 5 (#4dc1b2)
|
||||
U 6 (#1ab693)
|
||||
L 4 (#5e8df2)
|
||||
U 3 (#4dabf3)
|
||||
R 6 (#972492)
|
||||
U 5 (#3198c3)
|
||||
R 4 (#972490)
|
||||
U 3 (#54b613)
|
||||
R 6 (#4a8bb2)
|
||||
U 2 (#a4c5b3)
|
||||
R 3 (#126042)
|
||||
U 9 (#54acc3)
|
||||
L 5 (#2b4682)
|
||||
U 4 (#88f453)
|
||||
L 4 (#2b4680)
|
||||
U 8 (#4a4283)
|
||||
L 2 (#8bfdf0)
|
||||
U 2 (#a76851)
|
||||
L 4 (#0a9b30)
|
||||
U 6 (#43a141)
|
||||
L 3 (#14fd80)
|
||||
U 3 (#7e5391)
|
||||
L 6 (#43ba40)
|
||||
D 2 (#146e93)
|
||||
L 4 (#9c71b0)
|
||||
D 7 (#5ae483)
|
||||
L 5 (#0bcd70)
|
||||
U 6 (#52a1c3)
|
||||
L 4 (#3307f0)
|
||||
U 4 (#1da3f3)
|
||||
L 3 (#7a8c80)
|
||||
D 5 (#89c463)
|
||||
L 2 (#2984e0)
|
||||
D 2 (#828673)
|
||||
L 6 (#2cf252)
|
||||
U 7 (#500061)
|
||||
L 4 (#a07ff2)
|
||||
U 3 (#565f21)
|
||||
R 3 (#09ef22)
|
||||
U 3 (#a65f83)
|
||||
R 5 (#410672)
|
||||
U 4 (#24fe73)
|
||||
L 5 (#b6ed72)
|
||||
U 8 (#4574d3)
|
||||
L 6 (#2e3142)
|
||||
D 8 (#7ba311)
|
||||
L 3 (#1bc442)
|
||||
U 6 (#38b161)
|
||||
L 4 (#8ada92)
|
||||
U 2 (#24cdf1)
|
||||
L 3 (#37b3e2)
|
||||
U 3 (#3a3ec1)
|
||||
R 5 (#242ea2)
|
||||
U 2 (#1fe073)
|
||||
R 5 (#9ad182)
|
||||
U 6 (#4a9193)
|
||||
R 6 (#34c480)
|
||||
U 2 (#9ff123)
|
||||
R 5 (#34c482)
|
||||
U 4 (#08fe03)
|
||||
R 3 (#46d292)
|
||||
D 10 (#19fca3)
|
||||
R 3 (#1ea7d2)
|
||||
D 6 (#c2d531)
|
||||
R 8 (#614f82)
|
||||
D 6 (#c2d533)
|
||||
R 6 (#777202)
|
||||
D 2 (#38f573)
|
||||
R 3 (#84e142)
|
||||
D 3 (#036d11)
|
||||
R 5 (#113352)
|
||||
D 5 (#036d13)
|
||||
R 3 (#7ad752)
|
||||
U 4 (#969de3)
|
||||
R 7 (#7887d0)
|
||||
U 3 (#31aa61)
|
||||
R 4 (#affca0)
|
||||
U 6 (#31aa63)
|
||||
R 2 (#374010)
|
||||
U 6 (#574d53)
|
||||
L 4 (#4edbd2)
|
||||
U 2 (#2271c1)
|
||||
L 7 (#595d32)
|
||||
U 3 (#2271c3)
|
||||
R 3 (#2c6532)
|
||||
U 5 (#2754d3)
|
||||
R 8 (#8b2652)
|
||||
U 4 (#b27ab3)
|
||||
R 6 (#824b80)
|
||||
D 4 (#587173)
|
||||
R 4 (#3715b0)
|
||||
D 5 (#8f0b61)
|
||||
R 3 (#6a2ac0)
|
||||
D 3 (#1e0b21)
|
||||
R 5 (#29a290)
|
||||
D 3 (#8850b3)
|
||||
R 5 (#9013e0)
|
||||
D 3 (#24c5d3)
|
||||
R 5 (#2b12d0)
|
||||
U 6 (#4090a3)
|
||||
R 3 (#9cddd0)
|
||||
D 6 (#a93843)
|
||||
R 4 (#6fff30)
|
||||
D 4 (#3f1121)
|
||||
L 7 (#76f2c0)
|
||||
D 4 (#4f9e11)
|
||||
L 3 (#76f2c2)
|
||||
D 8 (#480d31)
|
||||
L 6 (#694740)
|
||||
D 5 (#177e81)
|
||||
L 9 (#692aa2)
|
||||
D 3 (#10b971)
|
||||
R 9 (#42f012)
|
||||
D 3 (#10b973)
|
||||
R 3 (#2c6202)
|
||||
D 8 (#851881)
|
||||
R 3 (#04ae62)
|
||||
D 2 (#470d81)
|
||||
R 4 (#155e10)
|
||||
U 3 (#01b053)
|
||||
R 2 (#c55dd0)
|
||||
U 5 (#01b051)
|
||||
R 9 (#026f30)
|
||||
D 2 (#113081)
|
||||
R 2 (#694742)
|
||||
D 4 (#22d821)
|
||||
L 5 (#03eb80)
|
||||
D 5 (#3bc5d1)
|
||||
L 4 (#69bf90)
|
||||
D 3 (#3fdce3)
|
||||
L 4 (#2d1350)
|
||||
D 2 (#3fdce1)
|
||||
L 3 (#65f500)
|
||||
U 4 (#bd7f81)
|
||||
L 8 (#8382e0)
|
||||
D 4 (#160053)
|
||||
L 7 (#5ff9f0)
|
||||
D 4 (#ab40d3)
|
||||
R 6 (#5ff9f2)
|
||||
D 2 (#58d1b3)
|
||||
R 2 (#6bcc80)
|
||||
D 6 (#b187c3)
|
||||
R 6 (#73b290)
|
||||
D 3 (#9fbf43)
|
||||
R 4 (#630f00)
|
||||
D 2 (#4f1b13)
|
||||
R 7 (#543b30)
|
||||
D 7 (#114c43)
|
||||
R 6 (#629ac0)
|
||||
D 6 (#1bedb3)
|
||||
R 4 (#016f50)
|
||||
D 2 (#285e31)
|
||||
R 3 (#611460)
|
||||
D 7 (#0dfd61)
|
||||
R 2 (#75f3e0)
|
||||
D 2 (#1e79b1)
|
||||
R 4 (#144e90)
|
||||
U 5 (#d16ff1)
|
||||
R 4 (#144e92)
|
||||
U 6 (#113511)
|
||||
R 5 (#610450)
|
||||
U 3 (#1291c1)
|
||||
R 2 (#328eb0)
|
||||
U 5 (#2f3f73)
|
||||
R 9 (#126af2)
|
||||
U 4 (#946843)
|
||||
L 6 (#126af0)
|
||||
U 5 (#866453)
|
||||
L 7 (#352e70)
|
||||
U 4 (#5f8413)
|
||||
L 7 (#c618e2)
|
||||
U 3 (#6c2813)
|
||||
L 2 (#c618e0)
|
||||
U 3 (#1d3db3)
|
||||
R 8 (#37e470)
|
||||
U 2 (#1705b3)
|
||||
R 6 (#6ab412)
|
||||
U 6 (#961873)
|
||||
R 3 (#6ab410)
|
||||
U 8 (#30e6f3)
|
||||
R 5 (#3308e0)
|
||||
U 3 (#1fc8c1)
|
||||
R 3 (#3450a0)
|
||||
D 8 (#9d4391)
|
||||
R 3 (#6a9c70)
|
||||
D 2 (#25d071)
|
||||
R 4 (#3e5330)
|
||||
D 6 (#401381)
|
||||
R 5 (#399052)
|
||||
D 3 (#ab9e81)
|
||||
R 4 (#2622a2)
|
||||
D 4 (#68c4c3)
|
||||
R 4 (#2c5f92)
|
||||
D 3 (#8021d3)
|
||||
R 5 (#75bd02)
|
||||
D 3 (#1885a1)
|
||||
R 3 (#67b420)
|
||||
D 3 (#7df001)
|
||||
R 6 (#67b422)
|
||||
D 2 (#5270f1)
|
||||
R 3 (#2bbed2)
|
||||
D 9 (#863371)
|
||||
L 3 (#45ba70)
|
||||
D 6 (#49f553)
|
||||
L 2 (#693800)
|
||||
D 6 (#49f551)
|
||||
L 7 (#450b90)
|
||||
D 7 (#3b7aa1)
|
||||
R 5 (#399050)
|
||||
D 2 (#0b37f1)
|
||||
R 4 (#5cbff0)
|
||||
U 4 (#573103)
|
||||
R 3 (#3668c0)
|
||||
U 9 (#573101)
|
||||
R 4 (#7d0a50)
|
||||
U 7 (#316341)
|
||||
R 3 (#4cbab0)
|
||||
U 8 (#5c0f21)
|
||||
R 3 (#22b3a2)
|
||||
U 3 (#804941)
|
||||
R 4 (#22b3a0)
|
||||
U 7 (#173641)
|
||||
R 5 (#1b7230)
|
||||
U 3 (#8a0511)
|
||||
R 4 (#1a5f82)
|
||||
D 5 (#52eda1)
|
||||
R 4 (#1a5f80)
|
||||
U 5 (#38db21)
|
||||
R 5 (#2f4720)
|
||||
U 2 (#2a75c1)
|
||||
R 9 (#aa4d40)
|
||||
U 3 (#538141)
|
||||
L 3 (#7ad770)
|
||||
U 5 (#66ec01)
|
||||
L 5 (#53e812)
|
||||
U 3 (#539a81)
|
||||
L 4 (#53e810)
|
||||
U 5 (#413821)
|
||||
L 5 (#618330)
|
||||
D 5 (#a4bf71)
|
||||
L 6 (#56e4b2)
|
||||
U 3 (#acf591)
|
||||
L 2 (#890732)
|
||||
U 8 (#2a62d1)
|
||||
R 4 (#458e22)
|
||||
U 5 (#2ef8e3)
|
||||
R 4 (#273c60)
|
||||
U 4 (#439bc3)
|
||||
R 2 (#273c62)
|
||||
D 4 (#64c3c3)
|
||||
R 5 (#0e0c12)
|
||||
D 5 (#9481d1)
|
||||
R 3 (#5321d2)
|
||||
U 4 (#5d6361)
|
||||
R 7 (#531760)
|
||||
U 7 (#068711)
|
||||
R 7 (#216570)
|
||||
U 7 (#a20e51)
|
||||
L 3 (#216572)
|
||||
D 3 (#46afb1)
|
||||
L 8 (#4e8f70)
|
||||
D 6 (#1261b1)
|
||||
L 5 (#3840e0)
|
||||
U 6 (#7b0901)
|
||||
L 3 (#75cf00)
|
||||
U 3 (#b56e51)
|
||||
L 7 (#43b850)
|
||||
U 3 (#01dfc1)
|
||||
L 6 (#067e40)
|
||||
U 7 (#613913)
|
||||
R 5 (#30ff10)
|
||||
U 7 (#285d33)
|
||||
R 5 (#72e5c0)
|
||||
D 7 (#285d31)
|
||||
R 3 (#3fdcf0)
|
||||
U 6 (#601d03)
|
||||
R 4 (#312812)
|
||||
U 4 (#4ea643)
|
||||
R 6 (#8253e2)
|
||||
D 7 (#4ea641)
|
||||
R 2 (#3045d2)
|
||||
U 7 (#8362b3)
|
||||
R 7 (#631a70)
|
||||
U 4 (#ba56c3)
|
||||
R 6 (#28e520)
|
||||
U 2 (#568a53)
|
||||
R 3 (#c1d452)
|
||||
U 2 (#3e2a33)
|
||||
R 5 (#c1d450)
|
||||
U 5 (#0f6e43)
|
||||
R 4 (#c65ae0)
|
||||
U 3 (#790e83)
|
||||
R 2 (#012b40)
|
||||
U 7 (#2ea6b3)
|
||||
R 4 (#358722)
|
||||
D 2 (#7b3bf3)
|
||||
R 6 (#adbd32)
|
||||
D 4 (#4f7b63)
|
||||
R 5 (#0d26f2)
|
||||
U 5 (#47f363)
|
||||
R 2 (#4c6160)
|
||||
D 5 (#70ff63)
|
||||
R 5 (#284290)
|
||||
D 3 (#231103)
|
||||
L 7 (#540e80)
|
||||
D 2 (#8b51b3)
|
||||
L 5 (#662c40)
|
||||
D 4 (#22e7e3)
|
||||
R 7 (#1d46a0)
|
||||
D 3 (#343a43)
|
||||
L 6 (#4d7d90)
|
||||
D 4 (#31a643)
|
||||
L 10 (#4e6b30)
|
||||
U 4 (#31a641)
|
||||
L 4 (#5abc90)
|
||||
D 3 (#799953)
|
||||
L 4 (#9e4ed0)
|
||||
D 5 (#3b73e3)
|
||||
R 7 (#390760)
|
||||
D 3 (#bd3533)
|
||||
L 7 (#390762)
|
||||
D 5 (#075bd3)
|
||||
L 3 (#1b7350)
|
||||
D 3 (#a01d23)
|
||||
R 4 (#a56752)
|
||||
D 2 (#6a4313)
|
||||
R 5 (#529462)
|
||||
D 4 (#843c43)
|
||||
R 4 (#829482)
|
||||
U 4 (#7914e3)
|
||||
R 3 (#2f0b90)
|
||||
U 7 (#5f3d53)
|
||||
R 6 (#114980)
|
||||
D 7 (#60b7e3)
|
||||
R 4 (#b9b2f0)
|
||||
D 4 (#60b7e1)
|
||||
R 5 (#2143f0)
|
||||
D 3 (#2f86d3)
|
||||
L 7 (#5f4440)
|
||||
D 4 (#366293)
|
||||
L 5 (#5baae0)
|
||||
U 8 (#80a9a3)
|
||||
L 3 (#61f680)
|
||||
D 8 (#80a9a1)
|
||||
L 5 (#8bdce0)
|
||||
U 4 (#46e4d1)
|
||||
L 5 (#120950)
|
||||
D 8 (#7c15b1)
|
||||
L 4 (#641450)
|
||||
D 2 (#047bf1)
|
||||
L 2 (#3b00c0)
|
||||
D 7 (#a18c33)
|
||||
L 3 (#543b70)
|
||||
D 2 (#a18c31)
|
||||
L 7 (#466150)
|
||||
D 4 (#5c3ad1)
|
||||
R 4 (#5caa80)
|
||||
D 2 (#230201)
|
||||
R 6 (#955102)
|
||||
D 6 (#b200c1)
|
||||
R 7 (#955100)
|
||||
D 3 (#1d8ff1)
|
||||
R 3 (#26f9d0)
|
||||
D 8 (#160d71)
|
||||
R 2 (#483920)
|
||||
D 4 (#4577c3)
|
||||
R 8 (#92ef90)
|
||||
D 5 (#a57e83)
|
||||
R 7 (#0715a0)
|
||||
D 3 (#1da9e3)
|
||||
L 2 (#627970)
|
||||
D 6 (#573ee1)
|
||||
L 8 (#006f30)
|
||||
D 4 (#735da1)
|
||||
L 4 (#006f32)
|
||||
D 4 (#266951)
|
||||
R 3 (#9745a0)
|
||||
D 6 (#412bb1)
|
||||
R 7 (#83f8f2)
|
||||
D 2 (#6c4d31)
|
||||
R 4 (#6a7e72)
|
||||
D 3 (#578921)
|
||||
L 7 (#6c5d92)
|
||||
D 2 (#5485c1)
|
||||
L 5 (#300852)
|
||||
D 4 (#cdf091)
|
||||
L 2 (#544dd2)
|
||||
D 3 (#1259f1)
|
||||
L 7 (#882292)
|
||||
D 6 (#03e4b1)
|
||||
R 7 (#cdf192)
|
||||
D 3 (#5f3c41)
|
||||
R 4 (#c836b0)
|
||||
D 5 (#4cfdc1)
|
||||
L 2 (#36a590)
|
||||
D 4 (#244753)
|
||||
L 2 (#73bd60)
|
||||
D 3 (#244751)
|
||||
L 7 (#72cc90)
|
||||
U 4 (#0e0d21)
|
||||
L 5 (#21ce60)
|
||||
D 4 (#523dd1)
|
||||
L 9 (#041252)
|
||||
D 3 (#8cfc81)
|
||||
R 5 (#041250)
|
||||
D 5 (#365031)
|
||||
R 6 (#21ce62)
|
||||
U 5 (#17b3e1)
|
||||
R 5 (#75a900)
|
||||
D 3 (#8d4fe1)
|
||||
R 4 (#75a902)
|
||||
D 3 (#342091)
|
||||
R 5 (#8d5570)
|
||||
D 5 (#a6f9a3)
|
||||
R 5 (#59f560)
|
||||
D 4 (#49ae63)
|
||||
R 5 (#59f562)
|
||||
D 5 (#2dc6c3)
|
||||
R 4 (#8fb550)
|
||||
U 6 (#884bf3)
|
||||
R 3 (#17ea50)
|
||||
U 4 (#560143)
|
||||
R 5 (#623ad0)
|
||||
D 8 (#5dfc41)
|
||||
R 5 (#ca0040)
|
||||
D 2 (#5bc201)
|
||||
R 4 (#ca0042)
|
||||
D 3 (#7008b1)
|
||||
R 7 (#b87530)
|
||||
U 4 (#5e8821)
|
||||
R 4 (#817080)
|
||||
U 7 (#69e951)
|
||||
R 2 (#518e30)
|
||||
U 4 (#0e9831)
|
||||
R 5 (#29ea82)
|
||||
D 4 (#26f041)
|
||||
R 9 (#6a1862)
|
||||
D 4 (#8d3971)
|
||||
L 4 (#6a1860)
|
||||
D 4 (#215e71)
|
||||
L 5 (#29ea80)
|
||||
D 3 (#282e61)
|
||||
R 3 (#bc6172)
|
||||
D 8 (#17c4f1)
|
||||
L 6 (#1abf10)
|
||||
U 5 (#1a15e1)
|
||||
L 3 (#2ed960)
|
||||
D 5 (#24f4f3)
|
||||
L 4 (#9d6b00)
|
||||
D 6 (#24f4f1)
|
||||
L 2 (#704c40)
|
||||
D 4 (#45b0c1)
|
||||
L 5 (#93a182)
|
||||
D 6 (#53b3b1)
|
||||
L 5 (#5f72d2)
|
||||
U 6 (#76a9f1)
|
||||
L 4 (#643b62)
|
||||
D 3 (#3f41f1)
|
||||
L 6 (#691122)
|
||||
D 2 (#606491)
|
||||
L 5 (#4c5b02)
|
||||
D 5 (#6d1fa1)
|
||||
L 2 (#bf6472)
|
||||
D 6 (#6d1fa3)
|
||||
L 6 (#989bb2)
|
||||
U 4 (#606493)
|
||||
L 3 (#348412)
|
||||
U 6 (#9e4561)
|
||||
L 4 (#9b1742)
|
||||
U 8 (#42a901)
|
||||
L 5 (#09f8f2)
|
||||
U 3 (#63a8c3)
|
||||
R 8 (#591640)
|
||||
U 4 (#2dcda3)
|
||||
L 8 (#591642)
|
||||
U 4 (#4f7803)
|
||||
L 2 (#3e5fe2)
|
||||
U 5 (#0b9e93)
|
||||
L 3 (#cae6b2)
|
||||
U 4 (#7399f3)
|
||||
L 7 (#28c482)
|
||||
U 6 (#d2ee83)
|
||||
L 3 (#28c480)
|
||||
U 6 (#2f0423)
|
||||
L 3 (#320f52)
|
||||
U 2 (#5f4ab1)
|
||||
L 4 (#8d6672)
|
||||
U 6 (#b09261)
|
||||
L 6 (#718952)
|
||||
D 8 (#750591)
|
||||
L 4 (#33df82)
|
||||
D 5 (#1052a1)
|
||||
L 4 (#9a90e2)
|
||||
U 6 (#8eb861)
|
||||
L 2 (#0c1e92)
|
||||
U 4 (#53b871)
|
||||
L 4 (#0739f2)
|
||||
U 4 (#76cfb1)
|
||||
L 6 (#9b6922)
|
||||
U 7 (#76cfb3)
|
||||
L 5 (#846eb2)
|
||||
D 4 (#53b873)
|
||||
L 3 (#6b7ae2)
|
||||
D 4 (#59dd21)
|
||||
L 2 (#60b0b2)
|
||||
D 6 (#a53b01)
|
||||
R 5 (#767632)
|
||||
D 4 (#6c6bb1)
|
||||
L 4 (#b3a932)
|
||||
D 3 (#0660a1)
|
||||
L 5 (#12b390)
|
||||
U 4 (#9c9d01)
|
||||
L 4 (#12b392)
|
||||
U 3 (#910691)
|
||||
L 4 (#8dec12)
|
||||
U 6 (#65ba53)
|
||||
L 3 (#1e02b2)
|
||||
U 2 (#b05803)
|
||||
L 2 (#1e02b0)
|
||||
U 8 (#8a5d93)
|
||||
L 2 (#3bea42)
|
||||
U 5 (#032da3)
|
||||
R 8 (#0aabc2)
|
||||
U 3 (#4a0a13)
|
||||
L 8 (#9f1c02)
|
||||
U 4 (#58a0f3)
|
||||
L 3 (#9f1c00)
|
||||
D 3 (#3a2cf3)
|
||||
L 7 (#169b22)
|
||||
D 2 (#004253)
|
||||
L 2 (#841fd2)
|
||||
D 9 (#0b8473)
|
||||
L 4 (#3f85a2)
|
||||
D 6 (#134bd3)
|
||||
L 2 (#17f832)
|
||||
D 5 (#8870f3)
|
||||
L 2 (#87cf62)
|
||||
D 3 (#8b9fa3)
|
||||
L 2 (#6ca082)
|
||||
D 3 (#9a6ea3)
|
||||
L 7 (#60cbc2)
|
||||
D 4 (#9a6ea1)
|
||||
L 2 (#296752)
|
||||
D 3 (#b0d5c3)
|
||||
L 8 (#0e0100)
|
||||
D 5 (#218503)
|
||||
L 6 (#36a620)
|
||||
D 7 (#071463)
|
||||
L 3 (#669dd0)
|
||||
D 3 (#3099a1)
|
||||
L 7 (#385d40)
|
||||
D 5 (#3099a3)
|
||||
L 7 (#3c66b0)
|
||||
D 3 (#8fec33)
|
||||
L 2 (#4ce142)
|
||||
D 4 (#4b7051)
|
||||
L 8 (#55b322)
|
||||
D 3 (#4b7053)
|
||||
L 7 (#38cd62)
|
||||
D 3 (#668b13)
|
||||
L 4 (#36a622)
|
||||
D 2 (#581f83)
|
||||
L 4 (#0e0102)
|
||||
D 7 (#356bd3)
|
||||
L 5 (#3eb472)
|
||||
D 3 (#4ca003)
|
||||
L 3 (#6afe62)
|
||||
D 5 (#4ca001)
|
||||
L 5 (#536dd2)
|
||||
U 8 (#978bb3)
|
||||
L 5 (#6118d2)
|
||||
U 7 (#aec403)
|
||||
14
day18/sample.txt
Normal file
14
day18/sample.txt
Normal file
@@ -0,0 +1,14 @@
|
||||
R 6 (#70c710)
|
||||
D 5 (#0dc571)
|
||||
L 2 (#5713f0)
|
||||
D 2 (#d2c081)
|
||||
R 2 (#59c680)
|
||||
D 2 (#411b91)
|
||||
L 5 (#8ceee2)
|
||||
U 2 (#caa173)
|
||||
L 1 (#1b58a2)
|
||||
U 2 (#caa171)
|
||||
R 2 (#7807d2)
|
||||
U 3 (#a77fa3)
|
||||
L 2 (#015232)
|
||||
U 2 (#7a21e3)
|
||||
BIN
day19/c/day19
Executable file
BIN
day19/c/day19
Executable file
Binary file not shown.
303
day19/c/day19.c
Normal file
303
day19/c/day19.c
Normal file
@@ -0,0 +1,303 @@
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
#include <string.h>
|
||||
|
||||
#define LINE_MAX_LENGTH 256
|
||||
#define MAX_INSTRUCTIONS 16
|
||||
#define MAX_WORKFLOWS 1024
|
||||
#define MAX_PARTS 2048
|
||||
#define NUM_0_CHARCODE 48
|
||||
#define NUM_9_CHARCODE NUM_0_CHARCODE + 9
|
||||
#define MAX_BREAKPOINTS 1024
|
||||
|
||||
typedef struct instruction {
|
||||
char category;
|
||||
char operator;
|
||||
int value;
|
||||
char destination[16];
|
||||
int destination_length;
|
||||
} instruction_t;
|
||||
|
||||
typedef struct workflow {
|
||||
char name[16];
|
||||
int name_length;
|
||||
instruction_t instructions[MAX_INSTRUCTIONS];
|
||||
int instructions_num;
|
||||
char default_action[16];
|
||||
int default_action_length;
|
||||
} workflow_t;
|
||||
|
||||
typedef struct part {
|
||||
int x;
|
||||
int m;
|
||||
int a;
|
||||
int s;
|
||||
} part_t;
|
||||
|
||||
typedef struct breakpoints {
|
||||
int x[MAX_BREAKPOINTS];
|
||||
int x_num;
|
||||
int m[MAX_BREAKPOINTS];
|
||||
int m_num;
|
||||
int a[MAX_BREAKPOINTS];
|
||||
int a_num;
|
||||
int s[MAX_BREAKPOINTS];
|
||||
int s_num;
|
||||
} breakpoints_t;
|
||||
|
||||
int cmp(const void *a, const void *b);
|
||||
char get_workflow_result(workflow_t workflows[], int workflows_num, part_t part, workflow_t in);
|
||||
|
||||
int main() {
|
||||
char *p, *q, *buf, c;
|
||||
|
||||
buf = (char *)malloc(LINE_MAX_LENGTH);
|
||||
memset(buf, 0, LINE_MAX_LENGTH);
|
||||
p = buf;
|
||||
|
||||
int first = 1;
|
||||
workflow_t *workflows = (workflow_t*)malloc(MAX_WORKFLOWS * sizeof(workflow_t));
|
||||
memset(workflows, 0, MAX_WORKFLOWS * sizeof(workflow_t));
|
||||
int workflows_num = 0;
|
||||
|
||||
part_t *parts = (part_t*)malloc(MAX_PARTS * sizeof(part_t));
|
||||
memset(parts, 0, MAX_PARTS * sizeof(part_t));
|
||||
int parts_num = 0;
|
||||
|
||||
while ((c = getchar()) != EOF) {
|
||||
*p++ = c;
|
||||
if (c == '\n') {
|
||||
if (buf[0] == '\n') {
|
||||
first = 0;
|
||||
} else {
|
||||
p = buf;
|
||||
if (first) {
|
||||
while (*p != '{') p++;
|
||||
strncpy(workflows[workflows_num].name, buf, p - buf);
|
||||
workflows[workflows_num].name_length = p - buf;
|
||||
p++;
|
||||
while(*p != '\n') {
|
||||
q = p;
|
||||
while(*p != '<' && *p != '>' && *p != '}') p++;
|
||||
// Default action
|
||||
if (*p == '}') {
|
||||
strncpy(workflows[workflows_num].default_action, q, p - q);
|
||||
workflows[workflows_num].default_action_length = p - q;
|
||||
} else {
|
||||
workflows[workflows_num].instructions[workflows[workflows_num].instructions_num].category = *q;
|
||||
workflows[workflows_num].instructions[workflows[workflows_num].instructions_num].operator = *p;
|
||||
p++;
|
||||
sscanf(p, "%i", &workflows[workflows_num].instructions[workflows[workflows_num].instructions_num].value);
|
||||
while (*p != ':') p++;
|
||||
p++;
|
||||
q = p;
|
||||
while (*p != ',') p++;
|
||||
strncpy(workflows[workflows_num].instructions[workflows[workflows_num].instructions_num].destination, q, p - q);
|
||||
workflows[workflows_num].instructions[workflows[workflows_num].instructions_num].destination_length = p - q;
|
||||
workflows[workflows_num].instructions_num++;
|
||||
}
|
||||
p++;
|
||||
}
|
||||
workflows_num++;
|
||||
} else {
|
||||
while (*p < NUM_0_CHARCODE || *p > NUM_9_CHARCODE) p++;
|
||||
sscanf(p, "%i", &parts[parts_num].x);
|
||||
while (*p != ',') p++;
|
||||
while (*p < NUM_0_CHARCODE || *p > NUM_9_CHARCODE) p++;
|
||||
sscanf(p, "%i", &parts[parts_num].m);
|
||||
while (*p != ',') p++;
|
||||
while (*p < NUM_0_CHARCODE || *p > NUM_9_CHARCODE) p++;
|
||||
sscanf(p, "%i", &parts[parts_num].a);
|
||||
while (*p != ',') p++;
|
||||
while (*p < NUM_0_CHARCODE || *p > NUM_9_CHARCODE) p++;
|
||||
sscanf(p, "%i", &parts[parts_num].s);
|
||||
parts_num++;
|
||||
}
|
||||
}
|
||||
memset(buf, 0, LINE_MAX_LENGTH);
|
||||
p = buf;
|
||||
}
|
||||
}
|
||||
|
||||
// Find start
|
||||
workflow_t *start;
|
||||
for (int i = 0; i < workflows_num; i++) {
|
||||
if (!strcmp(workflows[i].name, "in")) {
|
||||
start = &workflows[i];
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
int part1 = 0;
|
||||
for (int i = 0; i < parts_num; i++) {
|
||||
char result = get_workflow_result(workflows, workflows_num, parts[i], *start);
|
||||
if (result == 'A') {
|
||||
part1 += parts[i].x + parts[i].m + parts[i].a + parts[i].s;
|
||||
}
|
||||
}
|
||||
|
||||
printf("%i\n", part1);
|
||||
|
||||
breakpoints_t breakpoints;
|
||||
memset(&breakpoints, 0, sizeof(breakpoints_t));
|
||||
|
||||
for (int i = 0; i < workflows_num; i++) {
|
||||
for (int j = 0; j < workflows[i].instructions_num; j++) {
|
||||
if (workflows[i].instructions[j].category == 'x') {
|
||||
int value = workflows[i].instructions[j].operator == '<' ? workflows[i].instructions[j].value : workflows[i].instructions[j].value + 1;
|
||||
int found = 0;
|
||||
for (int k = 0; k < breakpoints.x_num; k++) {
|
||||
if (breakpoints.x[k] == value) {
|
||||
found = 1;
|
||||
break;
|
||||
}
|
||||
}
|
||||
if (!found) {
|
||||
breakpoints.x[breakpoints.x_num] = value;
|
||||
breakpoints.x_num++;
|
||||
}
|
||||
}
|
||||
if (workflows[i].instructions[j].category == 'm') {
|
||||
int value = workflows[i].instructions[j].operator == '<' ? workflows[i].instructions[j].value : workflows[i].instructions[j].value + 1;
|
||||
int found = 0;
|
||||
for (int k = 0; k < breakpoints.m_num; k++) {
|
||||
if (breakpoints.m[k] == value) {
|
||||
found = 1;
|
||||
break;
|
||||
}
|
||||
}
|
||||
if (!found) {
|
||||
breakpoints.m[breakpoints.m_num] = value;
|
||||
breakpoints.m_num++;
|
||||
}
|
||||
}
|
||||
if (workflows[i].instructions[j].category == 'a') {
|
||||
int value = workflows[i].instructions[j].operator == '<' ? workflows[i].instructions[j].value : workflows[i].instructions[j].value + 1;
|
||||
int found = 0;
|
||||
for (int k = 0; k < breakpoints.a_num; k++) {
|
||||
if (breakpoints.a[k] == value) {
|
||||
found = 1;
|
||||
break;
|
||||
}
|
||||
}
|
||||
if (!found) {
|
||||
breakpoints.a[breakpoints.a_num] = value;
|
||||
breakpoints.a_num++;
|
||||
}
|
||||
}
|
||||
if (workflows[i].instructions[j].category == 's') {
|
||||
int value = workflows[i].instructions[j].operator == '<' ? workflows[i].instructions[j].value : workflows[i].instructions[j].value + 1;
|
||||
int found = 0;
|
||||
for (int k = 0; k < breakpoints.s_num; k++) {
|
||||
if (breakpoints.s[k] == value) {
|
||||
found = 1;
|
||||
break;
|
||||
}
|
||||
}
|
||||
if (!found) {
|
||||
breakpoints.s[breakpoints.s_num] = value;
|
||||
breakpoints.s_num++;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
qsort(breakpoints.x, breakpoints.x_num, sizeof(breakpoints.x[0]), &cmp);
|
||||
qsort(breakpoints.m, breakpoints.m_num, sizeof(breakpoints.m[0]), &cmp);
|
||||
qsort(breakpoints.a, breakpoints.a_num, sizeof(breakpoints.a[0]), &cmp);
|
||||
qsort(breakpoints.s, breakpoints.s_num, sizeof(breakpoints.s[0]), &cmp);
|
||||
|
||||
double part2 = 0;
|
||||
#pragma omp parallel for schedule(dynamic)
|
||||
for (int i = 0; i < breakpoints.x_num + 1; i++) {
|
||||
for (int j = 0; j < breakpoints.m_num + 1; j++) {
|
||||
for (int k = 0; k < breakpoints.a_num + 1; k++) {
|
||||
for (int l = 0; l < breakpoints.s_num + 1; l++) {
|
||||
unsigned long x0 = i == 0 ? 1 : breakpoints.x[i - 1];
|
||||
unsigned long x1 = i == breakpoints.x_num ? 4001 : breakpoints.x[i];
|
||||
unsigned long m0 = j == 0 ? 1 : breakpoints.m[j - 1];
|
||||
unsigned long m1 = j == breakpoints.m_num ? 4001 : breakpoints.m[j];
|
||||
unsigned long a0 = k == 0 ? 1 : breakpoints.a[k - 1];
|
||||
unsigned long a1 = k == breakpoints.a_num ? 4001 : breakpoints.a[k];
|
||||
unsigned long s0 = l == 0 ? 1 : breakpoints.s[l - 1];
|
||||
unsigned long s1 = l == breakpoints.s_num ? 4001 : breakpoints.s[l];
|
||||
part_t metapart = {
|
||||
.x = x0,
|
||||
.m = m0,
|
||||
.a = a0,
|
||||
.s = s0,
|
||||
};
|
||||
char result = get_workflow_result(workflows, workflows_num, metapart, *start);
|
||||
#pragma omp critical
|
||||
if (result == 'A') {
|
||||
part2 += (double)(x1 - x0) * (double)(m1 - m0) * (double)(a1 - a0) * (double)(s1 - s0);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
printf("%f\n", part2);
|
||||
|
||||
free(buf);
|
||||
free(workflows);
|
||||
}
|
||||
|
||||
int cmp(const void *a, const void *b) {
|
||||
return *(int*)a - *(int*)b;
|
||||
}
|
||||
|
||||
char get_workflow_result(workflow_t workflows[], int workflows_num, part_t part, workflow_t in) {
|
||||
for (int i = 0; i < in.instructions_num; i++) {
|
||||
int value;
|
||||
switch (in.instructions[i].category) {
|
||||
case 'x':
|
||||
value = part.x;
|
||||
break;
|
||||
case 'm':
|
||||
value = part.m;
|
||||
break;
|
||||
case 'a':
|
||||
value = part.a;
|
||||
break;
|
||||
case 's':
|
||||
value = part.s;
|
||||
break;
|
||||
}
|
||||
int matches;
|
||||
switch (in.instructions[i].operator) {
|
||||
case '<':
|
||||
matches = value < in.instructions[i].value;
|
||||
break;
|
||||
case '>':
|
||||
matches = value > in.instructions[i].value;
|
||||
break;
|
||||
}
|
||||
if (matches) {
|
||||
if (!strcmp(in.instructions[i].destination, "A")) {
|
||||
return 'A';
|
||||
}
|
||||
if (!strcmp(in.instructions[i].destination, "R")) {
|
||||
return 'R';
|
||||
}
|
||||
for (int j = 0; j < workflows_num; j++) {
|
||||
if (!strcmp(workflows[j].name, in.instructions[i].destination)) {
|
||||
return get_workflow_result(workflows, workflows_num, part, workflows[j]);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if (!strcmp(in.default_action, "A")) {
|
||||
return 'A';
|
||||
}
|
||||
if (!strcmp(in.default_action, "R")) {
|
||||
return 'R';
|
||||
}
|
||||
for (int i = 0; i < workflows_num; i++) {
|
||||
if (!strcmp(workflows[i].name, in.default_action)) {
|
||||
return get_workflow_result(workflows, workflows_num, part, workflows[i]);
|
||||
}
|
||||
}
|
||||
|
||||
return 'F';
|
||||
}
|
||||
769
day19/input.txt
Normal file
769
day19/input.txt
Normal file
@@ -0,0 +1,769 @@
|
||||
mxf{m<2310:phv,zs}
|
||||
zjr{s>1167:zqt,skq}
|
||||
hm{x>2975:rkl,x>2818:vhs,a>1062:bkc,kjg}
|
||||
dkl{m>2321:ctj,x>3530:A,gj}
|
||||
zk{s<1218:R,A}
|
||||
zkd{m>864:A,a>488:R,jcp}
|
||||
zdl{m>3429:A,m>2961:R,R}
|
||||
xmd{a<576:A,a<1045:R,a<1386:R,A}
|
||||
kzz{m>1106:R,a<508:R,x>2970:A,R}
|
||||
gdr{x<139:R,x<183:A,s<222:A,R}
|
||||
rb{m<3239:R,a<3546:A,A}
|
||||
xns{x<621:vrz,gm}
|
||||
nd{s>2927:xnx,x<3488:A,a<434:pg,A}
|
||||
fl{s<3624:qg,m>952:qf,kjt}
|
||||
vhm{x<3815:R,s>1774:A,m>643:R,A}
|
||||
krp{a<2439:R,m>298:R,x<1440:R,R}
|
||||
njj{x<2856:cjc,x<2936:R,a>598:R,kzz}
|
||||
jp{m>1745:R,x<1239:A,a<625:lt,qbq}
|
||||
rhd{a<3515:R,a<3543:A,s<3959:R,R}
|
||||
htm{a>284:R,m<1961:R,s<2226:R,A}
|
||||
kjj{a>704:fcn,s<439:lq,R}
|
||||
jkk{s>1376:R,a<341:A,A}
|
||||
jt{s<3384:A,x<3143:R,xgd}
|
||||
bcm{a<1408:R,m<425:R,A}
|
||||
hc{s>1126:A,m>1159:A,R}
|
||||
jff{a>3411:A,s<804:jn,A}
|
||||
knh{s>2643:szq,A}
|
||||
klj{x>1392:A,a<2628:R,R}
|
||||
kfx{a>1268:R,A}
|
||||
cxd{a>1275:A,s>1768:R,R}
|
||||
clq{a>1293:R,x>3243:R,R}
|
||||
mpc{a<2362:R,R}
|
||||
ng{a>578:A,x>1430:A,R}
|
||||
hh{a>2697:A,s<1336:R,a<2167:A,A}
|
||||
cjc{a<661:R,s>1113:A,x<2787:A,A}
|
||||
fgv{m>3553:R,m<3400:A,m>3492:A,A}
|
||||
pqk{m<110:R,A}
|
||||
zqt{m<1713:mg,s>1555:jfx,s<1309:zm,A}
|
||||
jrz{a<665:nh,tgp}
|
||||
vsf{s<2496:R,R}
|
||||
xdc{a>2214:R,A}
|
||||
kkm{s>3217:A,x<3895:R,a<857:A,R}
|
||||
sbh{s>1082:ct,sgx}
|
||||
kcn{x<3313:A,x<3389:mmt,phd}
|
||||
sgg{a<817:rf,s>2209:nhz,R}
|
||||
jd{s>2746:R,a>2645:R,R}
|
||||
pb{x>2553:A,qb}
|
||||
hq{a<1200:A,a<1322:A,m<968:R,R}
|
||||
kfz{x<3631:A,R}
|
||||
fvf{a>917:drd,s>3325:qt,kcn}
|
||||
ctj{m>2668:R,A}
|
||||
tbl{x>2400:ql,m<2122:cs,m>2504:rq,tpp}
|
||||
kn{m<1806:R,a<588:R,x>3133:R,A}
|
||||
sv{a<1325:R,a>1460:R,m>1718:R,A}
|
||||
rkl{x>3112:A,s>3342:R,R}
|
||||
mg{m>1291:R,A}
|
||||
tm{x>1917:bs,A}
|
||||
rkq{a<2465:bxc,x>1862:nxc,sp}
|
||||
tk{a<1228:A,a<1455:R,A}
|
||||
vts{s>3466:jq,xns}
|
||||
nh{x<2134:rr,x<2484:pbv,m<976:lvp,mv}
|
||||
sz{x<3075:R,m>359:R,R}
|
||||
btr{x>3197:qkh,ph}
|
||||
ff{m>1946:A,s<2407:zc,A}
|
||||
cmk{s>2606:R,A}
|
||||
jr{a>804:A,a<475:R,R}
|
||||
rf{x<415:A,s>2228:R,a<735:R,R}
|
||||
drd{s>3365:tk,s<3276:bcm,A}
|
||||
hvq{s<2401:hsn,s>3374:fl,xdl}
|
||||
vpn{s<1325:fvm,m<689:R,R}
|
||||
vj{s<1347:A,x>673:R,R}
|
||||
tnz{s>999:A,x>2657:gk,A}
|
||||
rft{a<401:pqp,qdm}
|
||||
gkm{m>430:A,m>196:A,s>3374:R,A}
|
||||
vhs{m>623:R,R}
|
||||
zzt{x>3410:A,m>2991:R,m<2312:A,A}
|
||||
pth{x<3816:A,s>3893:A,R}
|
||||
vmd{s>3539:zr,gr}
|
||||
dlh{x<3015:R,A}
|
||||
lv{a<2026:A,m<292:R,x>588:R,A}
|
||||
pr{x>3172:rjk,a<1192:R,m<595:A,A}
|
||||
dzq{a<812:bgx,s>1212:nhn,nnd}
|
||||
kxf{x>3058:R,A}
|
||||
tgp{a>1311:kkg,a>960:jx,hmf}
|
||||
npv{s<668:A,x>1167:A,R}
|
||||
pd{a<1327:A,a<1446:rp,R}
|
||||
krf{m>228:A,A}
|
||||
cg{m<3308:nr,a>1054:fxs,cgf}
|
||||
qd{a>2742:qmb,x>1719:mt,s>818:nrs,mpc}
|
||||
bsc{x>1586:R,a<1207:R,R}
|
||||
kcb{a<1236:A,s<1368:A,A}
|
||||
mf{a<2852:zv,m<2664:prx,rb}
|
||||
pnj{a<754:R,rcb}
|
||||
zr{x>1721:A,x>683:R,x>265:R,A}
|
||||
bn{s>1397:A,a<219:R,R}
|
||||
hx{a>953:A,a>428:A,x>539:R,R}
|
||||
jv{s<837:pr,fsl}
|
||||
qmb{s<1185:R,A}
|
||||
zcf{x>784:A,R}
|
||||
jpf{s<2409:A,s<2671:A,x<1126:A,R}
|
||||
kj{a>836:jv,x>3467:tjj,rl}
|
||||
cnc{s<3455:A,s<3662:R,a>1191:A,R}
|
||||
vbg{s>2501:R,x<3479:xhj,x>3748:R,R}
|
||||
in{a>1666:mb,x<1861:dql,sl}
|
||||
xg{x<749:dgs,A}
|
||||
pj{m<830:R,R}
|
||||
jb{m>3287:A,m>3057:gfh,A}
|
||||
zdp{a>3403:R,a>3071:R,m>808:R,A}
|
||||
ggc{x>1433:A,s>2595:R,R}
|
||||
pxr{s<3463:R,m<792:R,A}
|
||||
lk{x<724:R,s<3706:A,trm}
|
||||
mjv{s<3762:A,bxn}
|
||||
hl{a>556:ks,s<2836:A,m<1771:kc,kjd}
|
||||
gf{x>1994:R,m<3457:xkg,s>3446:R,A}
|
||||
bxz{m<718:R,A}
|
||||
bv{s<2868:ggc,R}
|
||||
pg{a<269:A,x>3764:R,m>3066:R,R}
|
||||
vxn{s>1686:R,a>1312:R,m<2228:A,A}
|
||||
jj{a>673:A,R}
|
||||
zsx{x>3204:R,A}
|
||||
cs{s<1229:A,R}
|
||||
qdm{a<550:A,m>833:R,A}
|
||||
vkl{s>365:A,x<236:gdr,s<161:zt,vxr}
|
||||
cb{x<1464:A,x<1513:R,m<1814:R,R}
|
||||
fn{m>2717:A,s>3698:A,R}
|
||||
jzq{x>330:A,m>2865:R,A}
|
||||
gn{a<1001:A,R}
|
||||
cvv{m>817:fr,x<1974:mrv,m<316:vd,kh}
|
||||
spl{a<1511:R,A}
|
||||
qg{a<3083:csf,a>3444:mz,vmd}
|
||||
tf{x>3535:R,a<669:gxm,s>2146:clq,A}
|
||||
sg{s<463:lx,s<936:tq,R}
|
||||
pnb{s<1080:R,m<3125:A,m<3446:A,R}
|
||||
phd{x<3427:A,R}
|
||||
hmf{a>804:gsn,s<1343:btv,vsf}
|
||||
cdj{a>358:mdl,a<238:A,nk}
|
||||
xs{x>2559:A,m>1333:A,A}
|
||||
phv{m<2219:R,m<2257:R,x<565:A,A}
|
||||
rx{s<2069:nvr,m>2736:qr,R}
|
||||
vld{x>969:A,s>1063:A,m<689:R,A}
|
||||
drn{s>1516:kx,m<611:kbn,jff}
|
||||
jlg{s<2849:tgr,qlb}
|
||||
nrn{a<1365:xmh,a>1565:A,x<1595:R,fgv}
|
||||
fx{x>3184:R,a<1161:R,x<2964:A,R}
|
||||
nfm{m<3293:R,m<3660:A,A}
|
||||
cft{a<735:A,a>1165:jdq,m<1013:ctl,xdg}
|
||||
grs{x<630:chb,bp}
|
||||
tsq{s<3424:klj,s>3632:rkq,tj}
|
||||
ll{a<566:R,R}
|
||||
zc{m<1722:A,x>1506:A,x>1464:R,A}
|
||||
tmx{s>3389:A,x>2770:A,R}
|
||||
jdq{s>1592:A,R}
|
||||
hhb{m<728:R,s<3217:bf,kfz}
|
||||
chb{s>1613:A,A}
|
||||
zcv{m<1690:A,a>1254:cb,R}
|
||||
gdt{s<2338:R,a>529:R,A}
|
||||
lrd{s>1816:A,s<1737:R,x>3648:vhm,mxs}
|
||||
dl{s>1645:A,A}
|
||||
rdr{m<3263:lmt,nrn}
|
||||
dbp{x>1326:R,A}
|
||||
vr{m<2215:R,A}
|
||||
dqb{m>1367:A,s>3854:A,A}
|
||||
mj{x<3291:xmd,m<1474:A,x>3594:fp,mk}
|
||||
cvq{s<3167:vz,x>3484:dzt,m>1895:qsk,dj}
|
||||
hrq{m>912:zn,s<2570:pk,x<3198:A,A}
|
||||
tq{m<525:A,A}
|
||||
cx{s>971:xbb,a>2286:R,s>558:lv,R}
|
||||
vlz{s<432:bdx,m>419:R,m<201:fh,cm}
|
||||
hsm{x>3894:psb,s>3500:A,zh}
|
||||
pmv{m>1260:xn,x<1634:tkk,A}
|
||||
mt{m<3482:lps,R}
|
||||
qs{x>214:R,m<2255:A,A}
|
||||
pf{m>399:R,x>3064:R,R}
|
||||
fd{s>3477:A,R}
|
||||
cmp{a>553:A,R}
|
||||
gbx{s>657:R,m>939:A,m<824:A,A}
|
||||
hsn{a>2953:drn,m>656:kzh,x<1575:xm,vpx}
|
||||
vmr{a<696:A,m>594:R,s<2925:A,R}
|
||||
hv{m>2584:R,m>2556:A,R}
|
||||
gq{m<3154:A,x>3367:hmd,rsn}
|
||||
tpc{x>3467:A,m>1865:A,m<1087:R,R}
|
||||
vf{x>567:A,R}
|
||||
xq{s>2490:ll,jj}
|
||||
dx{m<213:mx,x<981:qtt,a<1191:A,ktx}
|
||||
sq{s<518:jtt,a<1365:fbb,spl}
|
||||
ds{m<1024:R,x<1332:A,A}
|
||||
nn{m<337:srx,tx}
|
||||
xf{a>645:cnc,R}
|
||||
ltv{m<3188:cp,pt}
|
||||
gjp{a<3444:R,A}
|
||||
tbx{a>2651:bv,zx}
|
||||
qf{a<3156:cmf,s>3778:gkk,x<1377:lk,jqq}
|
||||
qdf{m>3031:A,s>3921:cqp,fg}
|
||||
zx{s>2703:R,s<2561:gts,a>2305:A,snk}
|
||||
xlj{a<240:R,R}
|
||||
rl{x>3006:cdj,a>458:njj,vpn}
|
||||
psq{a>939:tnp,m<1665:mnk,rpj}
|
||||
bc{a<486:knh,m<3114:gth,lcr}
|
||||
zq{x<1396:R,x<1668:A,R}
|
||||
xm{x<973:cx,llb}
|
||||
fzx{x>1946:A,x>1916:A,s>2523:dgq,bz}
|
||||
gr{s<3443:A,R}
|
||||
rsh{m<2322:A,R}
|
||||
lzn{m<3606:A,m<3836:vql,a<423:R,R}
|
||||
rsn{s<2344:A,a>1284:A,m<3610:A,A}
|
||||
rg{m<752:A,s<3018:A,s<3072:R,R}
|
||||
drs{a>2000:A,A}
|
||||
ctl{s<1467:R,x>675:R,a<885:R,A}
|
||||
fvm{a>168:A,s>868:R,R}
|
||||
mtn{a>310:R,R}
|
||||
rbt{x>3216:R,A}
|
||||
dzt{m<1618:prn,zxd}
|
||||
cp{x>616:A,m<2469:qs,R}
|
||||
zkk{a>806:R,s<1275:A,a>636:A,R}
|
||||
jrp{a>1285:A,A}
|
||||
crv{m>183:R,x>1678:mbr,A}
|
||||
mk{m>2781:R,x<3408:R,x<3508:A,A}
|
||||
qvp{x<2839:R,s>2645:A,R}
|
||||
tj{m>3041:jxs,m<2346:R,A}
|
||||
gj{s<1310:R,R}
|
||||
dd{a>700:dx,s<1439:xg,rfd}
|
||||
ptj{m>919:cft,a<819:bq,grs}
|
||||
qbq{a>1005:A,x>1477:A,A}
|
||||
nmh{a>884:R,a>308:R,s<2046:R,hnp}
|
||||
lx{a<901:A,m>593:R,R}
|
||||
pqd{x>1493:A,x<1235:A,A}
|
||||
bnh{m<1280:R,s<3302:R,R}
|
||||
tv{a<332:zg,gdt}
|
||||
rnd{a<1518:R,a>1596:A,A}
|
||||
jlb{a>2132:R,s>736:R,x<1111:A,R}
|
||||
mmz{x>992:R,a<1403:R,x<929:A,R}
|
||||
qfp{m>1069:R,A}
|
||||
pt{s>1650:vf,s>1452:R,x<446:A,vj}
|
||||
tkk{s<1160:A,m>1174:R,a<673:R,A}
|
||||
kx{x>2642:R,s<1888:A,R}
|
||||
dq{x<1992:sc,x>2131:mjs,cmp}
|
||||
xbb{s>1608:A,a<2166:A,s<1285:R,A}
|
||||
btv{s>646:R,A}
|
||||
br{a<1023:kxf,sds}
|
||||
nr{m>2923:R,s>3647:R,m>2756:R,R}
|
||||
nhn{x<1067:ltv,rdr}
|
||||
mbr{x>3214:A,A}
|
||||
mrv{m>400:R,m<212:A,A}
|
||||
vpx{a>2478:tnz,s>821:nn,a<2119:vlz,vkv}
|
||||
hn{x>2956:A,A}
|
||||
jz{a<775:R,A}
|
||||
pqp{m>731:A,A}
|
||||
gbf{a>1519:pvj,m>715:gbx,rm}
|
||||
mz{m>549:R,x<2243:krf,a>3781:R,jm}
|
||||
gth{m>2216:brs,m>1852:xxk,a>662:R,A}
|
||||
bmn{s<892:A,R}
|
||||
pgh{s<2509:A,m<3134:R,R}
|
||||
kqd{s<2377:A,A}
|
||||
nhq{x>538:A,s<315:R,m<296:R,R}
|
||||
zhr{m>2625:kqd,tp}
|
||||
nrt{s<1274:A,x<1313:A,A}
|
||||
mp{a>2286:jd,psr}
|
||||
zn{m>1099:A,R}
|
||||
vkv{m>221:pf,s<542:qm,m<110:A,A}
|
||||
xdl{a<2851:nqc,s<2936:cvv,x>1808:kp,km}
|
||||
kfs{a>1392:bcv,s>2659:A,R}
|
||||
rcl{s>3400:R,m<528:A,R}
|
||||
fsl{s>1571:cxd,m>988:jrp,A}
|
||||
bd{m<486:R,R}
|
||||
sr{x<445:A,zdl}
|
||||
qt{s<3423:gkm,x<3311:A,m>745:R,bqz}
|
||||
zfp{x>1123:nqq,A}
|
||||
gbd{a>1434:A,x<2274:A,m>947:R,R}
|
||||
kbn{x<1675:R,sz}
|
||||
mb{m<1446:hvq,ch}
|
||||
bcg{a>2036:A,a<1912:A,R}
|
||||
mv{s<2113:jkk,s>2853:fd,xs}
|
||||
dgq{a<1317:R,m>2464:R,m<2017:A,A}
|
||||
dt{s<2641:R,m<702:A,R}
|
||||
stf{m<199:A,R}
|
||||
sh{m>261:R,a<915:A,R}
|
||||
dv{a>2613:A,R}
|
||||
zd{a<554:cdx,a<841:kjj,x<798:mlm,sg}
|
||||
jn{a<3252:A,x<2123:R,A}
|
||||
lvp{a>277:A,nf}
|
||||
fh{m>123:R,A}
|
||||
lt{x>1632:R,s<654:R,a<325:R,R}
|
||||
lcr{a<720:A,m>3584:A,R}
|
||||
jfx{s>1699:R,x>616:A,A}
|
||||
hg{s<2617:xmj,a<850:R,s>2800:A,A}
|
||||
vpd{m<2602:R,a<1388:R,x<2900:rnd,A}
|
||||
mc{x<1595:A,x<1769:R,x>1809:A,A}
|
||||
hnq{x>2458:A,s<1704:R,A}
|
||||
bp{x<1089:A,x<1479:A,R}
|
||||
lps{x>2602:R,A}
|
||||
gmh{m<2825:R,A}
|
||||
dmp{a<1343:dl,x<2089:A,x>2165:A,R}
|
||||
bbg{x<415:A,m<580:A,a>1069:mdk,nj}
|
||||
qlb{m<838:nl,m<1169:pq,x<799:pl,dxj}
|
||||
ms{s<3815:hn,a<1068:lqt,qdf}
|
||||
lh{s<885:vkl,m>1432:pn,a>1109:pd,vb}
|
||||
fg{s<3875:R,m<2292:A,x>2987:A,R}
|
||||
sgx{x>2162:R,x>2109:A,R}
|
||||
fb{x>2219:bc,sx}
|
||||
gh{a<2425:R,R}
|
||||
zj{s<1096:xlj,R}
|
||||
rc{a>1099:R,m>1634:jpf,x<1066:A,R}
|
||||
lxp{a>1410:tpc,s>2961:qgx,R}
|
||||
rsc{m<134:A,m>220:A,R}
|
||||
xr{s<789:pj,m>812:hq,s<967:xvt,vld}
|
||||
jq{a<892:zcf,m<3084:fn,R}
|
||||
jx{m<668:bzx,a>1083:R,A}
|
||||
ft{s>2537:R,x>3546:R,x>3014:A,pgh}
|
||||
db{a<998:R,s<1612:R,x>2784:A,R}
|
||||
vd{s>2660:pqk,a<3336:rsc,a>3760:hvb,A}
|
||||
cn{s>2852:R,m>2099:rsh,dxk}
|
||||
tjz{x<3743:R,s>3348:ssv,s>3252:R,kkm}
|
||||
nlt{a<205:R,x>1400:R,a<276:A,A}
|
||||
xvt{m>687:R,x<799:A,A}
|
||||
hp{m>1850:hg,m<1700:rc,s>2663:hl,jr}
|
||||
kch{m>1902:A,R}
|
||||
llb{s<1505:R,x<1208:R,x>1337:krp,R}
|
||||
tmk{x<647:tcj,x<1410:hp,x>1663:xq,cgj}
|
||||
psj{x<2003:hnh,R}
|
||||
szq{x<2455:A,x>2571:R,R}
|
||||
nxc{s<3784:A,s<3926:A,x>3006:A,A}
|
||||
ph{x>2866:ts,ngq}
|
||||
zh{a>920:A,R}
|
||||
md{x>809:hf,x<467:lh,zjr}
|
||||
kd{a<1002:jt,x<3170:vpd,pfg}
|
||||
sc{x<1928:A,a<406:R,m>2129:R,A}
|
||||
vg{a<2146:R,m<798:R,s>1349:R,A}
|
||||
clg{s<1574:A,A}
|
||||
gd{a<1867:R,s>1838:R,m>3359:R,A}
|
||||
dxk{a<463:A,s<2763:R,s<2797:R,R}
|
||||
prx{a>3468:vk,m<2059:rbt,x>3171:hk,qvp}
|
||||
fcn{x<1040:R,s>626:R,x<1572:A,A}
|
||||
srx{m>147:R,m<80:A,R}
|
||||
dzv{x>2236:zhr,a<1268:zll,tt}
|
||||
bx{s>2165:A,x<3424:A,s<2155:A,R}
|
||||
sx{m<2846:dq,s<2128:mq,s>3114:gf,lzn}
|
||||
mmt{m>667:R,R}
|
||||
zll{s>2412:sfz,x>2017:sbh,tm}
|
||||
hnp{s>2072:R,R}
|
||||
pl{x>413:R,m<1336:R,x<211:R,jz}
|
||||
dr{a>1530:R,A}
|
||||
qzf{s>2145:bx,a<1033:R,kfx}
|
||||
rj{a<3192:A,s>3193:R,m>697:A,A}
|
||||
fnd{x>449:A,s>115:R,R}
|
||||
vk{m<2203:A,s>2735:R,x>3249:R,A}
|
||||
vxh{m>559:bxz,x<777:R,R}
|
||||
tpp{x<1376:hh,bmn}
|
||||
nk{s<810:R,a>313:A,a>264:R,A}
|
||||
nvr{s>792:A,x>1945:R,R}
|
||||
zxd{x<3810:xf,m<2542:hsm,cg}
|
||||
kz{s<606:R,m>1077:A,A}
|
||||
bkc{x>2757:A,R}
|
||||
xnx{m>3422:A,a>711:R,s<3019:R,A}
|
||||
tjf{a<744:R,a>1261:A,a>1039:fx,zsx}
|
||||
kc{m>1735:R,A}
|
||||
tgr{x>786:xjb,bbg}
|
||||
td{a>3522:xqd,x>2536:R,x<2142:dlg,rj}
|
||||
zrh{m>1071:md,s<1184:kg,jrv}
|
||||
gsn{a<885:A,a>912:R,R}
|
||||
ldb{a>254:R,R}
|
||||
qx{a>982:A,m<2418:R,R}
|
||||
kp{s<3127:rg,s>3291:pb,x<3205:td,hhb}
|
||||
rr{s<2162:R,R}
|
||||
sj{m<572:R,A}
|
||||
st{x<2946:A,x>3298:A,a<700:R,R}
|
||||
sp{m<2339:R,s>3855:A,R}
|
||||
zzx{m<3186:dm,xl}
|
||||
bcv{s<2617:A,a>1559:R,x>1488:A,A}
|
||||
xhj{s>2477:A,R}
|
||||
fp{x>3859:R,R}
|
||||
nx{m<1903:A,bsc}
|
||||
gpf{m<821:A,m>1201:R,s<3661:R,R}
|
||||
bxc{x>1591:R,A}
|
||||
mx{m>85:R,R}
|
||||
dql{s>1910:lpf,m>2088:dzq,zrh}
|
||||
fvx{a<1533:A,A}
|
||||
snb{m>1043:A,s<1569:vg,m<829:A,mh}
|
||||
rp{x<289:A,A}
|
||||
xxk{m<1974:A,s<1985:A,R}
|
||||
qr{s<3186:A,a>1382:R,s>3578:A,A}
|
||||
jrv{m<380:dd,m<830:hhr,ptj}
|
||||
skq{x>635:A,hx}
|
||||
rpj{s>3338:kn,a>391:A,R}
|
||||
zs{m>2355:R,a>863:A,s<3650:A,A}
|
||||
rvd{s>1220:R,s<494:jzq,s<762:nlj,A}
|
||||
qm{x<2515:R,R}
|
||||
sqt{a<1023:A,R}
|
||||
lcl{m<2710:A,m<3464:R,m<3759:R,R}
|
||||
gkk{s<3899:R,a>3581:A,a<3426:R,rhd}
|
||||
fr{s<2683:njl,R}
|
||||
nhz{a<947:A,m>1908:R,m>1673:A,A}
|
||||
rlp{s<774:A,R}
|
||||
bf{s<3175:A,R}
|
||||
psr{x>1061:R,a<1875:A,x>357:R,A}
|
||||
nqs{x<319:A,s<3699:A,x>463:kch,R}
|
||||
fxs{s<3617:R,a<1444:A,A}
|
||||
dxj{m>1297:gn,flt}
|
||||
mhl{m>1106:R,s>1412:A,s<1288:R,R}
|
||||
cgf{x<3874:R,m>3565:A,A}
|
||||
qtt{x<603:A,m<300:R,x>743:R,R}
|
||||
sd{x<3134:A,x>3645:qfp,x<3407:hc,R}
|
||||
lpf{m>2444:cz,m<1547:jlg,s<3133:tmk,bt}
|
||||
bbp{a>1097:lxp,m<2430:mvh,nd}
|
||||
kkg{s>1504:fvx,s>961:gbd,x<2356:dr,A}
|
||||
vxr{m<1531:A,m<1719:R,x<357:R,R}
|
||||
mvh{m<1146:vmr,a<380:R,R}
|
||||
csf{x>2650:pxr,a<2576:R,vv}
|
||||
qzs{m<868:R,x<471:A,R}
|
||||
sl{x<2677:hrh,s>1997:cvq,xpq}
|
||||
hnh{s<2435:A,a<1516:A,a>1606:R,R}
|
||||
bq{x<943:qzs,m>870:cr,mvd}
|
||||
rq{a>2886:nrt,m>2662:gh,hv}
|
||||
dm{a<495:mtn,a>678:bpt,ng}
|
||||
mxs{a>470:R,x>3575:A,A}
|
||||
gxm{m>1455:A,a>431:R,R}
|
||||
bzx{a>1117:R,s<2331:A,A}
|
||||
tcj{a>1108:jkx,s>2661:cn,a>647:sgg,htm}
|
||||
zl{x<1326:R,a<186:R,A}
|
||||
bqz{a>544:A,a<307:R,A}
|
||||
xkg{x<1915:A,A}
|
||||
cdx{a>339:rlp,x<772:A,a>152:npv,jk}
|
||||
bz{a>1306:R,x<1884:R,x<1901:R,A}
|
||||
hd{x>441:A,m>802:A,A}
|
||||
kh{x>3037:R,cmk}
|
||||
mn{a<482:A,A}
|
||||
pk{s<2557:A,R}
|
||||
nqq{a>559:A,s<3600:A,x>1458:A,R}
|
||||
nrs{a>2275:R,a>2016:R,gd}
|
||||
rpk{s<2091:nmh,s>2183:mj,m<2279:tf,qzf}
|
||||
mlm{x<388:R,m>571:A,s<752:nhq,sh}
|
||||
jxs{a>2736:A,R}
|
||||
ks{x<974:A,a>1269:A,x>1159:R,R}
|
||||
xmh{m<3623:A,m<3765:A,R}
|
||||
hrh{m<1654:jrz,a<980:fb,dzv}
|
||||
tp{m<2079:hnq,kcb}
|
||||
fv{m>1406:ft,s<2551:vbg,hrq}
|
||||
bpt{a<758:A,m<2540:A,R}
|
||||
vql{x<1984:A,a>515:A,a<192:A,A}
|
||||
bs{m>2823:A,A}
|
||||
nf{m>644:R,R}
|
||||
ssv{s<3440:A,A}
|
||||
rfd{s<1718:clg,s>1797:stf,m<251:R,A}
|
||||
lq{a>646:R,x>1191:R,R}
|
||||
rv{a<531:zj,rvd}
|
||||
tz{s>403:A,s>222:R,A}
|
||||
gk{a<2728:R,x<3291:A,a>2857:R,R}
|
||||
vjj{x>745:zfp,nqs}
|
||||
cqp{x>2993:A,m<2484:R,a<1361:A,A}
|
||||
xqd{s>3201:A,R}
|
||||
cr{s>1438:A,a<283:A,x<1533:A,A}
|
||||
xdg{s>1494:A,R}
|
||||
xjb{s<2508:pqd,s>2732:xcm,s>2589:dt,ds}
|
||||
nnd{a>1189:sq,dck}
|
||||
brs{s<1860:A,x>2522:R,A}
|
||||
jm{s<3472:A,m>227:A,m<99:A,A}
|
||||
mh{m<948:A,m>1009:R,R}
|
||||
lm{s<2631:A,A}
|
||||
qgx{m>1733:A,a<1279:A,s>3061:R,A}
|
||||
kjg{m>757:tmx,A}
|
||||
njl{a<3412:R,s>2568:R,s>2458:R,A}
|
||||
mnk{m>1403:phx,m>1317:R,a>417:st,bnh}
|
||||
vb{a>478:zkk,bn}
|
||||
tnp{x<3103:A,x>3353:dkv,m<1534:A,sv}
|
||||
plz{a<2245:A,A}
|
||||
hhr{s>1496:vxh,sj}
|
||||
nv{m>3730:R,R}
|
||||
km{x<978:hd,rqf}
|
||||
dgs{m<245:A,s<1274:A,R}
|
||||
tnb{s>3817:pth,x>3774:A,gpf}
|
||||
cq{a<1034:mn,mmz}
|
||||
dck{s>410:cxs,m<2779:qx,jb}
|
||||
cm{a>1896:R,A}
|
||||
kms{a>2292:R,x<1613:drs,m>1261:bcg,A}
|
||||
bdx{m>310:R,s<240:A,s>356:R,A}
|
||||
rqf{s>3178:A,zdp}
|
||||
xmj{m>2206:A,R}
|
||||
hf{m>1482:jp,x<1267:cq,pmv}
|
||||
vv{s<3498:A,x>954:A,x>375:A,R}
|
||||
bxn{m>622:A,x<3163:A,A}
|
||||
lqt{m<3266:A,a<374:A,a<656:R,A}
|
||||
kjd{a>215:R,A}
|
||||
lvs{s<2888:lm,A}
|
||||
jcz{x>988:xd,mxf}
|
||||
bt{m<2092:vjj,jcz}
|
||||
gm{a>795:A,m>3022:R,R}
|
||||
prn{s>3549:tnb,tjz}
|
||||
tjj{s<1166:zkd,s>1652:lrd,x<3663:sxt,rft}
|
||||
tt{a>1417:psj,x>2002:dmp,a>1352:rx,fzx}
|
||||
nj{m<1121:R,R}
|
||||
qkh{m>3145:pnj,dkl}
|
||||
ch{s>2396:dg,cv}
|
||||
zm{x>625:A,x<542:A,m>1927:A,R}
|
||||
lmt{m>2506:R,s<1559:R,m>2329:mc,vxn}
|
||||
fbb{a<1249:R,s<765:A,R}
|
||||
nlj{s<671:R,x<425:R,R}
|
||||
frt{m<454:srz,a>1436:gbf,xr}
|
||||
cv{m>2927:qd,tbl}
|
||||
vz{s>2596:bbp,s<2247:rpk,s>2462:fv,ssd}
|
||||
pbv{s>1407:ldb,s>929:A,kz}
|
||||
bgx{x<941:rv,zzx}
|
||||
pfg{x>3349:zzt,nfm}
|
||||
ssd{m<2231:tjf,a>683:gq,tv}
|
||||
cmf{s<3771:xj,m<1213:plz,dqb}
|
||||
qsk{s<3510:kd,ms}
|
||||
mjs{s<1429:A,A}
|
||||
dj{s>3501:br,m>1254:psq,x<3181:hm,fvf}
|
||||
hmd{m<3500:R,m>3704:R,A}
|
||||
tx{x>2397:R,x<1870:A,s<1560:A,R}
|
||||
ts{a<1021:A,x>2977:R,lcl}
|
||||
sfz{m>2706:A,s>3253:A,A}
|
||||
vrz{m>3406:R,m<2945:A,A}
|
||||
psb{x>3943:R,R}
|
||||
hvb{m>189:A,m<82:R,A}
|
||||
xk{x<1541:dbp,m<3333:xpg,s<2457:R,nv}
|
||||
jkx{s<2566:R,A}
|
||||
trm{a>3458:A,A}
|
||||
xl{a>319:A,m>3484:zl,nlt}
|
||||
mvd{a>391:A,m>852:R,A}
|
||||
mdk{m<1132:R,m>1384:A,R}
|
||||
ql{a>2685:dlh,xdc}
|
||||
tg{x>1137:xk,sr}
|
||||
xcm{s>2808:A,R}
|
||||
dkv{m>1597:A,a<1295:R,m>1451:A,A}
|
||||
pq{x>685:zq,A}
|
||||
hcq{m<1264:A,a>3456:R,x<3097:R,R}
|
||||
gfh{a<942:R,s>187:A,m>3151:A,R}
|
||||
nqc{m>952:kms,m<498:crv,x<1886:mp,lvs}
|
||||
zv{a<2363:A,s>2848:A,dv}
|
||||
kg{a<990:zd,frt}
|
||||
sxt{x>3571:mhl,s>1399:R,R}
|
||||
rcb{s>831:R,R}
|
||||
ct{m<2782:R,x<2144:R,R}
|
||||
jk{x>1280:R,a<62:R,a<97:A,A}
|
||||
xpg{s<2389:R,x>1653:R,x>1605:A,A}
|
||||
rm{s>756:R,s<272:A,A}
|
||||
zt{m<1571:R,x>357:R,s<90:R,R}
|
||||
kzh{x>2664:sd,s<1123:jlb,snb}
|
||||
hk{a>3113:A,m<2299:R,R}
|
||||
xgd{s>3436:A,s<3413:A,m<2980:A,R}
|
||||
xn{a<733:A,x>1650:R,a<1166:A,R}
|
||||
zg{a>211:R,R}
|
||||
phx{m>1520:R,s<3316:R,A}
|
||||
nl{x>1066:rcl,R}
|
||||
gts{a<2156:R,A}
|
||||
cz{s<3196:tg,vts}
|
||||
flt{x<1306:R,m>1253:A,s<3466:R,R}
|
||||
mq{m<3476:R,a>643:R,m>3779:A,zk}
|
||||
xpq{m>1741:btr,kj}
|
||||
dlg{s<3232:R,s>3262:R,R}
|
||||
jcp{m<292:A,x<3654:A,a<245:A,A}
|
||||
sds{a>1440:A,x<3037:R,A}
|
||||
kjt{x<2493:bd,mjv}
|
||||
xd{x>1460:R,vr}
|
||||
dg{s>3110:tsq,x>2350:mf,tbx}
|
||||
snk{a>2064:A,m>2299:R,A}
|
||||
xj{s<3720:R,a>2638:A,A}
|
||||
cgj{a<890:ff,x>1546:nx,m<1898:zcv,kfs}
|
||||
srz{a>1345:A,A}
|
||||
pn{s<1253:A,R}
|
||||
ktx{a<1448:A,a<1571:A,A}
|
||||
mdl{s<786:R,m<811:A,A}
|
||||
jqq{s>3703:gjp,hcq}
|
||||
rjk{s>459:A,x>3536:A,A}
|
||||
cxs{s>846:pnb,s>638:R,A}
|
||||
jtt{s>281:gmh,x<928:fnd,s<175:A,A}
|
||||
ngq{s>979:db,x<2798:tz,m>2572:R,sqt}
|
||||
qb{m>669:R,A}
|
||||
pvj{m>712:R,x>690:R,a>1577:R,A}
|
||||
|
||||
{x=396,m=612,a=2012,s=177}
|
||||
{x=39,m=25,a=812,s=272}
|
||||
{x=1930,m=15,a=99,s=905}
|
||||
{x=373,m=1162,a=3153,s=1794}
|
||||
{x=1045,m=108,a=1143,s=639}
|
||||
{x=2178,m=621,a=580,s=172}
|
||||
{x=1292,m=1910,a=122,s=2528}
|
||||
{x=275,m=192,a=83,s=2992}
|
||||
{x=2218,m=157,a=99,s=545}
|
||||
{x=822,m=2795,a=82,s=150}
|
||||
{x=2178,m=12,a=1672,s=1504}
|
||||
{x=2463,m=620,a=882,s=1746}
|
||||
{x=1025,m=1370,a=21,s=45}
|
||||
{x=3161,m=944,a=884,s=1590}
|
||||
{x=285,m=849,a=595,s=2630}
|
||||
{x=423,m=480,a=177,s=2385}
|
||||
{x=2022,m=777,a=1166,s=371}
|
||||
{x=195,m=1446,a=1622,s=727}
|
||||
{x=1831,m=1163,a=710,s=98}
|
||||
{x=2054,m=767,a=416,s=462}
|
||||
{x=814,m=1038,a=1871,s=118}
|
||||
{x=2109,m=136,a=69,s=265}
|
||||
{x=30,m=745,a=2265,s=2135}
|
||||
{x=92,m=1923,a=1269,s=62}
|
||||
{x=2952,m=875,a=82,s=199}
|
||||
{x=1527,m=550,a=926,s=34}
|
||||
{x=84,m=1894,a=1418,s=3020}
|
||||
{x=1419,m=2050,a=2634,s=992}
|
||||
{x=19,m=1722,a=207,s=2292}
|
||||
{x=122,m=3195,a=179,s=979}
|
||||
{x=970,m=3603,a=193,s=1431}
|
||||
{x=515,m=681,a=501,s=459}
|
||||
{x=682,m=2621,a=1754,s=649}
|
||||
{x=1972,m=2722,a=215,s=2720}
|
||||
{x=358,m=2273,a=248,s=1091}
|
||||
{x=103,m=468,a=48,s=467}
|
||||
{x=111,m=251,a=199,s=55}
|
||||
{x=1536,m=541,a=1850,s=1349}
|
||||
{x=318,m=1491,a=1124,s=1821}
|
||||
{x=2441,m=1571,a=981,s=1207}
|
||||
{x=639,m=2165,a=588,s=658}
|
||||
{x=704,m=1423,a=2397,s=1207}
|
||||
{x=51,m=161,a=833,s=1036}
|
||||
{x=375,m=188,a=1668,s=681}
|
||||
{x=141,m=744,a=732,s=77}
|
||||
{x=341,m=1182,a=1040,s=249}
|
||||
{x=265,m=873,a=281,s=1691}
|
||||
{x=1022,m=37,a=1865,s=338}
|
||||
{x=1580,m=137,a=283,s=1031}
|
||||
{x=1361,m=1432,a=1179,s=2447}
|
||||
{x=617,m=1360,a=305,s=54}
|
||||
{x=235,m=733,a=60,s=2192}
|
||||
{x=362,m=181,a=1297,s=835}
|
||||
{x=133,m=132,a=1327,s=64}
|
||||
{x=573,m=263,a=741,s=98}
|
||||
{x=799,m=898,a=2180,s=732}
|
||||
{x=186,m=517,a=681,s=1168}
|
||||
{x=47,m=2806,a=3577,s=578}
|
||||
{x=3218,m=1130,a=1204,s=414}
|
||||
{x=2468,m=2891,a=900,s=2094}
|
||||
{x=215,m=1069,a=1689,s=1228}
|
||||
{x=372,m=937,a=725,s=412}
|
||||
{x=1434,m=1549,a=1539,s=1007}
|
||||
{x=3222,m=841,a=1854,s=1272}
|
||||
{x=2326,m=1637,a=1918,s=30}
|
||||
{x=1248,m=266,a=750,s=2521}
|
||||
{x=110,m=1288,a=364,s=749}
|
||||
{x=752,m=803,a=257,s=316}
|
||||
{x=1777,m=1615,a=942,s=110}
|
||||
{x=227,m=1524,a=1800,s=309}
|
||||
{x=105,m=246,a=1723,s=3455}
|
||||
{x=713,m=1172,a=833,s=804}
|
||||
{x=3026,m=39,a=376,s=71}
|
||||
{x=946,m=3437,a=1461,s=149}
|
||||
{x=1878,m=303,a=207,s=1081}
|
||||
{x=2982,m=2510,a=14,s=3078}
|
||||
{x=818,m=1042,a=943,s=958}
|
||||
{x=2349,m=7,a=802,s=822}
|
||||
{x=140,m=473,a=2454,s=3331}
|
||||
{x=1014,m=796,a=1453,s=348}
|
||||
{x=1578,m=2615,a=539,s=294}
|
||||
{x=993,m=276,a=564,s=2618}
|
||||
{x=2908,m=327,a=705,s=1430}
|
||||
{x=46,m=361,a=291,s=1076}
|
||||
{x=2267,m=212,a=952,s=365}
|
||||
{x=677,m=2277,a=550,s=1061}
|
||||
{x=226,m=1391,a=653,s=2321}
|
||||
{x=1654,m=15,a=27,s=421}
|
||||
{x=974,m=241,a=255,s=283}
|
||||
{x=202,m=84,a=1805,s=81}
|
||||
{x=337,m=529,a=254,s=42}
|
||||
{x=765,m=2055,a=473,s=413}
|
||||
{x=1731,m=81,a=370,s=133}
|
||||
{x=2839,m=739,a=513,s=990}
|
||||
{x=376,m=660,a=924,s=65}
|
||||
{x=627,m=1486,a=1422,s=2326}
|
||||
{x=2688,m=2,a=659,s=347}
|
||||
{x=1388,m=1650,a=1875,s=363}
|
||||
{x=305,m=1406,a=1285,s=50}
|
||||
{x=1095,m=382,a=2098,s=1120}
|
||||
{x=1172,m=402,a=1935,s=1646}
|
||||
{x=27,m=357,a=714,s=355}
|
||||
{x=42,m=45,a=217,s=1134}
|
||||
{x=22,m=415,a=624,s=358}
|
||||
{x=324,m=3057,a=221,s=3288}
|
||||
{x=540,m=179,a=1033,s=568}
|
||||
{x=7,m=999,a=453,s=316}
|
||||
{x=231,m=428,a=1092,s=8}
|
||||
{x=2221,m=3036,a=22,s=735}
|
||||
{x=247,m=516,a=339,s=1756}
|
||||
{x=3140,m=2229,a=1643,s=2012}
|
||||
{x=1248,m=500,a=624,s=779}
|
||||
{x=1245,m=1806,a=579,s=2269}
|
||||
{x=989,m=442,a=671,s=419}
|
||||
{x=266,m=1547,a=992,s=664}
|
||||
{x=1078,m=24,a=1069,s=1848}
|
||||
{x=908,m=1979,a=1027,s=956}
|
||||
{x=78,m=719,a=1328,s=105}
|
||||
{x=901,m=601,a=3503,s=1239}
|
||||
{x=949,m=851,a=356,s=1086}
|
||||
{x=315,m=565,a=1868,s=857}
|
||||
{x=1426,m=1398,a=918,s=1629}
|
||||
{x=1286,m=2229,a=500,s=16}
|
||||
{x=360,m=481,a=2006,s=991}
|
||||
{x=1514,m=2442,a=1921,s=183}
|
||||
{x=2155,m=1924,a=616,s=986}
|
||||
{x=2121,m=1323,a=352,s=958}
|
||||
{x=756,m=2750,a=543,s=2608}
|
||||
{x=833,m=168,a=2410,s=232}
|
||||
{x=3,m=810,a=451,s=40}
|
||||
{x=1151,m=452,a=1642,s=965}
|
||||
{x=560,m=2062,a=2265,s=846}
|
||||
{x=1,m=246,a=905,s=323}
|
||||
{x=1642,m=193,a=448,s=25}
|
||||
{x=86,m=486,a=588,s=75}
|
||||
{x=2360,m=5,a=417,s=2689}
|
||||
{x=676,m=947,a=402,s=355}
|
||||
{x=1869,m=44,a=944,s=1139}
|
||||
{x=36,m=1033,a=588,s=391}
|
||||
{x=63,m=31,a=608,s=817}
|
||||
{x=1115,m=2098,a=617,s=702}
|
||||
{x=2117,m=848,a=2371,s=3170}
|
||||
{x=270,m=2617,a=393,s=330}
|
||||
{x=325,m=3377,a=870,s=1077}
|
||||
{x=275,m=139,a=876,s=648}
|
||||
{x=657,m=231,a=2197,s=915}
|
||||
{x=1934,m=1410,a=1965,s=1574}
|
||||
{x=251,m=841,a=480,s=24}
|
||||
{x=771,m=479,a=107,s=2259}
|
||||
{x=1364,m=166,a=27,s=664}
|
||||
{x=774,m=303,a=909,s=93}
|
||||
{x=264,m=164,a=3471,s=176}
|
||||
{x=681,m=2247,a=1660,s=837}
|
||||
{x=1348,m=204,a=990,s=219}
|
||||
{x=650,m=1469,a=1269,s=1160}
|
||||
{x=1121,m=534,a=2270,s=927}
|
||||
{x=322,m=1871,a=693,s=170}
|
||||
{x=540,m=462,a=929,s=99}
|
||||
{x=3015,m=915,a=808,s=3661}
|
||||
{x=248,m=383,a=471,s=106}
|
||||
{x=1536,m=1350,a=2067,s=804}
|
||||
{x=1656,m=56,a=1629,s=995}
|
||||
{x=17,m=236,a=288,s=218}
|
||||
{x=663,m=1611,a=317,s=1272}
|
||||
{x=630,m=2397,a=1538,s=805}
|
||||
{x=211,m=2,a=137,s=514}
|
||||
{x=2340,m=191,a=173,s=618}
|
||||
{x=2154,m=6,a=42,s=884}
|
||||
{x=526,m=1292,a=694,s=1722}
|
||||
{x=606,m=355,a=1532,s=1351}
|
||||
{x=1405,m=543,a=126,s=3}
|
||||
{x=548,m=429,a=1382,s=572}
|
||||
{x=95,m=1008,a=1790,s=42}
|
||||
{x=1796,m=1272,a=188,s=201}
|
||||
{x=1437,m=3161,a=754,s=4}
|
||||
{x=891,m=447,a=1389,s=145}
|
||||
{x=183,m=894,a=821,s=1455}
|
||||
{x=457,m=79,a=1586,s=1179}
|
||||
{x=1631,m=828,a=2697,s=73}
|
||||
{x=56,m=506,a=1988,s=448}
|
||||
{x=3408,m=971,a=2130,s=1899}
|
||||
{x=347,m=1915,a=193,s=1460}
|
||||
{x=308,m=3,a=1189,s=191}
|
||||
{x=2,m=354,a=2761,s=287}
|
||||
{x=634,m=864,a=101,s=233}
|
||||
{x=632,m=91,a=1935,s=202}
|
||||
{x=27,m=1364,a=2765,s=2}
|
||||
{x=367,m=510,a=473,s=132}
|
||||
{x=987,m=2516,a=1834,s=1121}
|
||||
{x=626,m=845,a=176,s=265}
|
||||
{x=577,m=823,a=2129,s=23}
|
||||
{x=802,m=295,a=389,s=226}
|
||||
{x=844,m=301,a=549,s=126}
|
||||
{x=1139,m=235,a=9,s=1183}
|
||||
{x=663,m=2444,a=554,s=1516}
|
||||
{x=1244,m=355,a=252,s=1023}
|
||||
{x=151,m=2238,a=392,s=93}
|
||||
{x=99,m=1911,a=362,s=1272}
|
||||
{x=71,m=146,a=46,s=1359}
|
||||
{x=1140,m=650,a=75,s=1458}
|
||||
17
day19/sample.txt
Normal file
17
day19/sample.txt
Normal file
@@ -0,0 +1,17 @@
|
||||
px{a<2006:qkq,m>2090:A,rfg}
|
||||
pv{a>1716:R,A}
|
||||
lnx{m>1548:A,A}
|
||||
rfg{s<537:gd,x>2440:R,A}
|
||||
qs{s>3448:A,lnx}
|
||||
qkq{x<1416:A,crn}
|
||||
crn{x>2662:A,R}
|
||||
in{s<1351:px,qqz}
|
||||
qqz{s>2770:qs,m<1801:hdj,R}
|
||||
gd{a>3333:R,R}
|
||||
hdj{m>838:A,pv}
|
||||
|
||||
{x=787,m=2655,a=1222,s=2876}
|
||||
{x=1679,m=44,a=2067,s=496}
|
||||
{x=2036,m=264,a=79,s=2244}
|
||||
{x=2461,m=1339,a=466,s=291}
|
||||
{x=2127,m=1623,a=2188,s=1013}
|
||||
BIN
day2/c/day2
Executable file
BIN
day2/c/day2
Executable file
Binary file not shown.
75
day2/c/day2.c
Normal file
75
day2/c/day2.c
Normal file
@@ -0,0 +1,75 @@
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
#include <string.h>
|
||||
|
||||
#define LINE_MAX_LENGTH 256
|
||||
|
||||
#define RED_CUBES 12
|
||||
#define GREEN_CUBES 13
|
||||
#define BLUE_CUBES 14
|
||||
#define max(a, b) (a > b ? a : b)
|
||||
|
||||
int main() {
|
||||
char *p, *buf, c;
|
||||
int sum = 0, id = 0, count = 0;
|
||||
unsigned int part2_sum = 0;
|
||||
|
||||
buf = (char *)malloc(LINE_MAX_LENGTH);
|
||||
memset(buf, 0, LINE_MAX_LENGTH);
|
||||
p = buf;
|
||||
|
||||
while ((c = getchar()) != EOF) {
|
||||
*p++ = c;
|
||||
if (c == '\n') {
|
||||
int possible = 1;
|
||||
int r = 0, g = 0, b = 0;
|
||||
p = buf;
|
||||
// Read Game ID
|
||||
sscanf(p, "Game %i", &id);
|
||||
// Move to char ':'
|
||||
while (*p++ != ':');
|
||||
|
||||
// Read draws
|
||||
for (;;) {
|
||||
sscanf(p, "%i %c", &count, &c);
|
||||
|
||||
if ((c == 'r' && count > RED_CUBES) || (c == 'g' && count > GREEN_CUBES) || (c == 'b' && count > BLUE_CUBES)) {
|
||||
possible = 0;
|
||||
}
|
||||
|
||||
switch (c) {
|
||||
case 'r':
|
||||
r = max(r, count);
|
||||
break;
|
||||
case 'g':
|
||||
g = max(g, count);
|
||||
break;
|
||||
case 'b':
|
||||
b = max(b, count);
|
||||
break;
|
||||
}
|
||||
// Read to next separator or end of line
|
||||
while (*p != '\n' && *p != ',' && *p != ';') p++;
|
||||
|
||||
if (*p == '\n') {
|
||||
break;
|
||||
}
|
||||
|
||||
p+=2;
|
||||
}
|
||||
|
||||
if (possible) {
|
||||
sum += id;
|
||||
}
|
||||
|
||||
part2_sum += r * g * b;
|
||||
|
||||
memset(buf, 0, LINE_MAX_LENGTH);
|
||||
p = buf;
|
||||
}
|
||||
}
|
||||
|
||||
free(buf);
|
||||
printf("%i\n", sum);
|
||||
printf("%u\n", part2_sum);
|
||||
}
|
||||
100
day2/input.txt
Normal file
100
day2/input.txt
Normal file
@@ -0,0 +1,100 @@
|
||||
Game 1: 1 red, 5 blue, 1 green; 16 blue, 3 red; 6 blue, 5 red; 4 red, 7 blue, 1 green
|
||||
Game 2: 4 blue; 4 red, 3 blue, 1 green; 4 red, 9 blue, 2 green; 5 blue, 7 green, 4 red
|
||||
Game 3: 10 blue; 7 blue, 1 green; 19 blue, 1 green, 9 red
|
||||
Game 4: 2 green; 14 blue, 14 red, 4 green; 12 red, 11 green, 13 blue; 5 green, 9 red, 4 blue; 9 red, 7 green, 12 blue; 2 green, 3 blue, 8 red
|
||||
Game 5: 3 blue, 4 red; 12 red, 2 green, 15 blue; 1 red, 10 blue, 1 green
|
||||
Game 6: 1 blue, 7 red; 3 green, 5 red, 1 blue; 1 green, 7 red; 6 red, 1 blue, 4 green; 1 green, 8 red, 1 blue; 2 green, 4 red, 1 blue
|
||||
Game 7: 11 green, 10 blue, 2 red; 1 green, 12 blue, 2 red; 9 green, 14 blue; 1 red, 19 blue, 15 green
|
||||
Game 8: 4 green, 2 red, 14 blue; 9 green, 1 red, 15 blue; 2 green, 9 red, 8 blue; 11 green, 7 red, 8 blue; 9 red, 7 green, 6 blue
|
||||
Game 9: 4 blue, 1 green, 2 red; 1 blue, 3 red; 1 red, 3 blue, 3 green
|
||||
Game 10: 4 red, 3 green, 6 blue; 2 green, 15 blue, 6 red; 3 green, 2 blue; 2 red, 1 green; 11 blue, 7 red, 4 green; 2 blue, 2 red, 4 green
|
||||
Game 11: 10 red, 1 green, 7 blue; 5 red, 2 green, 7 blue; 2 green, 4 blue; 1 green, 10 red, 10 blue; 8 blue, 4 red
|
||||
Game 12: 6 green, 2 blue, 7 red; 3 green, 2 blue, 3 red; 6 red, 1 blue, 9 green; 9 green, 13 red, 5 blue; 6 green, 4 blue, 8 red
|
||||
Game 13: 10 green, 4 red, 6 blue; 19 red, 6 green, 7 blue; 6 blue, 5 red, 8 green
|
||||
Game 14: 4 blue, 2 green; 19 blue; 6 red, 17 blue; 10 blue, 7 red; 1 green, 2 blue, 7 red
|
||||
Game 15: 4 green, 12 blue, 15 red; 10 blue, 18 green, 13 red; 20 blue, 6 green, 10 red; 20 red, 12 blue, 13 green; 12 blue, 17 green, 10 red; 1 red, 3 blue, 7 green
|
||||
Game 16: 1 blue, 6 red, 5 green; 3 red, 3 green; 5 green, 1 red; 2 red, 1 blue, 6 green; 1 blue, 1 red, 6 green; 1 blue, 6 green
|
||||
Game 17: 4 red, 3 blue, 3 green; 8 blue, 8 green; 5 red, 3 green, 9 blue; 9 green, 12 blue, 13 red; 1 green, 1 blue, 5 red; 7 green, 6 red
|
||||
Game 18: 2 green, 11 blue, 6 red; 2 green, 11 red, 2 blue; 7 red, 4 blue, 9 green; 18 blue, 6 red, 1 green
|
||||
Game 19: 4 red, 7 green, 17 blue; 5 green, 6 red, 4 blue; 4 blue, 4 red, 1 green
|
||||
Game 20: 2 blue, 5 green, 9 red; 4 green, 8 red, 10 blue; 7 blue, 9 red, 1 green; 1 green, 10 blue, 9 red; 1 green, 8 red; 8 blue, 8 red, 1 green
|
||||
Game 21: 1 blue, 14 red; 1 green, 2 red; 9 red, 1 blue, 1 green
|
||||
Game 22: 7 green, 9 red, 4 blue; 9 red, 7 green, 9 blue; 8 green, 14 red; 5 blue; 10 red, 1 blue, 1 green; 8 green
|
||||
Game 23: 2 red, 12 green, 5 blue; 3 red, 5 blue, 3 green; 1 red, 9 green, 1 blue; 8 green, 6 blue; 13 green
|
||||
Game 24: 8 red, 7 green, 1 blue; 1 red, 6 green, 7 blue; 1 green, 3 red
|
||||
Game 25: 4 green, 2 red; 1 red, 2 green, 8 blue; 1 green; 8 blue
|
||||
Game 26: 1 green, 4 blue, 17 red; 15 red, 3 green, 3 blue; 2 blue, 2 red; 18 red, 2 green, 11 blue; 6 red, 7 blue; 10 blue, 1 green, 4 red
|
||||
Game 27: 2 red, 5 blue, 1 green; 14 green, 2 red, 6 blue; 1 red, 4 blue, 14 green
|
||||
Game 28: 3 red, 5 green, 2 blue; 2 red, 3 green, 4 blue; 1 red, 9 green, 3 blue; 13 green, 4 red, 4 blue
|
||||
Game 29: 18 red, 11 green; 4 blue, 18 red, 9 green; 16 red, 2 green, 4 blue; 2 red, 3 blue, 12 green; 1 green, 18 red; 2 blue, 15 green, 1 red
|
||||
Game 30: 10 red, 3 blue, 1 green; 6 red, 1 blue, 3 green; 2 green, 2 blue, 10 red; 6 green; 3 blue, 15 red
|
||||
Game 31: 1 blue, 7 green, 2 red; 12 red, 8 green, 4 blue; 2 green, 2 blue, 5 red; 2 blue, 3 green, 12 red; 7 red, 5 green, 4 blue; 7 red, 1 blue
|
||||
Game 32: 4 blue, 5 red, 11 green; 20 red, 8 green, 1 blue; 10 red, 7 green, 1 blue; 1 blue, 7 red, 2 green; 1 red, 19 green, 3 blue
|
||||
Game 33: 9 red; 9 red, 6 green, 7 blue; 5 red, 7 blue, 2 green
|
||||
Game 34: 5 green, 5 red, 3 blue; 8 green, 6 blue, 16 red; 12 blue, 8 red, 8 green; 1 blue, 10 red, 3 green; 1 green, 13 blue, 18 red; 4 blue, 5 green, 8 red
|
||||
Game 35: 15 green, 4 red, 8 blue; 7 red, 1 green, 14 blue; 12 green, 16 blue, 2 red
|
||||
Game 36: 3 blue, 3 green, 2 red; 7 red, 8 blue; 11 blue, 9 red; 4 red, 13 blue, 1 green
|
||||
Game 37: 4 red, 11 blue, 8 green; 6 green, 4 blue, 14 red; 5 blue, 7 green, 13 red; 6 red, 2 green, 5 blue; 4 red, 3 blue, 1 green; 6 red, 4 green, 6 blue
|
||||
Game 38: 10 green, 5 blue, 1 red; 3 red, 6 blue, 3 green; 9 green, 9 blue, 3 red; 9 blue, 1 red, 6 green
|
||||
Game 39: 3 blue, 16 red; 10 red, 4 green, 2 blue; 2 blue, 13 red, 1 green; 2 blue, 11 red, 2 green; 3 green, 13 red
|
||||
Game 40: 2 blue, 3 red, 2 green; 2 green, 2 blue, 6 red; 1 green, 9 red
|
||||
Game 41: 1 blue, 12 red; 8 blue, 1 red, 5 green; 1 green, 7 blue, 13 red; 8 red, 7 blue, 7 green; 4 green, 17 red, 9 blue; 2 green, 8 blue
|
||||
Game 42: 2 green, 6 red, 1 blue; 3 red, 2 green; 9 red, 1 green; 2 red, 2 green
|
||||
Game 43: 10 blue, 9 red; 14 blue, 4 green; 5 red, 3 green, 9 blue; 5 blue, 8 green, 1 red
|
||||
Game 44: 3 blue, 10 green, 1 red; 1 blue, 13 red, 3 green; 1 blue, 5 green, 16 red
|
||||
Game 45: 1 red, 1 green, 3 blue; 2 green, 1 red, 5 blue; 1 red, 2 blue, 1 green; 1 blue; 1 green, 5 blue; 1 blue
|
||||
Game 46: 8 green, 8 blue, 4 red; 10 green, 4 red, 7 blue; 2 red, 3 green, 14 blue
|
||||
Game 47: 3 green, 3 red; 5 green, 2 blue, 6 red; 3 blue, 5 red, 15 green; 2 green, 2 blue, 2 red
|
||||
Game 48: 11 blue, 12 green, 3 red; 8 blue, 3 red, 3 green; 1 green, 6 blue, 2 red
|
||||
Game 49: 3 blue, 17 green, 1 red; 4 red, 16 blue, 17 green; 1 green, 3 red, 5 blue; 14 blue, 1 red, 12 green
|
||||
Game 50: 2 blue, 5 red, 6 green; 8 blue, 11 green, 5 red; 2 green, 2 red, 6 blue
|
||||
Game 51: 1 green, 2 red; 4 green; 1 blue, 10 green
|
||||
Game 52: 8 blue, 9 red, 4 green; 2 green, 8 blue, 2 red; 1 red, 2 green, 1 blue; 2 blue, 8 green, 8 red; 4 red, 1 green, 9 blue; 11 blue, 4 green, 8 red
|
||||
Game 53: 1 green, 2 red; 3 blue, 1 green, 9 red; 5 blue, 11 red; 4 blue, 6 red, 1 green; 5 blue, 10 red; 5 blue, 5 red, 1 green
|
||||
Game 54: 1 blue, 8 green; 9 green, 1 red, 11 blue; 16 green, 8 blue; 5 green
|
||||
Game 55: 7 blue, 2 red, 1 green; 16 green, 19 blue, 5 red; 9 green, 3 blue, 7 red; 8 blue, 2 green, 4 red; 8 green, 15 blue, 5 red
|
||||
Game 56: 9 blue, 1 red, 4 green; 12 green, 12 blue; 1 green, 1 red, 5 blue
|
||||
Game 57: 1 green, 10 blue; 1 red, 9 blue; 10 blue, 1 red, 3 green
|
||||
Game 58: 6 red, 15 blue, 3 green; 13 blue, 5 red; 10 blue, 2 red; 5 red, 1 green, 14 blue
|
||||
Game 59: 7 red, 1 blue, 9 green; 4 green, 12 red, 2 blue; 6 green, 20 red, 1 blue; 4 blue, 9 red, 2 green; 8 red, 4 blue, 2 green
|
||||
Game 60: 11 red, 8 blue, 1 green; 18 green, 11 blue; 16 red, 10 blue, 7 green; 6 blue, 8 red; 7 red, 15 green, 4 blue
|
||||
Game 61: 1 blue, 1 green, 8 red; 3 red, 7 blue; 4 blue, 10 red; 1 green, 5 red, 8 blue; 10 red, 7 blue
|
||||
Game 62: 12 blue, 1 red, 1 green; 2 green, 1 red, 7 blue; 3 green, 18 blue; 11 blue, 4 green
|
||||
Game 63: 4 green, 4 red, 8 blue; 7 red, 5 blue, 5 green; 2 green, 20 blue, 4 red; 1 green, 4 blue, 3 red
|
||||
Game 64: 2 green, 2 red; 3 green, 2 blue; 12 green, 2 red, 4 blue; 5 red, 9 green, 8 blue; 7 blue, 6 green; 3 green, 5 red
|
||||
Game 65: 8 red, 2 green, 13 blue; 11 blue; 7 blue, 2 green; 12 blue, 1 green, 9 red
|
||||
Game 66: 1 blue, 3 red, 19 green; 3 red, 17 blue, 15 green; 9 green, 9 blue
|
||||
Game 67: 2 green, 7 blue, 1 red; 3 green, 1 red, 7 blue; 1 red, 6 green; 7 blue, 2 red, 10 green; 2 red, 5 green, 4 blue
|
||||
Game 68: 14 red, 10 green, 8 blue; 11 red, 1 blue, 6 green; 7 red, 7 green; 12 blue, 10 green, 3 red; 6 red, 12 blue, 10 green; 8 green, 14 red, 3 blue
|
||||
Game 69: 4 green, 8 red; 2 red, 15 green; 5 red, 1 blue, 12 green; 13 red, 6 green; 10 green, 13 red, 1 blue
|
||||
Game 70: 3 red, 10 blue, 3 green; 8 red, 11 blue, 11 green; 5 red, 13 green
|
||||
Game 71: 18 green, 3 red, 1 blue; 3 blue, 14 green, 2 red; 6 blue, 20 green, 4 red
|
||||
Game 72: 2 blue, 1 red; 2 blue, 3 green, 1 red; 4 blue, 2 red, 4 green
|
||||
Game 73: 11 red, 11 green; 5 green, 1 blue; 8 red, 7 green, 4 blue; 5 blue, 7 red, 12 green
|
||||
Game 74: 12 red, 12 green, 5 blue; 10 red, 7 blue, 15 green; 6 green, 19 red, 19 blue; 3 red, 7 blue, 16 green; 11 red, 14 green, 16 blue
|
||||
Game 75: 5 red, 17 green, 8 blue; 10 red, 8 blue, 19 green; 9 blue, 6 red, 18 green; 3 blue, 13 red, 12 green
|
||||
Game 76: 5 green, 2 red, 8 blue; 3 blue, 14 red, 2 green; 14 red, 1 blue; 3 green, 8 blue, 15 red; 11 red, 1 green; 11 red, 9 blue, 3 green
|
||||
Game 77: 3 blue, 2 red; 1 blue, 8 green, 11 red; 14 green, 14 red; 3 red, 5 green, 5 blue; 2 green, 16 blue, 3 red; 13 red, 7 green, 5 blue
|
||||
Game 78: 3 blue, 1 green, 1 red; 5 blue, 1 green, 1 red; 9 blue, 7 red, 1 green; 5 blue, 1 green, 5 red; 10 blue, 3 green, 7 red
|
||||
Game 79: 19 green, 17 blue, 4 red; 7 green, 7 red, 16 blue; 4 red, 10 green; 13 blue, 17 green, 2 red
|
||||
Game 80: 9 blue, 3 green; 15 blue, 1 red; 3 blue, 12 green, 2 red; 1 red, 14 green, 13 blue; 1 red, 10 blue, 16 green; 8 blue, 6 green, 2 red
|
||||
Game 81: 1 green, 3 red, 19 blue; 2 red, 1 green, 9 blue; 1 green, 2 red, 8 blue; 1 red, 1 green, 11 blue; 1 green, 3 red, 11 blue
|
||||
Game 82: 8 red, 1 blue, 4 green; 9 green, 3 blue, 4 red; 3 green, 3 blue, 18 red
|
||||
Game 83: 3 red, 13 blue, 16 green; 16 green, 2 blue; 14 green, 12 blue; 8 green, 14 blue, 4 red; 12 green, 4 blue; 20 green, 1 red
|
||||
Game 84: 4 green, 4 blue, 5 red; 6 red, 6 blue, 8 green; 5 blue, 12 green, 3 red; 5 red, 13 green; 6 blue, 1 green, 5 red
|
||||
Game 85: 10 green; 7 green, 1 blue; 5 red, 5 blue, 1 green; 2 green, 2 red, 3 blue; 3 red, 10 green, 3 blue; 1 blue, 1 red
|
||||
Game 86: 3 green, 1 red, 3 blue; 2 red, 2 green; 9 green, 2 blue, 3 red; 3 red, 3 blue, 4 green
|
||||
Game 87: 6 red, 4 green; 1 red, 3 green, 5 blue; 1 green, 7 blue, 4 red
|
||||
Game 88: 2 green, 4 red, 3 blue; 5 green, 1 blue; 3 red, 5 green, 2 blue; 1 green, 6 red, 1 blue; 7 red, 2 blue; 17 red, 13 green
|
||||
Game 89: 4 green, 2 blue, 6 red; 15 red, 7 green, 10 blue; 7 red, 9 blue, 4 green
|
||||
Game 90: 9 red, 17 blue; 1 green, 9 blue; 5 red, 8 blue; 3 blue, 9 red, 1 green; 17 blue, 1 red
|
||||
Game 91: 7 green, 3 red, 5 blue; 4 blue, 3 red, 9 green; 9 red, 7 blue, 7 green; 5 red, 6 blue, 3 green; 10 red, 2 green, 6 blue
|
||||
Game 92: 13 blue, 8 red; 7 green, 1 red, 8 blue; 5 blue, 4 red, 2 green; 9 red, 10 blue
|
||||
Game 93: 6 green; 1 blue, 16 green, 6 red; 5 green, 1 blue, 5 red; 5 red, 6 green; 16 green, 2 red, 1 blue; 11 green, 2 red
|
||||
Game 94: 9 blue, 4 green; 12 green, 17 blue; 4 green, 5 blue, 6 red; 2 red, 2 blue, 12 green
|
||||
Game 95: 5 red, 4 blue, 5 green; 2 blue, 4 green, 4 red; 4 blue, 2 red, 7 green; 1 green, 7 blue, 8 red
|
||||
Game 96: 7 blue, 6 green, 2 red; 3 green, 1 blue; 7 blue, 3 red, 5 green; 1 green, 5 blue; 6 blue, 2 red; 2 green, 1 red
|
||||
Game 97: 10 red, 1 green, 1 blue; 4 green, 11 red, 2 blue; 4 red, 1 blue, 4 green
|
||||
Game 98: 3 green, 4 blue, 7 red; 7 red, 8 green; 7 green, 16 red, 1 blue; 8 green, 2 blue, 4 red; 5 green, 3 blue, 18 red
|
||||
Game 99: 6 green, 12 red, 1 blue; 5 blue, 1 red, 7 green; 5 green, 7 red, 10 blue; 8 blue, 1 red, 7 green; 17 red, 4 blue, 9 green
|
||||
Game 100: 6 blue, 10 green; 3 green, 4 blue, 1 red; 7 blue, 1 red, 12 green
|
||||
1
day2/rust/.gitignore
vendored
Normal file
1
day2/rust/.gitignore
vendored
Normal file
@@ -0,0 +1 @@
|
||||
target
|
||||
7
day2/rust/Cargo.lock
generated
Normal file
7
day2/rust/Cargo.lock
generated
Normal file
@@ -0,0 +1,7 @@
|
||||
# This file is automatically @generated by Cargo.
|
||||
# It is not intended for manual editing.
|
||||
version = 3
|
||||
|
||||
[[package]]
|
||||
name = "rust"
|
||||
version = "0.1.0"
|
||||
8
day2/rust/Cargo.toml
Normal file
8
day2/rust/Cargo.toml
Normal file
@@ -0,0 +1,8 @@
|
||||
[package]
|
||||
name = "rust"
|
||||
version = "0.1.0"
|
||||
edition = "2021"
|
||||
|
||||
# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html
|
||||
|
||||
[dependencies]
|
||||
135
day2/rust/src/main.rs
Normal file
135
day2/rust/src/main.rs
Normal file
@@ -0,0 +1,135 @@
|
||||
struct Game {
|
||||
id: usize,
|
||||
grabs: Vec<Grab>,
|
||||
}
|
||||
|
||||
struct Grab {
|
||||
cubes: Vec<Cube>,
|
||||
}
|
||||
|
||||
struct Cube {
|
||||
count: usize,
|
||||
color: Color,
|
||||
}
|
||||
|
||||
#[derive(Debug)]
|
||||
enum Color {
|
||||
RED,
|
||||
GREEN,
|
||||
BLUE,
|
||||
UNKNOWN,
|
||||
}
|
||||
|
||||
fn main() {
|
||||
let stdin = std::io::stdin();
|
||||
|
||||
let mut games: Vec<Game> = Vec::new();
|
||||
|
||||
// Read and parse input
|
||||
for line in stdin.lines() {
|
||||
let line = line.unwrap();
|
||||
|
||||
let (game_id_str, grab_strs) = line.split_once(":").unwrap();
|
||||
|
||||
let game_id = game_id_str.split_once(" ").unwrap().1.parse().unwrap();
|
||||
|
||||
let mut grabs = Vec::new();
|
||||
|
||||
for grab_str in grab_strs.split(";") {
|
||||
let mut cubes = Vec::new();
|
||||
|
||||
for cube in grab_str.split(",").map(|str| str.trim()) {
|
||||
let (count, color) = cube.split_once(' ').unwrap();
|
||||
|
||||
let count = count.parse().unwrap();
|
||||
let color = match color {
|
||||
"red" => Color::RED,
|
||||
"green" => Color::GREEN,
|
||||
"blue" => Color::BLUE,
|
||||
_ => Color::UNKNOWN,
|
||||
};
|
||||
|
||||
cubes.push(Cube { count, color })
|
||||
}
|
||||
|
||||
grabs.push(Grab { cubes });
|
||||
}
|
||||
|
||||
games.push(Game { id: game_id, grabs })
|
||||
}
|
||||
|
||||
// Part 1
|
||||
let red_cubes = 12;
|
||||
let green_cubes = 13;
|
||||
let blue_cubes = 14;
|
||||
let mut part1 = 0;
|
||||
|
||||
for game in &games {
|
||||
let mut possible = true;
|
||||
for grab in &game.grabs {
|
||||
for cube in &grab.cubes {
|
||||
match cube.color {
|
||||
Color::RED => {
|
||||
if cube.count > red_cubes {
|
||||
possible = false;
|
||||
break;
|
||||
}
|
||||
}
|
||||
Color::GREEN => {
|
||||
if cube.count > green_cubes {
|
||||
possible = false;
|
||||
break;
|
||||
}
|
||||
}
|
||||
Color::BLUE => {
|
||||
if cube.count > blue_cubes {
|
||||
possible = false;
|
||||
break;
|
||||
}
|
||||
}
|
||||
Color::UNKNOWN => (),
|
||||
}
|
||||
}
|
||||
|
||||
if !possible {
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
if possible {
|
||||
part1 += game.id;
|
||||
}
|
||||
}
|
||||
|
||||
println!("{}", part1);
|
||||
|
||||
// Part 2
|
||||
let mut part2 = 0;
|
||||
|
||||
for game in &games {
|
||||
let mut min_reds = 0;
|
||||
let mut min_greens = 0;
|
||||
let mut min_blues = 0;
|
||||
|
||||
for grab in &game.grabs {
|
||||
for cube in &grab.cubes {
|
||||
match cube.color {
|
||||
Color::RED => {
|
||||
min_reds = std::cmp::max(min_reds, cube.count);
|
||||
}
|
||||
Color::GREEN => {
|
||||
min_greens = std::cmp::max(min_greens, cube.count);
|
||||
}
|
||||
Color::BLUE => {
|
||||
min_blues = std::cmp::max(min_blues, cube.count);
|
||||
}
|
||||
Color::UNKNOWN => (),
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
part2 += min_reds * min_greens * min_blues;
|
||||
}
|
||||
|
||||
println!("{}", part2);
|
||||
}
|
||||
5
day2/sample.txt
Normal file
5
day2/sample.txt
Normal file
@@ -0,0 +1,5 @@
|
||||
Game 1: 3 blue, 4 red; 1 red, 2 green, 6 blue; 2 green
|
||||
Game 2: 1 blue, 2 green; 3 green, 4 blue, 1 red; 1 green, 1 blue
|
||||
Game 3: 8 green, 6 blue, 20 red; 5 blue, 4 red, 13 green; 5 green, 1 red
|
||||
Game 4: 1 green, 3 red, 6 blue; 3 green, 6 red; 3 green, 15 blue, 14 red
|
||||
Game 5: 6 red, 1 blue, 3 green; 2 blue, 1 red, 2 green
|
||||
BIN
day20/c/day20
Executable file
BIN
day20/c/day20
Executable file
Binary file not shown.
204
day20/c/day20.c
Normal file
204
day20/c/day20.c
Normal file
@@ -0,0 +1,204 @@
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
#include <string.h>
|
||||
|
||||
#define LINE_MAX_LENGTH 256
|
||||
#define MAX_CONNECTED 16
|
||||
#define MAX_MODULES 128
|
||||
#define MAX_QUEUE 1024
|
||||
|
||||
typedef enum module_type {
|
||||
FLIPFLOP,
|
||||
CONJUNCTION,
|
||||
BROADCAST,
|
||||
} module_type_t;
|
||||
|
||||
typedef struct module {
|
||||
module_type_t type;
|
||||
char name[16];
|
||||
int name_length;
|
||||
int state;
|
||||
struct module *inputs[MAX_CONNECTED];
|
||||
int input_memory[MAX_CONNECTED];
|
||||
int input_num;
|
||||
struct module *outputs[MAX_CONNECTED];
|
||||
int output_num;
|
||||
char output_names[MAX_CONNECTED][16];
|
||||
int output_name_lengths[MAX_CONNECTED];
|
||||
} module_t;
|
||||
|
||||
typedef struct signal {
|
||||
int value;
|
||||
module_t *module;
|
||||
module_t *source;
|
||||
} signal_t;
|
||||
|
||||
int main() {
|
||||
char *p, *buf, c, *q;
|
||||
|
||||
buf = (char *)malloc(LINE_MAX_LENGTH);
|
||||
memset(buf, 0, LINE_MAX_LENGTH);
|
||||
p = buf;
|
||||
|
||||
module_t *modules = (module_t*)malloc(MAX_MODULES * sizeof(module_t));
|
||||
memset(modules, 0, MAX_MODULES * sizeof(module_t));
|
||||
int modules_num = 0;
|
||||
|
||||
while ((c = getchar()) != EOF) {
|
||||
*p++ = c;
|
||||
if (c == '\n') {
|
||||
p = buf;
|
||||
|
||||
if (*p == '%' || *p == '&' || *p == '#') {
|
||||
switch (*p) {
|
||||
case '%':
|
||||
modules[modules_num].type = FLIPFLOP;
|
||||
break;
|
||||
case '&':
|
||||
modules[modules_num].type = CONJUNCTION;
|
||||
break;
|
||||
}
|
||||
p++;
|
||||
} else {
|
||||
modules[modules_num].type = BROADCAST;
|
||||
}
|
||||
q = p;
|
||||
while(*p != ' ') p++;
|
||||
strncpy(modules[modules_num].name, q, p - q);
|
||||
modules[modules_num].name_length = p - q;
|
||||
p++;
|
||||
while(*p != ' ') p++;
|
||||
p++;
|
||||
// Read outputs
|
||||
while(*p != '\0') {
|
||||
q = p;
|
||||
while (*p != '\n' && *p != ',') p++;
|
||||
strncpy(modules[modules_num].output_names[modules[modules_num].output_num], q, p - q);
|
||||
modules[modules_num].output_name_lengths[modules[modules_num].output_num] = p - q;
|
||||
modules[modules_num].output_num++;
|
||||
p+=2;
|
||||
}
|
||||
|
||||
modules_num++;
|
||||
memset(buf, 0, LINE_MAX_LENGTH);
|
||||
p = buf;
|
||||
}
|
||||
}
|
||||
|
||||
// Link up modules
|
||||
for (int i = 0; i < modules_num; i++) {
|
||||
// Link outputs
|
||||
int found = 0;
|
||||
for (int j = 0; j < modules[i].output_num; j++) {
|
||||
for (int k = 0; k < modules_num; k++) {
|
||||
if (!strcmp(modules[k].name, modules[i].output_names[j])) {
|
||||
modules[i].outputs[j] = &modules[k];
|
||||
found++;
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
// Link inputs
|
||||
for (int j = 0; j < modules_num; j++) {
|
||||
for (int k = 0; k < modules[j].output_num; k++) {
|
||||
if (!strcmp(modules[i].name, modules[j].output_names[k])) {
|
||||
modules[i].inputs[modules[i].input_num] = &modules[j];
|
||||
modules[i].input_num++;
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// Find start
|
||||
module_t *broadcast;
|
||||
for (int i = 0; i < modules_num; i++) {
|
||||
if (modules[i].type == BROADCAST) {
|
||||
broadcast = &modules[i];
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
signal_t signal_queue[MAX_QUEUE];
|
||||
unsigned long low_pulses = 0, high_pulses = 0;
|
||||
|
||||
int turned_on = 0;
|
||||
#ifdef PART2
|
||||
for(unsigned long l = 0; !turned_on; l++) {
|
||||
#else
|
||||
for (unsigned long l = 0; l < 1000; l++) {
|
||||
#endif
|
||||
memset(signal_queue, 0, MAX_QUEUE * sizeof(signal_t));
|
||||
int signal_queue_length = 1;
|
||||
signal_queue[0].value = 0;
|
||||
signal_queue[0].module = broadcast;
|
||||
signal_queue[0].source = NULL;
|
||||
while (signal_queue_length > 0) {
|
||||
// Pop first
|
||||
signal_t signal = signal_queue[0];
|
||||
for (int i = 0; i < signal_queue_length - 1; i++) {
|
||||
memcpy(&signal_queue[i], &signal_queue[i+1], sizeof(signal_t));
|
||||
}
|
||||
signal_queue_length--;
|
||||
int output;
|
||||
if (signal.value) {
|
||||
high_pulses++;
|
||||
} else {
|
||||
low_pulses++;
|
||||
}
|
||||
|
||||
if (signal.module == NULL) {
|
||||
if (signal.value == 0) {
|
||||
printf("Machine turn on: %lu\n", l+1);
|
||||
turned_on = 1;
|
||||
break;
|
||||
}
|
||||
continue;
|
||||
}
|
||||
|
||||
switch (signal.module->type) {
|
||||
case FLIPFLOP:
|
||||
if (signal.value == 0) {
|
||||
signal.module->state = !signal.module->state;
|
||||
output = signal.module->state;
|
||||
} else {
|
||||
output = -1;
|
||||
}
|
||||
break;
|
||||
case BROADCAST:
|
||||
output = signal.value;
|
||||
break;
|
||||
case CONJUNCTION:
|
||||
// Update input memory
|
||||
for (int i = 0; i < signal.module->input_num; i++) {
|
||||
if (signal.module->inputs[i] == signal.source) {
|
||||
signal.module->input_memory[i] = signal.value;
|
||||
}
|
||||
}
|
||||
int all_high = 1;
|
||||
for (int i = 0; i < signal.module->input_num; i++) {
|
||||
if (signal.module->input_memory[i] == 0) {
|
||||
all_high = 0;
|
||||
break;
|
||||
}
|
||||
}
|
||||
output = !all_high;
|
||||
break;
|
||||
}
|
||||
|
||||
if (output != -1) {
|
||||
for (int i = 0; i < signal.module->output_num; i++) {
|
||||
signal_queue[signal_queue_length].value = output;
|
||||
signal_queue[signal_queue_length].module = signal.module->outputs[i];
|
||||
signal_queue[signal_queue_length].source = signal.module;
|
||||
signal_queue_length++;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
printf("%lu\n", high_pulses * low_pulses);
|
||||
|
||||
free(buf);
|
||||
free(modules);
|
||||
}
|
||||
58
day20/input.txt
Normal file
58
day20/input.txt
Normal file
@@ -0,0 +1,58 @@
|
||||
%db -> cq
|
||||
%rj -> gp, nd
|
||||
%ff -> bk
|
||||
%rc -> gp
|
||||
%bk -> tv
|
||||
%xz -> tf, bn
|
||||
%gs -> bn
|
||||
%ps -> rs, gp
|
||||
%jr -> gp, cg
|
||||
&pm -> vf
|
||||
%pn -> pp, rt
|
||||
%nv -> jr
|
||||
%rs -> nv
|
||||
%kz -> mj
|
||||
%nd -> rc, gp
|
||||
%nm -> rt, db
|
||||
%dg -> rt, xl
|
||||
%vg -> gn
|
||||
%hc -> vr
|
||||
%ft -> lf, bn
|
||||
%mj -> hc, cz
|
||||
%vb -> ft
|
||||
%qd -> cz, sz
|
||||
%pp -> rt
|
||||
%cq -> rt, vg
|
||||
%sr -> vb
|
||||
%lf -> vx, bn
|
||||
%lh -> pn, rt
|
||||
%ls -> sl, cz
|
||||
%tv -> gp, rj
|
||||
%tf -> sr, bn
|
||||
&mk -> vf
|
||||
%bs -> rt, lh
|
||||
%vx -> bn, gs
|
||||
&bn -> fs, bv, vb, mk, sr, bz, cf
|
||||
%rr -> ls
|
||||
%bv -> xz
|
||||
%hp -> bs, rt
|
||||
&pk -> vf
|
||||
%cg -> rq
|
||||
%gn -> rt, dg
|
||||
&cz -> hc, kz, rr, hf, sh
|
||||
%sl -> cz, kz
|
||||
broadcaster -> sh, nm, ps, fs
|
||||
%cf -> bv
|
||||
&vf -> rx
|
||||
&rt -> pk, xl, nm, vg, db
|
||||
%xl -> hp
|
||||
%sh -> rr, cz
|
||||
%bz -> cf
|
||||
%fz -> dn, cz
|
||||
&gp -> rs, nv, pm, cg, ff, bk, ps
|
||||
%fs -> bz, bn
|
||||
&hf -> vf
|
||||
%vr -> cz, qd
|
||||
%rq -> gp, ff
|
||||
%sz -> cz, fz
|
||||
%dn -> cz
|
||||
5
day20/sample.txt
Normal file
5
day20/sample.txt
Normal file
@@ -0,0 +1,5 @@
|
||||
broadcaster -> a, b, c
|
||||
%a -> b
|
||||
%b -> c
|
||||
%c -> inv
|
||||
&inv -> a
|
||||
5
day20/sample2.txt
Normal file
5
day20/sample2.txt
Normal file
@@ -0,0 +1,5 @@
|
||||
broadcaster -> a
|
||||
%a -> inv, con
|
||||
&inv -> b
|
||||
%b -> con
|
||||
&con -> output
|
||||
BIN
day21/c/day21
Executable file
BIN
day21/c/day21
Executable file
Binary file not shown.
102
day21/c/day21.c
Normal file
102
day21/c/day21.c
Normal file
@@ -0,0 +1,102 @@
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
#include <string.h>
|
||||
|
||||
#define LINE_MAX_LENGTH 256
|
||||
|
||||
typedef enum tile_type {
|
||||
GARDEN_PLOT,
|
||||
ROCK,
|
||||
WALKED,
|
||||
} tile_type_t;
|
||||
|
||||
int main(int argc, char *argv[]) {
|
||||
if (argc != 2) {
|
||||
fprintf(stderr, "Please specify the step number\n");
|
||||
return 1;
|
||||
}
|
||||
int step_number = 0;
|
||||
sscanf(argv[1], "%i", &step_number);
|
||||
char *p, *buf, c;
|
||||
|
||||
tile_type_t map[LINE_MAX_LENGTH][LINE_MAX_LENGTH];
|
||||
int x = 0, y = 0;
|
||||
|
||||
buf = (char *)malloc(LINE_MAX_LENGTH);
|
||||
memset(buf, 0, LINE_MAX_LENGTH);
|
||||
p = buf;
|
||||
|
||||
int start[2];
|
||||
|
||||
while ((c = getchar()) != EOF) {
|
||||
*p++ = c;
|
||||
if (c == '\n') {
|
||||
p = buf;
|
||||
x = 0;
|
||||
while (*p != '\n') {
|
||||
switch (*p) {
|
||||
case '.':
|
||||
map[x][y] = GARDEN_PLOT;
|
||||
break;
|
||||
case '#':
|
||||
map[x][y] = ROCK;
|
||||
break;
|
||||
case 'S':
|
||||
map[x][y] = GARDEN_PLOT;
|
||||
start[0] = x;
|
||||
start[1] = y;
|
||||
break;
|
||||
}
|
||||
x++;
|
||||
p++;
|
||||
}
|
||||
y++;
|
||||
memset(buf, 0, LINE_MAX_LENGTH);
|
||||
p = buf;
|
||||
}
|
||||
}
|
||||
|
||||
tile_type_t walked_curr[LINE_MAX_LENGTH][LINE_MAX_LENGTH], walked_next[LINE_MAX_LENGTH][LINE_MAX_LENGTH];
|
||||
memcpy(walked_curr, map, sizeof(map));
|
||||
walked_curr[start[0]][start[1]] = WALKED;
|
||||
|
||||
for (int i = 0; i < step_number; i++) {
|
||||
memcpy(walked_next, map, sizeof(map));
|
||||
for (int j = 0; j < y; j++) {
|
||||
for (int k = 0; k < x; k++) {
|
||||
if (walked_curr[k][j] == WALKED) {
|
||||
// UP
|
||||
if (j > 0 && walked_next[k][j-1] == GARDEN_PLOT) {
|
||||
walked_next[k][j-1] = WALKED;
|
||||
}
|
||||
// LEFT
|
||||
if (k > 0 && walked_next[k-1][j] == GARDEN_PLOT) {
|
||||
walked_next[k-1][j] = WALKED;
|
||||
}
|
||||
// DOWN
|
||||
if (j < y - 1 && walked_next[k][j+1] == GARDEN_PLOT) {
|
||||
walked_next[k][j+1] = WALKED;
|
||||
}
|
||||
// RIGHT
|
||||
if (k < x - 1 && walked_next[k+1][j] == GARDEN_PLOT) {
|
||||
walked_next[k+1][j] = WALKED;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
memcpy(walked_curr, walked_next, sizeof(map));
|
||||
}
|
||||
|
||||
int part1 = 0;
|
||||
|
||||
for (int i = 0; i < y; i++) {
|
||||
for (int j = 0; j < x; j++) {
|
||||
if (walked_curr[j][i] == WALKED) {
|
||||
part1++;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
printf("%i\n", part1);
|
||||
free(buf);
|
||||
}
|
||||
131
day21/input.txt
Normal file
131
day21/input.txt
Normal file
@@ -0,0 +1,131 @@
|
||||
...................................................................................................................................
|
||||
...##......#....#...#.....#.#....#...#...#...#......#........................##......#..#..#.#........#....................##......
|
||||
...#.......#..........#..#....#................#...##.....##...................#..........###......#.....#.........#....#.#........
|
||||
........#..##.............#..#...##...#..#...##...............................#.........................#..........................
|
||||
..............#............#..#..........#.#.#....#...#......................#..#......#.##...#............................#.......
|
||||
..##...............#...#...#......#.......................................#..............##...............#.....#...........#...#..
|
||||
.##............#.................#...#..#......#...................................#.......#.#..#......##................##........
|
||||
......###...#...#........#..............#....#.......##.......................##.......#..#.......#.........#...................#..
|
||||
.................#...........................................#......................#.....#.....##...........#...............#.....
|
||||
..#...#....#.......##...........#..#.............#............................##........#.......#...#...#...#....#....##...........
|
||||
..............#..#.....#.....#.........#..#..#..#..#.......#.#..#....##........#.....#.........#..............#........#..#...#....
|
||||
...##...............#...#.#....#............##..#.......................................#.......#...........#..#...........##....#.
|
||||
.......................................#......#...........#..........#.............#..........##.............#....#..##....#.......
|
||||
..................................#.............#........#...#.##.....................#....................#.##....#.............#.
|
||||
.#......##...#......#..#...#...........#...#.............#.............#..#.........#..#.#........#.#...........#..................
|
||||
............#............#..........#........#..........#.....#.#...#.......#........#.#...........#....#.............#.........#..
|
||||
.....#.......##............#...#.#.#...#...#..............##..#....#......#......................#...#...#..........#......#.#.....
|
||||
........#....#....#......#..........#........................#.....#....................................#.....#....#..##.##....#...
|
||||
............#.................#.##.........#.........#.....#........#.........#........#....###...........#.............#..........
|
||||
....##....#..#............#...#.#..#.........................#.#....##.....................#........#.........#....#....#........#.
|
||||
...#...#...........#..#..................#.......#.#..#............................................##................#.............
|
||||
...........#......#....#........#.#..........................#.#......#......##.............#..#...#...#.#..................#..#...
|
||||
.............................#........#............#........#........#.#.......#...............##....#........#...#..#..#..........
|
||||
..................................#...........................#.#..#.........................#...#.#......#..............##.....##.
|
||||
........................#..........................#..................#...#............................#.......#...........#...##..
|
||||
.......#.#.....#....#.....#................................##...#.........##..#.....................#..............................
|
||||
......#........##..........#.................#..##......#..#.......#..........#....................................................
|
||||
....#..........#......................................................##.#..#.#.##..................#......#............##...#.....
|
||||
.............#..........#.#..............................................#.#........#....#...........#.......................#.....
|
||||
..#.............#....#........#.#..............#.......#......#.#..#......#.#...........................................##.........
|
||||
..#.....#.....#....#...#....#..........#......#..............................#...........#............#..#.....##..........#.......
|
||||
......#.#.#...#........................#..........#.#......#............#......................................#...................
|
||||
.#...........#...#....................#..#..#....#.#........................................................................#.#....
|
||||
........#.#...........................#...#......#.#.#..#......##..#.#..#..#...#.#.#..................#.......##.#....#........#...
|
||||
......#......#......#.....#..............#.#.........##.................#....................#............#....##........#.........
|
||||
........#.............#..#............#......#........#....#............#.....#...........#..#...............###........#.....#....
|
||||
.....#.........##....#..................#..#...........#.#....##...........................#.............#..##..#.........#........
|
||||
............#....#..#.................#.............#..#.....##.....#.....#.........#........#............#........#.........##....
|
||||
.#.......#.#..........#...............#..............#.....#........#...#......#......##...........................#..#.#......##..
|
||||
.##.#.........#.............................#............................#.#..#...#.............#...#.........#...#......#.........
|
||||
................................#........#..#..........##......#..................................#................#.#...#...#.....
|
||||
.........#........#...........#........................#.#.##.........#.....#..#................................#.............##...
|
||||
.........#.#....#..#.........#.#....#.......#.............#........#............#...#..........#...##..........#........#........#.
|
||||
..............................###.....#......#......#...#....#...........#...#...............#.....##.#.....................#..#...
|
||||
..........................#......#...#..............................##.#.......#........##..........#................#...##.....#..
|
||||
...........#............................#..................#...#..#.....................#...#.................................#....
|
||||
..#.#...............................................#..........#..........#..............#............##...........................
|
||||
........#...#..................#.........#............#...............#.#..#.........#....#...............#.............##.........
|
||||
............................##....................##......#..#....#.......#....#........................#...#.........#.....#....#.
|
||||
.....#.#...............#....#..#....#...........#........#.#..................#.....##....#.......#......#......................#..
|
||||
...........#.........#.#.......#......#.#.#.......#.#...#...................#...#......#..............#...#....#.................#.
|
||||
...#..#...........#.............#..........##..............................###...........#.#.....##.......#.............#..........
|
||||
...##.....................##...#..#.....#.........#.#....#.#.....................#..............#.#...#...#......#..............#..
|
||||
......##................#.................#.#........#.#..#................#............#......#.#..............#...............#..
|
||||
.......#...........#.................................##..................#...#........#.......#..##...##...........#.........#.....
|
||||
..............#........#.............#..........#...............#..#.......#.........#..#...............#......#..#.........##.#...
|
||||
.....#..........................................#...............#....#......#..#................................#...............#..
|
||||
...............#.......#..#.........#......#..................#........#................#.#...........#....##......#............#..
|
||||
...........................#.....##.........#...#...........#........#..#................#.#.#............#..#...#.....#...........
|
||||
................#.....#..#.#......#.............#.....#...........##....#...#.#.....#.........#....................................
|
||||
....................................#...........#..............#................#............#..#...............#.##..#.##.........
|
||||
.........#.#..............#........#.........#..#...#........#............##......##.......#....##.............#...................
|
||||
..........##.....................#................#...#....#........#.....#..........#........#................#..###..............
|
||||
......................#............................#........................#.#..#..........#......................................
|
||||
........#...........#.#....#.........#.....#..........#..#.#..............#.......................#..#................#.#..........
|
||||
.................................................................S.................................................................
|
||||
.........#.....#..#..........#.....#...........#...............##..#...............#.##....#...........#........#.#....#....#......
|
||||
.........##...#......#..#.#................#...........#..#...........#...#....#..............#......#..#.................##.......
|
||||
.....................##.....................##...#.......#......#.............................#..#.................................
|
||||
........................#..............#....#.................#....#...........#.................#...#.........#........#..........
|
||||
.........#..#.#...#.#..................#..............#.#...###....#......#......#.#....#..##..............#............#..........
|
||||
..#.......#...#..............#...#..##............#.........#......#.#....#.#..........................#......#..#.....#...........
|
||||
..#........#......##.............................#..............#..#....................##.......#....#..#..#..........#...........
|
||||
.....................#.....#...........#.##................#.#....#.#.#............#...#..##.............#.....##..................
|
||||
..##............#........#........#...#......#..........##.................#...#.#..........#...................................##.
|
||||
...#.............#....#...#..#........#.........#......#..................#..#..#..........#.....#........#.#....##............#...
|
||||
...#.............#...............................#.......#....#..........#..........................##......##...#.............#...
|
||||
....#................#..#.#................#.....#.......#..................#.......................#.#............................
|
||||
....#.#..............#..#.........#..#..#................#..#...#.#..............#......#...................#......................
|
||||
.#......#....................#.................#........##......#......##..........#...............#..##.#.....#.............#.....
|
||||
...##................#..........#......##.....#........#...#..................#........#......#....#..#.....#......................
|
||||
......#..................#......#.......#.......#..............#......#.........#.......#..#.#.#...##.....#.............#..........
|
||||
.#...................#...#....#......#.#.....#.....#..................#.#......#.......#.....#..#......................#.....#.....
|
||||
...#......................#.......#..#.........#............#...#......##..........#...............................................
|
||||
...#..#........#........#...........#.#...#...#.#..#.#...#..................#........#........#.#.##...#...........#...............
|
||||
........#.......................#.............#....#...##.........#....................................#..............#...#........
|
||||
...#...........##........#..#.......#...............................#..................#.....#.......#.#.........#.................
|
||||
..........#...............#.###...................#..................................#.....#...#................##...............#.
|
||||
..#......#..........................#...........................#..................#..#........#....##...................##......#.
|
||||
....#...........#..#..........................#......###................#...........................#.........#.#........#.#.......
|
||||
...#...#..#........#...............#...........#.......#........................##..#...............#............#...........#.....
|
||||
.....#..........................#..#........#.......#......#......#..........#..#.....#.....#..#.................#........#........
|
||||
....#...##.......................#...#.....#.....................................##.#..#....#....#................#................
|
||||
..#.....##.........#..............#.#................#.........#...#.................#.........#..............................#....
|
||||
............#...........#........#........................#.#.......#..#..#.........##...................#......##.#.......#.......
|
||||
.........#......#......#............#.....#...##...#...............................#.....#..............##............#..#.....##..
|
||||
...........................#.................#...........#.........#....#.#.#....#......#..#....................#......#...........
|
||||
....#.#..............................#......#..........#...........#....#.............#.#..............................#.....#..#..
|
||||
...........#...........#.............##....#......#.........#................#........#...............................#............
|
||||
...#........#.#....#.....................#..........#.......#...#.........#..........................##........#.#.#...##..........
|
||||
....#.#....#.........#.......#....................#...........#..........#....#......................#.............#.....#..#....#.
|
||||
..........#................................#......#....#......#.................................................#..................
|
||||
.............#................................#...#.##.#.....#.......#....#............###.......#........##.......................
|
||||
..........#......##.............#.........#............................#.#..#.......................................#.....#......#.
|
||||
...#.....#.......#............#.............#.#...#.....#.............#..#..........##.......................#.....................
|
||||
..........................#......#..................#..#........#............#.......##......................###.......#.....#.....
|
||||
............#.#....#.#................................##......#..............#..#.#........................#......#...#...#........
|
||||
......##..........#......###...#......................#.........#.#............#..............#......#..............#.......#......
|
||||
............#........#.....#........#..#.......#...#...................#.....#..................##.............#.................#.
|
||||
........#.#........##..................................#......#......................................#.....................#.#...#.
|
||||
.#.......##......#.....#..........#................#...................##..#...............#.......##....................#.........
|
||||
...#..#..#.............................#...................#................#....................................#........#........
|
||||
.....#....................................#.........##.............#...........................#...................................
|
||||
............................#....#......#...................#..................................#...........................##......
|
||||
...............#...#..#...#.###.#...........#..............#..........#...............##........#.##.#....#.#.............##.....#.
|
||||
...........#.##......#...#.#.........#.#.#...#.........................................#..........#.............#.#.............#..
|
||||
........#...............#........#........................#.#......#......#......................#...........#.........#.#...#.....
|
||||
....#..#.............#......................#...................#.....##...............#...#........#.................#............
|
||||
............#......#...#.....#..........#....#...............##.....##..#.........#....#..#.......#...#..#.........................
|
||||
......#...........#.......#...#.#.....#...#......#...........#......#................#................#....#.#...#.................
|
||||
.......#.#...#.......#......#.................................#..............................#...........#.............#.........#.
|
||||
...................................#.....#.........#.............................#..#............#...................#...#.........
|
||||
...............#......#...........................#................#...............##...........#......#........#....##......#.#...
|
||||
...............#....................##....#...#.....#.................................#..#.............#.#..#.....#..#.#...........
|
||||
.............................#......##..#........................................##....#.................#......#....#...#.........
|
||||
......#.#.#...............#.......#............................................................#................#..........#..#....
|
||||
...#.#...........#..#......#....###...............#..#..#......................#....#..............#......#................#.......
|
||||
.......................#....#.....#..#.##.#..........#.....................#..................................#....####.##.........
|
||||
......#..........##...#...........................#....#.................#........#.......................#.................#..#...
|
||||
.................#..#...................#..#...#...##...#..................#..........#.#....#..#...........................#....#.
|
||||
...................................................................................................................................
|
||||
11
day21/sample.txt
Normal file
11
day21/sample.txt
Normal file
@@ -0,0 +1,11 @@
|
||||
...........
|
||||
.....###.#.
|
||||
.###.##..#.
|
||||
..#.#...#..
|
||||
....#.#....
|
||||
.##..S####.
|
||||
.##..#...#.
|
||||
.......##..
|
||||
.##.#.####.
|
||||
.##..##.##.
|
||||
...........
|
||||
BIN
day22/c/day22
Executable file
BIN
day22/c/day22
Executable file
Binary file not shown.
140
day22/c/day22.c
Normal file
140
day22/c/day22.c
Normal file
@@ -0,0 +1,140 @@
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
#include <string.h>
|
||||
#include <omp.h>
|
||||
|
||||
#define LINE_MAX_LENGTH 256
|
||||
#define MAX_BRICKS 2048
|
||||
#define NUM_0_CHARCODE 48
|
||||
#define NUM_9_CHARCODE NUM_0_CHARCODE + 9
|
||||
#define max(a,b) ((a) > (b) ? (a) : (b))
|
||||
#define min(a,b) ((a) < (b) ? (a) : (b))
|
||||
#define in_range(c,a,b) ((c) <= max(a,b) && (c) >= min(a,b))
|
||||
|
||||
typedef struct corner {
|
||||
int x;
|
||||
int y;
|
||||
int z;
|
||||
} corner_t;
|
||||
|
||||
typedef struct brick {
|
||||
corner_t corners[2];
|
||||
int fallen;
|
||||
} brick_t;
|
||||
|
||||
int fall(brick_t bricks[], int bricks_num);
|
||||
int intersect(brick_t brick_a, brick_t brick_b);
|
||||
|
||||
int main() {
|
||||
char *p, *buf, c;
|
||||
|
||||
buf = (char *)malloc(LINE_MAX_LENGTH);
|
||||
memset(buf, 0, LINE_MAX_LENGTH);
|
||||
p = buf;
|
||||
|
||||
brick_t bricks[MAX_BRICKS];
|
||||
int bricks_num = 0;
|
||||
|
||||
while ((c = getchar()) != EOF) {
|
||||
*p++ = c;
|
||||
if (c == '\n') {
|
||||
p = buf;
|
||||
sscanf(p, "%i", &bricks[bricks_num].corners[0].x);
|
||||
while (*p != ',') p++;
|
||||
p++;
|
||||
sscanf(p, "%i", &bricks[bricks_num].corners[0].y);
|
||||
while (*p != ',') p++;
|
||||
p++;
|
||||
sscanf(p, "%i", &bricks[bricks_num].corners[0].z);
|
||||
while (*p != '~') p++;
|
||||
p++;
|
||||
sscanf(p, "%i", &bricks[bricks_num].corners[1].x);
|
||||
while (*p != ',') p++;
|
||||
p++;
|
||||
sscanf(p, "%i", &bricks[bricks_num].corners[1].y);
|
||||
while (*p != ',') p++;
|
||||
p++;
|
||||
sscanf(p, "%i", &bricks[bricks_num].corners[1].z);
|
||||
bricks_num++;
|
||||
memset(buf, 0, LINE_MAX_LENGTH);
|
||||
p = buf;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
while (fall(bricks, bricks_num));
|
||||
for (int i = 0; i < bricks_num; i++) {
|
||||
bricks[i].fallen = 0;
|
||||
}
|
||||
|
||||
int part1 = 0;
|
||||
int part2 = 0;
|
||||
#pragma omp parallel for schedule(dynamic)
|
||||
for (int i = 0; i < bricks_num; i++) {
|
||||
brick_t bricks_copy[MAX_BRICKS];
|
||||
memcpy(bricks_copy, bricks, sizeof(bricks));
|
||||
bricks_copy[i].corners[0].z = 0;
|
||||
bricks_copy[i].corners[1].z = 0;
|
||||
int fallen = 0;
|
||||
while (fall(bricks_copy, bricks_num));
|
||||
for (int j = 0; j < bricks_num; j++) {
|
||||
fallen += bricks_copy[j].fallen;
|
||||
}
|
||||
#pragma omp critical
|
||||
{
|
||||
if (fallen == 0) {
|
||||
part1++;
|
||||
}
|
||||
part2 += fallen;
|
||||
}
|
||||
}
|
||||
|
||||
printf("%i\n", part1);
|
||||
printf("%i\n", part2);
|
||||
|
||||
free(buf);
|
||||
}
|
||||
|
||||
int fall(brick_t bricks[], int bricks_num) {
|
||||
int result = 0;
|
||||
for (int i = 0; i < bricks_num; i++) {
|
||||
int fallen = 0;
|
||||
for (;;) {
|
||||
bricks[i].corners[0].z--;
|
||||
bricks[i].corners[1].z--;
|
||||
if (bricks[i].corners[0].z <= 0 || bricks[i].corners[1].z <= 0) {
|
||||
break;
|
||||
}
|
||||
int collision = 0;
|
||||
for (int j = 0; j < bricks_num; j++) {
|
||||
if (i == j) continue;
|
||||
if (intersect(bricks[i], bricks[j])) {
|
||||
collision = 1;
|
||||
break;
|
||||
}
|
||||
}
|
||||
if (collision) {
|
||||
break;
|
||||
}
|
||||
bricks[i].fallen = 1;
|
||||
fallen = 1;
|
||||
}
|
||||
bricks[i].corners[0].z++;
|
||||
bricks[i].corners[1].z++;
|
||||
result += fallen;
|
||||
}
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
int intersect(brick_t brick_a, brick_t brick_b) {
|
||||
if (
|
||||
(in_range(brick_b.corners[0].x, brick_a.corners[0].x, brick_a.corners[1].x) || in_range(brick_b.corners[1].x, brick_a.corners[0].x, brick_a.corners[1].x) || in_range(brick_a.corners[1].x, brick_b.corners[0].x, brick_b.corners[1].x) || in_range(brick_a.corners[0].x, brick_b.corners[0].x, brick_b.corners[1].x)) &&
|
||||
(in_range(brick_b.corners[0].y, brick_a.corners[0].y, brick_a.corners[1].y) || in_range(brick_b.corners[1].y, brick_a.corners[0].y, brick_a.corners[1].y) || in_range(brick_a.corners[1].y, brick_b.corners[0].y, brick_b.corners[1].y) || in_range(brick_a.corners[0].y, brick_b.corners[0].y, brick_b.corners[1].y)) &&
|
||||
(in_range(brick_b.corners[0].z, brick_a.corners[0].z, brick_a.corners[1].z) || in_range(brick_b.corners[1].z, brick_a.corners[0].z, brick_a.corners[1].z) || in_range(brick_a.corners[1].z, brick_b.corners[0].z, brick_b.corners[1].z) || in_range(brick_a.corners[0].z, brick_b.corners[0].z, brick_b.corners[1].z))
|
||||
) {
|
||||
return 1;
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
1439
day22/input.txt
Normal file
1439
day22/input.txt
Normal file
File diff suppressed because it is too large
Load Diff
7
day22/sample.txt
Normal file
7
day22/sample.txt
Normal file
@@ -0,0 +1,7 @@
|
||||
1,0,1~1,2,1
|
||||
0,0,2~2,0,2
|
||||
0,2,3~2,2,3
|
||||
0,0,4~0,2,4
|
||||
2,0,5~2,2,5
|
||||
0,1,6~2,1,6
|
||||
1,1,8~1,1,9
|
||||
BIN
day23/c/day23
Executable file
BIN
day23/c/day23
Executable file
Binary file not shown.
219
day23/c/day23.c
Normal file
219
day23/c/day23.c
Normal file
@@ -0,0 +1,219 @@
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
#include <string.h>
|
||||
#include <stdint.h>
|
||||
|
||||
#define LINE_MAX_LENGTH 256
|
||||
#define MAX_QUEUE 256*256
|
||||
#define cmp(a,b) ((a)[0] == (b)[0] && (a)[1] == (b)[1])
|
||||
#define abs(a) ((a) < 0 ? -(a) : (a))
|
||||
|
||||
typedef enum tile_type {
|
||||
PATH,
|
||||
FOREST,
|
||||
SLOPE_UP,
|
||||
SLOPE_DOWN,
|
||||
SLOPE_LEFT,
|
||||
SLOPE_RIGHT,
|
||||
} tile_type_t;
|
||||
|
||||
int check_direction(int curr[2], int dir[2], uint8_t **visited, tile_type_t map[LINE_MAX_LENGTH][LINE_MAX_LENGTH]);
|
||||
int highest_cost(int curr[2], tile_type_t map[LINE_MAX_LENGTH][LINE_MAX_LENGTH], int x, int y, uint8_t **visited, int cost, int finish[2], int ignore_slopes, int walkable);
|
||||
|
||||
int curr_max = 0;
|
||||
|
||||
int directions[4][2] = {
|
||||
{0, -1},
|
||||
{0, 1},
|
||||
{-1, 0},
|
||||
{1, 0}
|
||||
};
|
||||
|
||||
int main() {
|
||||
char *p, *buf, c;
|
||||
|
||||
buf = (char *)malloc(LINE_MAX_LENGTH);
|
||||
memset(buf, 0, LINE_MAX_LENGTH);
|
||||
p = buf;
|
||||
|
||||
tile_type_t map[LINE_MAX_LENGTH][LINE_MAX_LENGTH];
|
||||
int x = 0, y = 0;
|
||||
int walkable = 0;
|
||||
|
||||
while ((c = getchar()) != EOF) {
|
||||
*p++ = c;
|
||||
if (c == '\n') {
|
||||
p = buf;
|
||||
x = 0;
|
||||
while (*p != '\n') {
|
||||
switch (*p) {
|
||||
case '.':
|
||||
map[x][y] = PATH;
|
||||
walkable++;
|
||||
break;
|
||||
case '#':
|
||||
map[x][y] = FOREST;
|
||||
break;
|
||||
case '^':
|
||||
map[x][y] = SLOPE_UP;
|
||||
walkable++;
|
||||
break;
|
||||
case 'v':
|
||||
map[x][y] = SLOPE_DOWN;
|
||||
walkable++;
|
||||
break;
|
||||
case '<':
|
||||
map[x][y] = SLOPE_LEFT;
|
||||
walkable++;
|
||||
break;
|
||||
case '>':
|
||||
map[x][y] = SLOPE_RIGHT;
|
||||
walkable++;
|
||||
break;
|
||||
}
|
||||
x++;
|
||||
p++;
|
||||
}
|
||||
y++;
|
||||
memset(buf, 0, LINE_MAX_LENGTH);
|
||||
p = buf;
|
||||
}
|
||||
}
|
||||
|
||||
int start[2], finish[2];
|
||||
start[1] = 0;
|
||||
finish[1] = y - 1;
|
||||
|
||||
// Find start and finish
|
||||
for (int i = 0; i < x; i++) {
|
||||
if (map[i][0] == PATH) {
|
||||
start[0] = i;
|
||||
}
|
||||
if (map[i][y - 1] == PATH) {
|
||||
finish[0] = i;
|
||||
}
|
||||
}
|
||||
|
||||
uint8_t **visited = (uint8_t**)malloc(x * sizeof(uint8_t*));
|
||||
for (uint8_t i = 0; i < x; i++) {
|
||||
visited[i] = (uint8_t*)malloc(y * sizeof(uint8_t));
|
||||
memset(visited[i], 0, y * sizeof(uint8_t));
|
||||
}
|
||||
|
||||
printf("Part 1: %i\n", highest_cost(start, map, x, y, visited, 0, finish, 0, walkable));
|
||||
|
||||
for (uint8_t i = 0; i < x; i++) {
|
||||
memset(visited[i], 0, y * sizeof(uint8_t));
|
||||
}
|
||||
|
||||
printf("Part 2: %i\n", highest_cost(start, map, x, y, visited, 0, finish, 1, walkable));
|
||||
|
||||
free(buf);
|
||||
for (int i = 0; i < y; i++) {
|
||||
free(visited[i]);
|
||||
}
|
||||
free(visited);
|
||||
}
|
||||
|
||||
int highest_cost(int curr[2], tile_type_t map[LINE_MAX_LENGTH][LINE_MAX_LENGTH], int x, int y, uint8_t **visited, int cost, int finish[2], int ignore_slopes, int walkable) {
|
||||
if (cmp(curr, finish)) {
|
||||
return cost;
|
||||
}
|
||||
|
||||
// We will never reach the end
|
||||
if ((walkable - cost) < (abs(finish[0] - curr[0]) + abs(finish[1] - curr[1])) || visited[finish[0]][finish[1]-1]) {
|
||||
return -1;
|
||||
}
|
||||
|
||||
visited[curr[0]][curr[1]] = 1;
|
||||
|
||||
int *options[4], options_num = 0, *dir, max = 0;
|
||||
|
||||
if (map[curr[0]][curr[1]] == SLOPE_UP && !ignore_slopes) {
|
||||
dir = directions[0];
|
||||
if (check_direction(curr, dir, visited, map)) {
|
||||
options[0] = dir;
|
||||
options_num = 1;
|
||||
}
|
||||
} else if (map[curr[0]][curr[1]] == SLOPE_DOWN && !ignore_slopes) {
|
||||
dir = directions[1];
|
||||
if (check_direction(curr, dir, visited, map)) {
|
||||
options[0] = dir;
|
||||
options_num = 1;
|
||||
}
|
||||
} else if (map[curr[0]][curr[1]] == SLOPE_LEFT && !ignore_slopes) {
|
||||
dir = directions[2];
|
||||
if (check_direction(curr, dir, visited, map)) {
|
||||
options[0] = dir;
|
||||
options_num = 1;
|
||||
}
|
||||
} else if (map[curr[0]][curr[1]] == SLOPE_RIGHT && !ignore_slopes) {
|
||||
dir = directions[3];
|
||||
if (check_direction(curr, dir, visited, map)) {
|
||||
options[0] = dir;
|
||||
options_num = 1;
|
||||
}
|
||||
} else {
|
||||
for (int i = 0; i < 4; i++) {
|
||||
int *dir = directions[i];
|
||||
if (check_direction(curr, dir, visited, map)) {
|
||||
options[options_num] = dir;
|
||||
options_num++;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if (options_num == 0) {
|
||||
return -1;
|
||||
}
|
||||
|
||||
|
||||
uint8_t ***visited_copies = (uint8_t***)malloc(options_num * sizeof(uint8_t**));
|
||||
for (uint8_t i = 0; i < options_num - 1; i++) {
|
||||
visited_copies[i] = (uint8_t**)malloc(x * sizeof(uint8_t*));
|
||||
for (uint8_t j = 0; j < y; j++) {
|
||||
visited_copies[i][j] = (uint8_t*)malloc(y * sizeof(uint8_t));
|
||||
memcpy(visited_copies[i][j], visited[j], y * sizeof(uint8_t));
|
||||
}
|
||||
}
|
||||
|
||||
for (int i = 0; i < options_num; i++) {
|
||||
int next[2];
|
||||
next[0] = curr[0] + options[i][0];
|
||||
next[1] = curr[1] + options[i][1];
|
||||
int c;
|
||||
if (i != options_num - 1) {
|
||||
c = highest_cost(next, map, x, y, visited_copies[i], cost + 1, finish, ignore_slopes, walkable);
|
||||
} else {
|
||||
c = highest_cost(next, map, x, y, visited, cost + 1, finish, ignore_slopes, walkable);
|
||||
}
|
||||
if (c > max) {
|
||||
max = c;
|
||||
}
|
||||
}
|
||||
|
||||
for (int i = 0; i < options_num - 1; i++) {
|
||||
for (int j = 0; j < y; j++) {
|
||||
free(visited_copies[i][j]);
|
||||
}
|
||||
free(visited_copies[i]);
|
||||
}
|
||||
free(visited_copies);
|
||||
|
||||
if (max > curr_max) {
|
||||
curr_max = max;
|
||||
printf("Current best: %i\n", curr_max);
|
||||
}
|
||||
|
||||
return max;
|
||||
}
|
||||
|
||||
int check_direction(int curr[2], int dir[2], uint8_t **visited, tile_type_t map[LINE_MAX_LENGTH][LINE_MAX_LENGTH]) {
|
||||
int next_x = curr[0] + dir[0];
|
||||
int next_y = curr[1] + dir[1];
|
||||
if (next_y > 0 && !visited[next_x][next_y] && map[next_x][next_y] != FOREST) {
|
||||
return 1;
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
141
day23/input.txt
Normal file
141
day23/input.txt
Normal file
@@ -0,0 +1,141 @@
|
||||
#.###########################################################################################################################################
|
||||
#.#...#...#.....###...#.......###...#####...#...#...#...#...#...#.......#...#.....#.....#.......#...#...#...###...#.....#.....#.............#
|
||||
#.#.#.#.#.#.###.###.#.#.#####.###.#.#####.#.#.#.#.#.#.#.#.#.#.#.#.#####.#.#.#.###.#.###.#.#####.#.#.#.#.#.#.###.#.#.###.#.###.#.###########.#
|
||||
#.#.#.#.#.#.#...#...#.#...#...#...#...#...#...#.#.#.#.#.#.#...#...#.....#.#.#...#.#.#...#.....#.#.#...#.#.#...#.#.#.#...#...#.#.....#.....#.#
|
||||
#.#.#.#.#.#.#.###.###.###.#.###.#####.#.#######.#.#.#.#.#.#########.#####.#.###.#.#.#.#######.#.#.#####.#.###.#.#.#.#.#####.#.#####.#.###.#.#
|
||||
#...#.#.#.#.#...#.#...###.#...#.#...#.#.....#...#.#...#.#.#.........#.....#...#.#.#.#...#...#.#.#.#.....#.#...#.#.#.#...#...#.#.....#...#...#
|
||||
#####.#.#.#.###.#.#.#####.###.#.#.#.#.#####.#.###.#####.#.#.#########.#######.#.#.#.###.#.#.#.#.#.#.#####.#.###.#.#.###.#.###.#.#######.#####
|
||||
#.....#.#.#.###...#.#...#.#...#.#.#...#.....#.#...#...#.#.#.###.....#.....#...#.#.#.#...#.#.#.#.#.#...###.#...#.#.#...#...#...#.....#...#...#
|
||||
#.#####.#.#.#######.#.#.#.#.###.#.#####.#####.#.###.#.#.#.#.###.###.#####.#.###.#.#.#.###.#.#.#.#.###.###.###.#.#.###.#####.#######.#.###.#.#
|
||||
#.#...#.#...#.....#.#.#.#.#...#.#.>.>.#.....#.#.#...#...#.#...#.#...###...#.#...#...#.#...#...#.#.#...#...#...#.#.###.#.....#...#...#...#.#.#
|
||||
#.#.#.#.#####.###.#v#.#.#.###.#.###v#.#####.#.#.#.#######.###.#.#.#####.###.#.#######.#.#######.#.#.###.###.###.#.###.#.#####.#.#.#####.#.#.#
|
||||
#...#...#...#.#...#.>.#.#.###.#.#...#.......#.#.#.#.>.>.#.#...#.#...#...#...#.#.....#.#.....#...#.#.###...#.#...#...#.#.#...#.#.#...#...#.#.#
|
||||
#########.#.#.#.###v###.#.###.#.#.###########.#.#.#.#v#.#.#.###.###.#.###.###.#.###.#.#####.#.###.#.#####.#.#.#####.#.#.#.#.#.#.###.#.###.#.#
|
||||
###.....#.#...#.#...###.#.#...#.#...###...###...#...#.#.#.#...#...#.#.#...###...#...#.#...#.#...#.#.>.>...#.#.#.....#.#.#.#.#.#.#...#.....#.#
|
||||
###.###.#.#####.#.#####.#.#.###.###.###.#.###########.#.#.###.###.#.#.#.#########.###.#.#.#.###.#.###v#####.#.#.#####.#.#.#.#.#.#.#########.#
|
||||
#...#...#.....#.#.....#.#.#.....###...#.#.....#.......#...###...#.#.#.#.#.>.>.#...#...#.#.#.#...#.###.#.....#.#.#...#.#.#.#.#.#.#.#.........#
|
||||
#.###.#######.#.#####.#.#.###########.#.#####.#.###############.#.#.#.#.#.#v#.#.###.###.#.#.#.###.###.#.#####.#.#.#.#.#.#.#.#.#.#.#.#########
|
||||
#...#.........#.....#.#.#.#...........#.###...#.......###.......#.#.#.#...#.#.#...#.#...#...#...#.#...#.#...#.#.#.#.#.#.#.#.#.#.#.#.#...#...#
|
||||
###.###############.#.#.#.#.###########.###.#########.###.#######.#.#.#####.#.###.#.#.#########.#.#.###.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#
|
||||
###...............#.#.#.#.#...#.......#...#.#...#...#...#...#...#.#...###...#.....#...#...#.....#.#...#.#.#.#.#.#.#.#.#.#.#.#.#.#.#...#.#.#.#
|
||||
#################.#.#.#.#.###.#.#####.###.#.#.#.#.#.###.###.#.#.#.#######.#############.#.#.#####.###.#.#.#.#.#.#.#.#.#.#.#.#.#.#.#####.#.#.#
|
||||
#.................#...#...###.#.#.....#...#...#.#.#.#...###...#.#.#.......#...#...#.....#.#.#.....#...#...#...#.#.#...#.#.#...#...#...#...#.#
|
||||
#.###########################.#.#.#####.#######.#.#.#.#########.#.#.#######.#.#.#.#.#####.#.#.#####.###########.#.#####.#.#########.#.#####.#
|
||||
#.................###...#####...#.....#.#.......#.#...#...#.....#.#...#...#.#...#.#.#.....#...#.....#...###...#.#.....#...###...#...#.#...#.#
|
||||
#################.###.#.#############.#.#.#######.#####.#.#.#####.###.#.#.#.#####.#.#.#########.#####.#.###.#.#.#####.#######.#.#.###.#.#.#.#
|
||||
#.......#...#...#.#...#...#...#.....#...#.....###.....#.#.#.....#...#...#.#.#.....#.#.#.....#...#...#.#...#.#.#.......#...#...#.#.###...#...#
|
||||
#.#####.#.#.#.#.#.#.#####.#.#.#.###.#########.#######.#.#.#####.###.#####.#.#.#####.#.#.###.#.###.#.#.###.#.#.#########.#.#.###.#.###########
|
||||
#.#...#...#...#...#.#.....#.#.#...#.###.......#.......#.#...###.....###...#.#.#.....#.#.#...#.....#...###...#...###...#.#.#...#.#...........#
|
||||
#.#.#.#############.#.#####.#.###.#.###.#######.#######.###.###########.###.#.#.#####.#.#.#####################.###.#.#.#.###.#.###########.#
|
||||
#...#.#...#...#...#.#...#...#...#.#.....#.....#...#...#.#...#.........#.....#.#.#.....#.#.#...#.......#.........#...#.#.#.#...#...#.......#.#
|
||||
#####.#.#.#.#.#.#.#.###.#.#####.#.#######.###.###.#.#.#.#.###.#######.#######.#.#.#####.#.#.#.#.#####.#.#########.###.#.#.#.#####.#.#####.#.#
|
||||
#.....#.#.#.#.#.#.#...#.#.#.....#...#...#.#...###...#...#.#...#.......###...#...#...#...#.#.#.#...#...#.#.......#...#...#...#####...#...#.#.#
|
||||
#.#####.#.#.#v#.#.###.#.#.#.#######.#.#.#.#.#############.#.###.#########.#.#######.#.###.#.#.###.#.###.#.#####.###.#################.#.#.#.#
|
||||
#.......#...#.>.#...#.#.#.#...#...#...#...#.###...###.....#...#.#...#.....#.#.......#...#.#.#.....#...#...#...#...#.#...............#.#.#...#
|
||||
#############v#####.#.#.#.###.#.#.#########.###.#.###v#######.#.#.#.#.#####.#.#########.#.#.#########.#####.#.###.#.#.#############.#.#.#####
|
||||
#.........###.....#...#...#...#.#.......#...#...#.#.>.>.#...#.#.#.#.#.....#.#.#...#...#.#.#.......#...#...#.#...#.#.#.#.............#.#.....#
|
||||
#.#######.#######.#########.###.#######.#.###.###.#.#v#.#.#.#.#.#.#.#####.#.#.#.#.#.#.#.#.#######.#.###.#.#v###.#.#.#.#.#############.#####.#
|
||||
#.......#.#.....#.....#.....###.......#.#...#...#...#.#.#.#.#.#.#.#...###.#.#...#.#.#.#.#...#...#.#...#.#.>.>.#...#...#...............#...#.#
|
||||
#######.#.#.###.#####.#.#############.#.###v###.#####.#.#.#.#.#.#.###.###.#.#####v#.#.#.###.#.#.#.###.#.###v#.#########################.#.#.#
|
||||
#...###.#.#...#.#.....#.#.....#...#...#.#.>.>...#.....#...#.#.#...###...#.#.#...>.>.#...###.#.#.#.#...#.#...#.#...#...#...#.........#...#.#.#
|
||||
#.#.###.#.###.#.#.#####.#.###.#.#.#.###.#.#v#####.#########.#.#########.#.#.#.###v#########.#.#.#.#.###.#.###.#.#.#.#.#.#.#v#######.#.###.#.#
|
||||
#.#...#.#.###.#.#.....#.#.###.#.#...###...#.....#...#...###...#.......#.#.#.#...#.#...#...#.#.#.#.#.#...#.###.#.#.#.#.#.#.>.###...#...###...#
|
||||
#.###.#.#.###.#.#####.#.#.###.#.###############.###.#.#.#######.#####.#.#.#.###.#.#.#.#.#.#.#.#.#.#.#.###.###.#.#.#.#.#.###v###.#.###########
|
||||
#...#.#.#...#.#.......#.#.#...#.###...###...#...###...#.........#.....#...#.....#...#...#.#.#.#.#.#.#.###...#...#.#.#.#.###.....#.#...#...###
|
||||
###.#.#.###.#.#########.#.#.###.###.#.###.#.#.###################.#######################.#.#.#.#.#.#.#####.#####.#.#.#.#########.#.#.#.#.###
|
||||
#...#.#...#.#.#.......#.#.#...#.#...#.#...#.#.#.................#.....#.................#.#...#...#...#.....#...#...#...#.........#.#...#...#
|
||||
#.###.###.#.#.#.#####.#.#.###.#.#.###.#.###.#.#.###############.#####.#.###############.#.#############.#####.#.#########.#########.#######.#
|
||||
#...#.....#...#.#.....#...#...#.#...#...###...#...#...#.......#.#.....#...........#...#...#...###.....#.....#.#.###...###.........#.#.......#
|
||||
###.###########.#.#########.###.###.#############.#.#.#.#####.#.#.###############.#.#.#####.#.###.###.#####.#.#.###.#.###########.#.#.#######
|
||||
###.............#.....#...#.....###...#...###...#...#...#.....#...#...#...#...###...#...#...#...#...#.#.....#.#.#...#...#.........#.#.#...###
|
||||
#####################.#.#.###########.#.#.###.#.#########.#########.#.#.#.#.#.#########.#.#####.###.#.#.#####.#.#.#####.#.#########.#.#.#.###
|
||||
#.....................#.#.#.....#...#...#.....#.#...#.....###...###.#.#.#.#.#.#...#.....#.....#.###.#.#...###.#.#...#...#.........#.#...#...#
|
||||
#.#####################.#.#.###.#.#.###########.#.#.#.#######.#.###.#.#.#.#.#.#.#.#.#########.#.###.#.###v###.#.###.#.###########v#.#######.#
|
||||
#.#.....#.............#.#.#...#.#.#.............#.#.#.......#.#.###.#.#.#.#.#.#.#.#...#####...#.#...#...>.>.#.#.#...#...#.....#.>.#.#.......#
|
||||
#.#.###.#.###########.#.#.###.#.#v###############.#.#######.#.#.###.#.#.#.#.#.#.#.###v#####.###.#.#######v#.#.#.#.#####.#.###.#.#v#.#.#######
|
||||
#...#...#.#.....#...#.#.#.#...#.>.>...#...###.....#...#.....#.#.###.#.#.#.#.#.#.#...>.>.#...###.#.#.......#...#...#.....#...#...#.#.#.#...###
|
||||
#####.###.#.###.#.#.#.#.#.#.#####v###.#.#.###.#######.#.#####.#.###.#.#.#.#.#.#.#####v#.#.#####.#.#.###############.#######.#####.#.#.#.#.###
|
||||
#...#.....#...#...#...#.#...###...###...#...#.#.......#.....#.#.#...#.#.#.#.#.#...#...#...#...#...#.....#...###.....#...#...#.....#.#...#...#
|
||||
#.#.#########.#########.#######.###########.#.#.###########.#.#.#.###.#.#.#.#.###.#.#######.#.#########.#.#.###.#####.#.#.###.#####.#######.#
|
||||
#.#.#...#...#...#.....#.......#.......#...#...#...###...#...#.#.#...#.#.#.#.#.#...#.........#.#...#####...#...#...#...#...###.......#...#...#
|
||||
#.#.#.#.#.#.###.#.###.#######.#######.#.#.#######.###.#.#v###.#.###.#.#.#.#.#.#.#############.#.#.###########.###.#.#################.#.#.###
|
||||
#.#...#...#.....#.#...#...#...#.......#.#.......#...#.#.>.>...#.#...#.#.#.#.#.#...###.......#.#.#.............#...#.#.................#...###
|
||||
#.###############.#.###.#.#.###.#######.#######.###.#.###v#####.#.###.#.#.#.#.###.###.#####.#.#.###############.###.#.#######################
|
||||
#...#.....#...###.#.....#...###...#...#...#.....#...#...#.#...#...###...#...#.#...#...#...#...#.............###.#...#.......................#
|
||||
###.#.###.#.#v###.###############.#.#.###.#.#####.#####.#.#.#.###############.#.###.###.#.#################.###.#.#########################.#
|
||||
###.#.###.#.#.>...#...........#...#.#.....#.#...#...#...#.#.#.........#.......#.###.....#.#.......#.......#...#.#.#...###...#...............#
|
||||
###.#.###.#.#v#####.#########.#.###.#######.#.#.###.#.###.#.#########.#.#######.#########.#.#####.#.#####.###.#.#.#.#.###.#.#.###############
|
||||
#...#...#...#...#...#.........#.....#.......#.#...#.#.###.#.#.....#...#.......#...#.......#.#.....#.....#.....#...#.#.....#...#...#...###...#
|
||||
#.#####.#######.#.###.###############.#######.###.#.#.###.#.#.###.#.#########.###.#.#######.#.#########.###########.###########.#.#.#.###.#.#
|
||||
#.#.....#.....#...#...#...#...#...###.........#...#.#.###...#...#...#####...#.....#.........#...###...#.........###.....#.....#.#...#.#...#.#
|
||||
#.#.#####.###.#####.###.#.#.#.#.#.#############.###.#.#########.#########.#.###################.###.#.#########.#######.#.###.#.#####.#.###.#
|
||||
#...#...#...#.......###.#.#.#.#.#...#...........###...#...#...#...#...###.#.###.......#.........#...#.#.........#...###...###...#.....#.#...#
|
||||
#####.#.###.###########.#.#.#.#.###.#.#################.#.#.#.###.#.#.###.#.###.#####.#.#########.###.#.#########.#.#############.#####.#.###
|
||||
#.....#.....#.........#.#...#.#...#.#...#...#...###...#.#.#.#.###...#.....#...#.....#.#.........#...#.#.....#.....#.#...###...#...#.....#.###
|
||||
#.###########.#######.#.#####.###.#.###.#.#.#.#.###.#.#.#.#.#.###############.#####.#.#########.###.#.#####.#.#####.#.#.###.#.#.###.#####.###
|
||||
#.......#...#.#.......#.....#...#.#.###...#...#...#.#.#.#.#.#...#.....#.....#.#.....#...........###.#.......#.#.....#.#.#...#.#.....#...#...#
|
||||
#######.#.#.#.#.###########.###.#.#.#############.#.#.#.#.#.###.#.###.#.###.#.#.###################.#########.#.#####.#.#.###.#######.#.###.#
|
||||
#.......#.#...#.........#...#...#.#.#...###.......#.#.#.#.#.#...#.###...###...#.......#...###.....#.....#...#.#.#...#.#.#.#...#...###.#.#...#
|
||||
#.#######.#############.#.###.###.#.#.#.###v#######.#.#.#.#.#.###v###################.#.#.###.###.#####v#.#.#.#.#.#.#.#.#.#.###.#.###.#.#v###
|
||||
#.......#.#.............#...#...#.#.#.#...>.>...#...#.#.#...#...>.>.#...#...###.......#.#...#...#.#...>.>.#.#.#.#.#.#.#.#.#...#.#.....#.>.###
|
||||
#######.#.#.###############.###.#.#.#.#####v###.#.###.#.#########v#.#.#.#.#.###.#######.###.###.#.#.###v###.#.#.#.#.#.#.#.###.#.#########v###
|
||||
###...#...#.........###...#...#...#...###...#...#.#...#...#...#...#...#...#...#.........#...###.#.#...#...#.#.#.#.#.#.#.#.#...#.#...###...###
|
||||
###.#.#############.###.#.###.###########.###.###.#.#####.#.#.#.#############.###########.#####.#.###.###.#.#.#.#.#.#.#.#.#.###.#.#.###.#####
|
||||
#...#...............#...#.#...#...........###...#.#.#.....#.#.#...#...........#...#.......###...#.#...#...#.#.#.#.#.#.#.#.#.....#.#...#.#...#
|
||||
#.###################.###.#.###.###############.#.#.#.#####.#.###.#.###########.#.#.#########.###.#.###.###.#.#.#.#.#.#.#.#######.###.#.#.#.#
|
||||
#.#...........#...#...#...#...#.............#...#.#...###...#.#...#...###...#...#.#.........#...#.#.###...#...#...#...#...#.....#.#...#...#.#
|
||||
#.#.#########.#.#v#.###.#####.#############.#.###.#######.###.#.#####.###.#.#.###.#########.###.#.#.#####.#################.###.#.#.#######.#
|
||||
#.#.###...###...#.>.###.......#...###.......#.....###...#...#.#.....#...#.#.#.#...#...###...#...#.#...#...#...#...#...#...#...#...#...#...#.#
|
||||
#.#.###.#.#######v#############.#.###.###############.#.###.#.#####.###.#.#.#.#.###.#.###v###.###.###.#.###.#.#.#.#.#.#.#.###.#######.#.#.#.#
|
||||
#...#...#.......#.........#.....#.....#...###...###...#.....#.#.....#...#.#.#.#...#.#...>.>.#...#.....#.....#.#.#...#...#.###.......#.#.#.#.#
|
||||
#####.#########.#########.#.###########.#.###.#.###.#########.#.#####.###.#.#.###.#.#####v#.###.#############.#.#########.#########.#.#.#.#.#
|
||||
#.....#.......#.#...#...#.#.............#.....#.#...#...#...#.#...#...#...#...#...#...#...#.#...###...........#.........#.#...#...#.#.#.#...#
|
||||
#.#####.#####.#.#.#.#.#.#.#####################.#.###.#.#.#.#.###.#.###.#######.#####.#.###.#.#####.###################.#.#.#.#.#.#.#.#.#####
|
||||
#.#.....#.....#...#...#...#.......#.............#.....#...#.#.....#...#.......#.....#.#...#.#.....#.............#.......#...#...#.#.#.#.....#
|
||||
#.#.#####.#################.#####.#.#######################.#########.#######.#####.#.###.#.#####.#############.#.###############.#.#.#####.#
|
||||
#...#...#.#...#.......#...#...#...#...........#.......#...#.#...#...#.#.......#.....#.#...#.......#.......#.....#...#...#...#...#...#.......#
|
||||
#####.#.#.#.#.#.#####.#.#.###.#.#############.#.#####.#.#.#.#.#.#.#.#.#.#######.#####.#.###########.#####.#.#######.#.#.#.#.#.#.#############
|
||||
#...#.#.#...#...#.....#.#.#...#...###...#.....#.....#...#...#.#.#.#.#...#...###.......#.#...#.....#.#...#...###...#.#.#.#.#...#.###.........#
|
||||
#.#.#.#.#########.#####.#.#.#####.###.#.#.#########.#########.#.#.#.#####.#.###########.#.#.#.###.#.#.#.#######.#.#.#.#.#.#####.###.#######.#
|
||||
#.#...#.#...#...#.....#.#.#...#...#...#...###.....#...#...###.#.#.#.#...#.#.###...#...#.#.#.#.#...#.#.#.......#.#.#...#...#...#.....#...#...#
|
||||
#.#####.#.#.#.#.#####.#.#.###.#.###.#########.###.###.#.#.###.#.#.#.#.#.#.#.###.#.#.#.#v#.#.#.#.###.#.#######.#.#.#########.#.#######.#.#.###
|
||||
#.....#.#.#...#.#.....#.#...#.#.###...###...#...#.###.#.#.#...#.#.#.#.#.#.#.#...#.#.#.>.>.#...#.###...#.......#.#.#.........#.........#...###
|
||||
#####.#.#.#####.#.#####.###.#.#.#####v###.#.###.#.###v#.#.#.###.#.#.#.#.#.#.#.###.#.###v#######.#######.#######.#.#.#########################
|
||||
#.....#...#...#...#...#...#.#.#.#...>.>...#.#...#...>.>.#.#...#.#.#.#.#.#.#.#...#.#.#...#.....#...#.....#.....#.#.#.........#.........#.....#
|
||||
#.#########.#.#####.#.###.#.#.#.#.###v#####.#.#######v###.###.#.#.#.#.#.#.#.###.#.#.#.###.###.###.#.#####.###.#.#.#########.#.#######.#.###.#
|
||||
#.....#.....#.....#.#...#.#.#.#.#...#...###...###...#...#...#.#.#.#.#.#.#.#.#...#...#...#...#.....#.......#...#.#...#...###.#.#.......#...#.#
|
||||
#####.#.#########.#.###.#.#.#.#.###.###.#########.#.###.###.#.#.#.#.#.#.#.#.#.#########.###.###############.###.###.#.#.###.#.#.#########.#.#
|
||||
#.....#.#.........#...#.#.#.#.#.#...###.......#...#.#...###.#.#.#.#.#.#.#.#.#.#...#.....###.........#.......#...#...#.#...#...#...#.......#.#
|
||||
#.#####.#.###########.#.#.#.#.#.#.###########.#.###.#.#####.#.#.#.#.#.#.#.#.#.#.#.#.###############.#.#######.###.###.###.#######.#.#######.#
|
||||
#...#...#.........#...#.#.#.#.#...#...........#...#...#...#.#.#.#.#.#.#...#.#.#.#.#.....#####.......#...#...#...#.###.#...#.....#...#...#...#
|
||||
###.#.###########.#.###.#.#.#.#####.#############.#####.#.#.#.#.#.#.#.#####.#.#.#.#####.#####.#########v#.#.###.#.###.#.###v###.#####.#.#.###
|
||||
###...#...###...#.#...#...#...###...#...#.......#.......#.#...#.#.#.#...#...#.#.#.......#.....#.......>.>.#.#...#...#.#...>.###.......#...###
|
||||
#######.#.###.#.#v###.###########.###.#.#.#####.#########.#####.#.#.###.#.###.#.#########.#####.#######v###.#.#####.#.#####v#################
|
||||
#.......#.....#.#.>.#.......#...#.....#...#.....#.........#...#...#.#...#.#...#...#...###.#...#.....###...#.#.....#.#...#...###...#...#.....#
|
||||
#.#############.#v#.#######.#.#.###########.#####.#########.#.#####.#.###.#.#####.#.#.###.#.#.#####.#####.#.#####.#.###.#.#####.#.#.#.#.###.#
|
||||
#.............#...#.......#.#.#...........#...###.......#...#...###...###.#...###...#...#...#.#.....#...#.#.#...#.#.#...#.#...#.#...#.#.#...#
|
||||
#############.###########.#.#.###########.###.#########.#.#####.#########.###.#########.#####.#.#####.#.#.#.#.#.#.#.#.###.#.#.#.#####.#.#.###
|
||||
#...#...#...#...........#.#.#...#.......#.....#...###...#.#.....#...#...#.#...#.........#...#.#.#.....#...#.#.#...#.#...#.#.#.#.#.....#.#...#
|
||||
#.#.#.#.#.#.###########.#.#.###.#.#####.#######.#.###.###.#.#####.#.#.#.#.#.###.#########.#.#.#.#.#########.#.#####.###.#.#.#.#.#.#####.###.#
|
||||
#.#...#...#.......#.....#...###...#...#...#.....#.#...###.#.#...#.#...#.#...###...........#.#.#.#.....#...#.#...#...#...#...#.#.#.#...#.#...#
|
||||
#.###############.#.###############.#.###.#.#####.#.#####.#.#.#.#.#####.###################.#.#.#####.#.#.#.###.#.###.#######.#.#.#.#.#.#.###
|
||||
#...............#.#.......#...#.....#.....#.#.....#.......#.#.#.#...#...###.................#...#...#...#.#.#...#...#.....#...#.#.#.#...#...#
|
||||
###############.#.#######.#.#.#.###########.#.#############.#.#.###.#.#####.#####################.#.#####.#.#.#####.#####.#.###.#.#.#######.#
|
||||
#...............#.#.....#...#.#.............#.....#.......#.#.#.###.#.#...#.......#...........#...#.....#.#...#.....#.....#.....#...###.....#
|
||||
#.###############.#.###.#####.###################.#.#####.#.#.#.###.#.#.#.#######.#.#########.#.#######.#.#####.#####.#################.#####
|
||||
#.......#...#...#...###.......###...#.............#.....#...#.#...#.#...#.###...#...#.........#.......#...#...#.......###...#...#.......#...#
|
||||
#######.#.#.#.#.#################.#.#.#################.#####.###.#.#####.###.#.#####.###############.#####.#.###########.#.#.#.#.#######.#.#
|
||||
#...###...#...#.....#...#...#.....#.#.........#...#.....#...#.#...#.#.....#...#.......###...###...###...#...#...#...#.....#.#.#.#.....#...#.#
|
||||
#.#.###############.#.#.#.#.#.#####.#########.#.#.#.#####.#.#.#.###.#.#####.#############.#.###.#.#####.#.#####.#.#.#.#####.#.#.#####.#.###.#
|
||||
#.#.................#.#.#.#.#.#.....#.........#.#.#...###.#.#.#.#...#.#...#.......#.....#.#.#...#.......#.#.....#.#.#.#.....#.#...###...#...#
|
||||
#.###################.#.#.#.#.#.#####.#########.#.###.###.#.#.#.#.###.#.#.#######.#.###.#.#.#.###########.#.#####.#.#.#.#####.###.#######.###
|
||||
#.#...#...#.....#...#.#.#.#.#.#.#...#.......#...#...#...#.#.#.#.#...#.#.#.###...#...#...#.#.#.....#.......#.....#.#.#.#.....#...#.#.....#...#
|
||||
#.#.#.#.#.#.###.#.#.#.#.#.#.#.#.#.#.#######.#.#####.###.#.#.#.#.###.#.#.#.###.#.#####v###.#.#####.#.###########.#.#.#.#####.###.#.#.###.###.#
|
||||
#...#...#.#.#...#.#.#.#.#.#.#.#.#.#.###.....#...#...#...#.#.#.#...#.#.#.#...#.#.#...>.>.#.#.#...#...#...........#.#.#.#.....###.#.#.#...#...#
|
||||
#########.#.#.###.#.#.#.#.#.#.#.#.#.###v#######.#.###v###.#.#.###.#.#.#.###.#.#.#.#####.#.#.#.#.#####v###########.#.#.#.#######.#.#.#.###v###
|
||||
#.........#.#...#.#...#.#.#.#.#.#.#...>.>...#...#.#.>.>.#.#.#...#.#.#.#...#...#.#...###.#.#...#.#...>.>.#...#...#.#.#.#.#...#...#...#.#.>.###
|
||||
#.#########.###.#.#####.#.#.#.#.#.#########.#.###.#.###.#.#.###.#.#.#.###.#####.###.###.#.#####.#.#####.#.#.#.#.#.#.#.#.#.#.#.#######.#.#v###
|
||||
#.....#...#.#...#.#.....#.#.#.#.#.#.........#...#.#...#.#.#.#...#.#.#.#...#.....#...#...#.....#.#...#...#.#.#.#.#.#.#.#.#.#.#.#.......#.#.###
|
||||
#####.#.#.#.#.###.#.#####.#.#.#.#.#.###########.#.###.#.#.#.#.###.#.#.#.###.#####.###.#######.#.###.#.###.#.#.#.#.#.#.#.#.#.#.#.#######.#.###
|
||||
#####...#...#.....#.......#...#...#.............#.....#...#...###...#...###.......###.........#.....#.....#...#...#...#...#...#.........#...#
|
||||
###########################################################################################################################################.#
|
||||
23
day23/sample.txt
Normal file
23
day23/sample.txt
Normal file
@@ -0,0 +1,23 @@
|
||||
#.#####################
|
||||
#.......#########...###
|
||||
#######.#########.#.###
|
||||
###.....#.>.>.###.#.###
|
||||
###v#####.#v#.###.#.###
|
||||
###.>...#.#.#.....#...#
|
||||
###v###.#.#.#########.#
|
||||
###...#.#.#.......#...#
|
||||
#####.#.#.#######.#.###
|
||||
#.....#.#.#.......#...#
|
||||
#.#####.#.#.#########v#
|
||||
#.#...#...#...###...>.#
|
||||
#.#.#v#######v###.###v#
|
||||
#...#.>.#...>.>.#.###.#
|
||||
#####v#.#.###v#.#.###.#
|
||||
#.....#...#...#.#.#...#
|
||||
#.#########.###.#.#.###
|
||||
#...###...#...#...#.###
|
||||
###.###.#.###v#####v###
|
||||
#...#...#.#.>.>.#.>.###
|
||||
#.###.###.#.###.#.#v###
|
||||
#.....###...###...#...#
|
||||
#####################.#
|
||||
BIN
day3/c/day3
Executable file
BIN
day3/c/day3
Executable file
Binary file not shown.
155
day3/c/day3.c
Normal file
155
day3/c/day3.c
Normal file
@@ -0,0 +1,155 @@
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
#include <string.h>
|
||||
|
||||
#define LINE_MAX_LENGTH 256
|
||||
#define MAX_MAP_SIZE 1024
|
||||
#define MAX_NUMBERS 32*1024
|
||||
#define abs(a) ((a) < 0 ? -(a) : (a))
|
||||
|
||||
struct num_position_t {
|
||||
int x;
|
||||
int y;
|
||||
int length;
|
||||
unsigned int value;
|
||||
};
|
||||
|
||||
struct num_position_t* create_position(int x, int y, int length, unsigned int value);
|
||||
int has_adjacent_symbol(struct num_position_t* number, int symbol_map[MAX_MAP_SIZE][MAX_MAP_SIZE]);
|
||||
unsigned int gear_ratio(int x, int y, struct num_position_t** numbers, int num_numbers);
|
||||
|
||||
int main() {
|
||||
char *p, *buf, c, tmp[64];
|
||||
struct num_position_t **numbers, *tmp_pos;
|
||||
numbers = (struct num_position_t**)malloc(MAX_NUMBERS * sizeof(struct num_position_t*));
|
||||
|
||||
int symbol_map[MAX_MAP_SIZE][MAX_MAP_SIZE];
|
||||
memset(symbol_map, 0, MAX_MAP_SIZE*MAX_MAP_SIZE*sizeof(int));
|
||||
|
||||
int num_numbers = 0, num_length = 0;
|
||||
unsigned int curr = 0;
|
||||
int x = 0, y = 0;
|
||||
|
||||
buf = (char *)malloc(LINE_MAX_LENGTH);
|
||||
memset(buf, 0, LINE_MAX_LENGTH);
|
||||
p = buf;
|
||||
|
||||
int map_x = 0;
|
||||
int map_y = 0;
|
||||
|
||||
while ((c = getchar()) != EOF) {
|
||||
*p++ = c;
|
||||
if (c == '\n') {
|
||||
p = buf;
|
||||
while (*p != '\n') {
|
||||
if (*p == '-' || *p == '+') {
|
||||
symbol_map[x][y] = 1;
|
||||
p++;
|
||||
x++;
|
||||
} else if (sscanf(p, "%u", &curr) != 0) {
|
||||
num_length = sprintf(tmp, "%u", curr);
|
||||
tmp_pos = create_position(x, y, num_length, curr);
|
||||
numbers[num_numbers] = tmp_pos;
|
||||
num_numbers++;
|
||||
p += num_length;
|
||||
x += num_length;
|
||||
} else {
|
||||
if (*p != '.') {
|
||||
symbol_map[x][y] = 1;
|
||||
}
|
||||
if (*p == '*') {
|
||||
symbol_map[x][y] = 2;
|
||||
}
|
||||
p++;
|
||||
x++;
|
||||
}
|
||||
}
|
||||
map_x = x;
|
||||
x = 0;
|
||||
y++;
|
||||
memset(buf, 0, LINE_MAX_LENGTH);
|
||||
p = buf;
|
||||
}
|
||||
}
|
||||
|
||||
map_y = y;
|
||||
|
||||
// Part 1
|
||||
unsigned int part1 = 0;
|
||||
|
||||
for (int i = 0; i < num_numbers; i++) {
|
||||
if (has_adjacent_symbol(numbers[i], symbol_map)) {
|
||||
part1 += numbers[i]->value;
|
||||
}
|
||||
}
|
||||
|
||||
printf("%u\n", part1);
|
||||
|
||||
// Part 2
|
||||
unsigned int part2 = 0;
|
||||
|
||||
for (int i = 0; i < map_y; i++) {
|
||||
for (int j = 0; j < map_x; j++) {
|
||||
if (symbol_map[j][i] == 2) {
|
||||
part2 += gear_ratio(j, i, numbers, num_numbers);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
printf("%u\n", part2);
|
||||
|
||||
free(buf);
|
||||
for (int i = 0; i < num_numbers; i++) {
|
||||
free(numbers[i]);
|
||||
}
|
||||
free(numbers);
|
||||
}
|
||||
|
||||
struct num_position_t* create_position(int x, int y, int length, unsigned int value) {
|
||||
struct num_position_t *pos;
|
||||
pos = (struct num_position_t*)malloc(sizeof(struct num_position_t));
|
||||
pos->x = x;
|
||||
pos->y = y;
|
||||
pos->length = length;
|
||||
pos->value = value;
|
||||
return pos;
|
||||
}
|
||||
|
||||
int has_adjacent_symbol(struct num_position_t* number, int symbol_map[MAX_MAP_SIZE][MAX_MAP_SIZE]) {
|
||||
int x, y;
|
||||
for (int i = 0; i < number->length; i++) {
|
||||
for (int j = -1; j <= 1; j++) {
|
||||
for (int k = -1; k <= 1; k++) {
|
||||
x = number->x + i + j;
|
||||
y = number->y + k;
|
||||
if (x < 0 || y < 0) continue;
|
||||
if (symbol_map[x][y]) return 1;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
unsigned int gear_ratio(int x, int y, struct num_position_t** numbers, int num_numbers) {
|
||||
int gear_num = 0;
|
||||
unsigned int num_parts[2];
|
||||
for (int i = 0; i < num_numbers; i++) {
|
||||
for (int j = 0; j < numbers[i]->length; j++) {
|
||||
if (abs(numbers[i]->x + j - x) <= 1 && abs(numbers[i]->y - y) <= 1) {
|
||||
// Not a gear
|
||||
if (gear_num == 2) return 0;
|
||||
// Add gear
|
||||
num_parts[gear_num] = numbers[i]->value;
|
||||
gear_num++;
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if (gear_num == 2) {
|
||||
return num_parts[0] * num_parts[1];
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
140
day3/input.txt
Normal file
140
day3/input.txt
Normal file
@@ -0,0 +1,140 @@
|
||||
........936..672.........846.922........359...332......582..856........................579..93......674..740.....243.156....................
|
||||
...........%.........4=...*...*........*.......*......#....................806..481.........................*.......*.........900......$564.
|
||||
.............520........624.965....143..405.....960.............273...651...*....*.........554....139@.....38...*.........58..*...392.......
|
||||
................$....................*.........................*.....&......634.3..../.................-......310....*313.*.........*.......
|
||||
...196....544......541................775.216...+557..225/..463.......................517..........960.228........452.....593.......772.....
|
||||
.....*....*...654.*........638............*...........................163....................386#......................20......169..........
|
||||
.....566..20...$...132........*969......747........*971..342............=.245*.......................277.522............*..............+....
|
||||
.............+..............................205.716...........................855.............324......................871..752.........291.
|
||||
.........47..390.......128...%....528........%..........91*192.......=.....................=.#.............%..852*156......+................
|
||||
.....975..*.......=....*...322.......#............&63.............946...................462....939..520...268............#.....*....380.....
|
||||
.........55..=.....871..68.............................................491.......................*.....*............674.770.333.415...*.275.
|
||||
..............633...........@.....642.5........+.......739........632.....*.......992.74.615...858...998.............*..............761.*...
|
||||
....446......................180./..../........83...&.....*924....&........379...*......................................................118.
|
||||
...........488*240.......150......................958..........$.....&...........964...351...........+..633.........123....../603...........
|
||||
...................987....../........546-...674...............466.....602.............@...........956..#............./......................
|
||||
......503=....465.................91.........*..........................................583..............128..124..........$.....217........
|
||||
..............*...32$..53....&594.........648...827....*..994.......971...................*..........304...%....*.......387..80.............
|
||||
............756.......#..........................*..888...$............@....339.......+..868........*........851..............*.........128.
|
||||
...905-.........312..................729...356*.697.........736.....+.......+.......748.......797....41....................272..753.........
|
||||
.................*....&604............*.............%915.......*.529..889...................*.........................992.........*.....718.
|
||||
...........272....487..............+...961.892..............632........*.................502.118....141................@......546.669.......
|
||||
787..........*....................85............/..330...........-...374.............................*.........446...%.........*............
|
||||
....-...../...120....919&.....................339....*....*663...403........167...533.170.............698..587...*....279.......776.+.......
|
||||
.575.....34.*.................668...19..759.......804..730...../.............*...........*.....789...........*....803......666.......25.....
|
||||
............375...773*.............*.........................$.876...287......201........484......*.........196.............................
|
||||
565...866.............23..477...455....................794.996.........*.....................887.959...146...........496....790.............
|
||||
..............648...........+........325.738....156.....*.........534..941.....%536..31..../.%...........*............*.....*.......511.....
|
||||
..............*.................166.....*......*.....647..........*......................262...........887..210.3..860.....161....4....*420.
|
||||
......141.606...........193.111..*..........252......................935*689..................500...........*...*.................*.........
|
||||
..635....*........=........*.....959.....................@834.................-.....542..547....-..........770.8...........439..............
|
||||
.................896.........93......................244..........@......247..735..*.................................497.............%......
|
||||
...............................%........................*..........200....+.......342.613.245.@............$.........#....*.......176...21..
|
||||
......51......702.37.......798....325.....&974.....834.860.....+.........................*.....533..866....864.............269..............
|
||||
..141..*......................-...&............875*.............207...882*.........................*............309.739........%......../...
|
||||
.......394....144.....................................$...................835.3..........290.......489...........&.....*177.833....866$.153.
|
||||
.689.................719.314/..$......673.....5*557...443......+..#649.............575....*..634*...........................................
|
||||
....&...........794...*........614...*......................350.............411......*.104.......141........369...934...........997.........
|
||||
.......519......*...787..............739.....628...................................784.......$..........989*........*...987.......*....#....
|
||||
.........*...309.........209.............957*........50.....@995...765.......269.@........380..624.................643.....*....836...356...
|
||||
......886............234.+....................51*935..*...........*.....188.......73..............*696...14.....#...........................
|
||||
............203..948...&...............................957......804.736*......388....689.219*660........*.....218....................$..40..
|
||||
..............*.....*.....475.....930..........%................................*......*..............477.624................848...687......
|
||||
....57*.50.229....636....*.................804.164....590.........-....547..80..310....675.......=.@...........................*............
|
||||
........................398......&........*..............*.....748...........*................226..200................160......853..........
|
||||
......292........................889.......867.....365...............192+..530.........................@910....=..222*.............894......
|
||||
..427....#.../...959........................................322.....................735*304....742..........195..........$..............22..
|
||||
...........465..-.........52.$......168.......418.......+.........................................$..............&......563...649*26........
|
||||
....................464..../.969....*......-..*........150......724.....83..301...............527...............858.506.....................
|
||||
...935.........910....+...........116....427...347.............-........*.....=.......891.......*....847...750........@................531..
|
||||
....*.........$.........676...............................510............11.......647.*.................#.....%.683.............193...+.....
|
||||
....761.169...............=...524........&......152..........*...975.994.........*....122..........858*...........%.......776...........*...
|
||||
...........-..180/.850..............$.....524....-...........940.=......*......199........963..............#........836...*.....34...543.448
|
||||
482...947...................94&....541..............265..............477..890..............*....988.....343..........&...599....+...........
|
||||
.......*...532..81..73..417............992/...99&...#........................*.33@.149..305.........678.....31.........@.................417
|
||||
....304.....@.....*...#../....452.842.................519.....307.949.....268................=.........*....*...........259.................
|
||||
..................361............*.......346............*.+......*...........................288.......492..985.............727.683.........
|
||||
....530....438..........950..........*......*........787..316...............762.724.257..889.....................844.......*......=....@125.
|
||||
..............*...446...*......879..827......148......................*730.......@..........*...832...............*.......647.......48......
|
||||
....500.......994........41.......*.....#805...........*...........614...............*....940................291&.129.8............=........
|
||||
....*...#..........698..........581.................940.462.....@......443...82.784.593......../.#375..%148............*..#.................
|
||||
.....39.562...784............................................805...$......@...*..*..........844.....................776....363...667........
|
||||
................%...265.......337.....438...295.....................499......341.74..................271.405.......................%.155....
|
||||
.........97..........*......@....*252.*......*....+.........270.229.................394...879*247.....*...*.....146.....................*...
|
||||
........%.............226..258........996.944......793........*.../...................+..............321.578.....$..........838.....529.831.
|
||||
.................%109.........................................615....822.....................501.............616....293.....&........-......
|
||||
.......%....482...........................%717.236.......562...........*...........915...580....*............*.....+..........230...........
|
||||
.....303.......*128..86&......762.928.............$........*......861*.311........*....../....517..........471.544.....996.......*38...628..
|
||||
...........563............89.*......*.583...%.148.......$.987...................35..................996...........=....*...............*....
|
||||
......776.....+...........*......967...@..168...*.....772.........838*.....480..............................-........976..............530...
|
||||
................649*32...84.#...................315...................37............398.656...631..........340.985*..........522............
|
||||
............................922........................./.173....894................*.........$....................177.......#..............
|
||||
......................................................423....*....*.....816.........13.................=..............................251...
|
||||
..154...................878*......................568......723..329....&......928.................-71.123.378..100...................*......
|
||||
........*21..250............448.734.718.....&....*......................................599...............%....*.....700+.....*803..401.....
|
||||
.779.550........*.817............./..*....118....980..589.....235......=....539...........*...281*236..........591.........927..........*...
|
||||
...-.................*...............854.............*.................911.=............939........................616..*............770.50.
|
||||
.............82......399.......452..................184........643..........................*871..................*....370..................
|
||||
.185.405.....*...634............*......189.838.................*...............@623......252...........315.86.....568...........157.104.....
|
||||
...&......586.......*........957..........*.......841.........509.600........................896..565.....*...............+............*....
|
||||
..................633.628...........811..........*.....677.........-..580..751...183.........................540.81.......656..665..634.....
|
||||
......112.............*.....=........./.322...430.........*..........+.....*...............683............$.....*...........................
|
||||
830&...*..426........649..910...........*................717..359........831........=..157..%.............143......758................579...
|
||||
.....373....*..................215.......666....................*.#...........459..547...+.........773.........980*.........404...126.......
|
||||
205......636....................*...420.......440..........225.11.516...568....*......................*....474........620...*.....*.........
|
||||
..............250......685...209.....+...........*257.................../...407.......295..498....122.............970...@.392.412...........
|
||||
783..83+...........706....=.................330*............833.................*250....%..=..........%...........*............#....898.....
|
||||
...........$....................................398..35........*......646....759.....#.............527..........160.....254.................
|
||||
500........777...........112..428...663....957#..............524.....*..../........249..530*672............567......*......*759.....284*....
|
||||
....861....................*.*......*............*...277*832.....644.130..216.446............................*...683.955................950.
|
||||
....*........826..........68.535..192.........306..................#..................762%...%....#631..500.406..........763...137..........
|
||||
..65............-...499=..................546.....&.........$........../..........177........988.......@.............336...*..*.............
|
||||
.....362..................@...$..........-....610..65......64.........830..........-...........................452......+.604.542...........
|
||||
........*902.633*........873..63.....781...31...*.................258.....12...681..........18*........&...&............................848.
|
||||
..803............752.........................-.....672...................*.............................470..86.59.......%...................
|
||||
.......@..547..........$...184.......320..........+..........471......834...=...551..108.............................176.................82.
|
||||
..950.562............261...$.....754..+..............134.654*...............778..&......%..713.837.......................329........186.....
|
||||
............112..72...............*..........917......*.................415............................946....=....614.....*................
|
||||
..............*.$......850.....766.....308.....*....666................*......812.....293................*.624.......%..296.....612...333...
|
||||
..996......154...........................*......283.....*.555.%........................-.......552.714.563.......227..............-.........
|
||||
....*.682.................=.......281.217..............84.*....908.....@...=....522..............$.*.......630......*79..............556....
|
||||
..635...*............516...402............................333........114..496..*.......324..........522.....................................
|
||||
.........511....779...*............@............350.853.........................791...................................$.....821.....+.......
|
||||
.................*.....486........984......332.....*..............893..730*480...................756...................776...........155....
|
||||
......161......57..590....................@....398..................*....................477.....*......602....506............996...........
|
||||
.151.....*..=.......*......955.......916........#.....=..269.........423..........289......*..379...*..@.....................*..............
|
||||
...-....123..927.600...........-........*395........226./....676*755...........30..........58.....582.........671.118..43.367...943......478
|
||||
.....................725........74...............................................+...........................-......*..*................&...
|
||||
........378......563*.....*999............*...................497.349...26.....$............362.........&........723....20....717...317.....
|
||||
...*....................22.........../.575.552..........291......*..........600......152.../......./...169......................-.@....*977.
|
||||
886.250..........$.............383.603.............36*.../....%......................*.............253........215..........139....583.......
|
||||
................225............................................721...814..............829..................*.......613*544.*...=........901.
|
||||
..........741.......595.........785.............%677..50................=.................252......710....91...............912.180..........
|
||||
...........*...................*....808...956..........+.....812...............*381......*.....676.../..........599....................+....
|
||||
............134.184......759..81...*.........*.782........41*......=....125.216........679...../..........@........*.................567....
|
||||
.......165.........*......@................66...*.....*.........379.....................................&..626...241........................
|
||||
.........*.........232.........387.86...........635.47.806.857.........$537...............240........617..............806..941..........531.
|
||||
.......687...654.......735......*...$......................%.....357..............*884.......*571..........273.551......*.....*....576..*...
|
||||
............*................648...................716.304..........*...690....663.................*38...........*....365......911....@..424
|
||||
....67*156...250..828...................&222.......#...*......16....300.+..................-....-.9....813...982..443.......................
|
||||
.....................*......136..757..................65..314...*........................615.291.......&....*................972............
|
||||
................721..592...@.............................../...808.............665...176.............................200.....*..............
|
||||
..198..459+............................218........-772..............169...39..*........*........939..742......#....=......532...#..264......
|
||||
.....*...............$..........713...*............................*.....*...831....689...589*.......*.......91....75.........641...#.......
|
||||
..896..167*........372...138...........462...*227..$.....801......512.........................775.673.......................................
|
||||
...............47........*.......135...............725.....*...............743..........489*.............735..622.815.551...........519.....
|
||||
.......=........*......636.987...*...................................827........496*........48.121................*.....*........#.....*311.
|
||||
....525.......819.580.........#.369......119...............77.........*...............10*........*.%.....975.....961....888......304........
|
||||
........................96*..........................816............857......=...........376...859.522..=...................................
|
||||
629...419..259...#360.......44%.........190..=969...........=...539.....-913.429......................................119.....476...707.....
|
||||
...*.....*...*....................*906.*.....................84.....286...............$...=...127.200.465........324.............=.....*599.
|
||||
905.....762...262.....-597.....847......311......@654...837............*....455..37..439..147....*.....*...262...*.....787..778.............
|
||||
...........................25...........................=...........908....*.......*................827......%....567....-....#.427..819....
|
||||
..............................#.$....643=...............................886......243....../.....672..............................*....*.....
|
||||
...........185*....107.....226..965........$.................756........................808.221...-.../574...541&...+....871...326....349...
|
||||
......................*.....................841.....=...........*688........177................*....................166....*................
|
||||
.......189..744......308.......99*391..630/........463......................@...930..........543..........................519...............
|
||||
..984.%........-.741.......................................522.915+.....769......*................207....976.....158*.......................
|
||||
....*...............*...............&.331...787........48...........224..*......184........874.......=.....*........................537.....
|
||||
.....934....*339...829....495.....682...*.............*....+..........*..794..........-430...*....&........848..367....+............*....505
|
||||
.........175..........................381............270....198......911...................52......642...............45............445......
|
||||
1
day3/rust/.gitignore
vendored
Normal file
1
day3/rust/.gitignore
vendored
Normal file
@@ -0,0 +1 @@
|
||||
target
|
||||
7
day3/rust/Cargo.lock
generated
Normal file
7
day3/rust/Cargo.lock
generated
Normal file
@@ -0,0 +1,7 @@
|
||||
# This file is automatically @generated by Cargo.
|
||||
# It is not intended for manual editing.
|
||||
version = 3
|
||||
|
||||
[[package]]
|
||||
name = "rust"
|
||||
version = "0.1.0"
|
||||
8
day3/rust/Cargo.toml
Normal file
8
day3/rust/Cargo.toml
Normal file
@@ -0,0 +1,8 @@
|
||||
[package]
|
||||
name = "rust"
|
||||
version = "0.1.0"
|
||||
edition = "2021"
|
||||
|
||||
# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html
|
||||
|
||||
[dependencies]
|
||||
160
day3/rust/src/main.rs
Normal file
160
day3/rust/src/main.rs
Normal file
@@ -0,0 +1,160 @@
|
||||
struct Number {
|
||||
value: usize,
|
||||
}
|
||||
|
||||
enum Symbol {
|
||||
Asterisk,
|
||||
Other,
|
||||
}
|
||||
|
||||
enum Tile<'a> {
|
||||
Number(&'a Number),
|
||||
Symbol(Symbol),
|
||||
Period,
|
||||
}
|
||||
|
||||
fn main() {
|
||||
let stdin = std::io::stdin();
|
||||
|
||||
let mut map: Vec<Vec<Tile>> = Vec::new();
|
||||
|
||||
for line in stdin.lines() {
|
||||
let line = line.unwrap();
|
||||
|
||||
let mut num = Vec::new();
|
||||
let mut v = Vec::new();
|
||||
for char in line.chars() {
|
||||
if !char.is_digit(10) && num.len() > 0 {
|
||||
let s: String = num.iter().collect();
|
||||
|
||||
let number = Box::leak(Box::new(Number {
|
||||
value: s.parse().unwrap(),
|
||||
}));
|
||||
|
||||
for _ in 0..s.len() {
|
||||
v.push(Tile::Number(number));
|
||||
}
|
||||
|
||||
num.clear();
|
||||
}
|
||||
|
||||
if char == '.' {
|
||||
v.push(Tile::Period);
|
||||
} else if char == '*' {
|
||||
v.push(Tile::Symbol(Symbol::Asterisk));
|
||||
} else if char.is_digit(10) {
|
||||
num.push(char);
|
||||
} else {
|
||||
v.push(Tile::Symbol(Symbol::Other));
|
||||
}
|
||||
}
|
||||
|
||||
if num.len() > 0 {
|
||||
let s: String = num.iter().collect();
|
||||
|
||||
let number = Box::leak(Box::new(Number {
|
||||
value: s.parse().unwrap(),
|
||||
}));
|
||||
|
||||
for _ in 0..s.len() {
|
||||
v.push(Tile::Number(number));
|
||||
}
|
||||
}
|
||||
map.push(v);
|
||||
}
|
||||
|
||||
// Part 1
|
||||
let mut part1 = 0;
|
||||
|
||||
for (x, row) in map.iter().enumerate() {
|
||||
let mut already_added = false;
|
||||
for (y, tile) in row.iter().enumerate() {
|
||||
match tile {
|
||||
Tile::Number(number) => {
|
||||
if already_added {
|
||||
continue;
|
||||
};
|
||||
|
||||
for dx in -1i32..=1 {
|
||||
for dy in -1i32..=1 {
|
||||
let ix = x.wrapping_add(dx as usize);
|
||||
let iy = y.wrapping_add(dy as usize);
|
||||
if let Some(v) = map.get(ix) {
|
||||
if let Some(Tile::Symbol(_)) = v.get(iy) {
|
||||
already_added = true;
|
||||
part1 += number.value;
|
||||
}
|
||||
}
|
||||
if already_added {
|
||||
break;
|
||||
};
|
||||
}
|
||||
if already_added {
|
||||
break;
|
||||
};
|
||||
}
|
||||
}
|
||||
_ => {
|
||||
if already_added {
|
||||
already_added = false;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
println!("{}", part1);
|
||||
|
||||
// Part 2
|
||||
let mut part2 = 0;
|
||||
|
||||
for (x, row) in map.iter().enumerate() {
|
||||
for (y, tile) in row.iter().enumerate() {
|
||||
if let Tile::Symbol(Symbol::Asterisk) = tile {
|
||||
let mut gears = [None; 2];
|
||||
let mut gear_num = 0;
|
||||
let mut skip = false;
|
||||
|
||||
for dx in -1i32..=1 {
|
||||
for dy in -1i32..=1 {
|
||||
let ix = x.wrapping_add(dx as usize);
|
||||
let iy = y.wrapping_add(dy as usize);
|
||||
if let Some(v) = map.get(ix) {
|
||||
if let Some(Tile::Number(number)) = v.get(iy) {
|
||||
if let Some(gear) = gears[0] {
|
||||
if std::ptr::eq(gear, *number) {
|
||||
continue;
|
||||
}
|
||||
}
|
||||
if let Some(gear) = gears[1] {
|
||||
if std::ptr::eq(gear, *number) {
|
||||
continue;
|
||||
}
|
||||
}
|
||||
|
||||
if gear_num == 2 {
|
||||
skip = true;
|
||||
break;
|
||||
}
|
||||
|
||||
gears[gear_num] = Some(*number);
|
||||
gear_num += 1;
|
||||
}
|
||||
}
|
||||
}
|
||||
if skip {
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
if gear_num == 2 {
|
||||
unsafe {
|
||||
part2 += (*gears[0].unwrap()).value * (*gears[1].unwrap()).value;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
println!("{}", part2);
|
||||
}
|
||||
10
day3/sample.txt
Normal file
10
day3/sample.txt
Normal file
@@ -0,0 +1,10 @@
|
||||
467..114..
|
||||
...*......
|
||||
..35..633.
|
||||
......#...
|
||||
617*......
|
||||
.....+.58.
|
||||
..592.....
|
||||
......755.
|
||||
...$.*....
|
||||
.664.598..
|
||||
BIN
day4/c/day4
Executable file
BIN
day4/c/day4
Executable file
Binary file not shown.
88
day4/c/day4.c
Normal file
88
day4/c/day4.c
Normal file
@@ -0,0 +1,88 @@
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
#include <string.h>
|
||||
|
||||
#define LINE_MAX_LENGTH 256
|
||||
#define MAX_WINNING_NUMBERS 16
|
||||
#define MAX_SCRATCHED_NUMBERS 64
|
||||
#define MAX_FORESIGHT (MAX_WINNING_NUMBERS+1)
|
||||
#define NUM_0_CHARCODE 48
|
||||
#define NUM_9_CHARCODE NUM_0_CHARCODE + 9
|
||||
|
||||
int read_numbers(char *p, char endchar, int dest[]) {
|
||||
int count = 0;
|
||||
while (*p != endchar && *(p+1) != endchar) {
|
||||
// Advance till first digit
|
||||
while (*p < NUM_0_CHARCODE || *p > NUM_9_CHARCODE) p++;
|
||||
// Read number
|
||||
sscanf(p, "%i", &dest[count]);
|
||||
count++;
|
||||
// Advance till endchar or separator
|
||||
while (*p != ' ' && *p != endchar) p++;
|
||||
}
|
||||
|
||||
return count;
|
||||
}
|
||||
|
||||
int main() {
|
||||
char *p, *buf, c;
|
||||
int card_id;
|
||||
int part1 = 0;
|
||||
|
||||
buf = (char *)malloc(LINE_MAX_LENGTH);
|
||||
memset(buf, 0, LINE_MAX_LENGTH);
|
||||
p = buf;
|
||||
|
||||
int winning_numbers[MAX_WINNING_NUMBERS], winning_numbers_num = 0;
|
||||
int scratched_numbers[MAX_SCRATCHED_NUMBERS], scratched_numbers_num = 0;
|
||||
|
||||
int foresight[MAX_FORESIGHT], sum_scratchcards = 0;
|
||||
memset(foresight, 0, MAX_FORESIGHT * sizeof(foresight[0]));
|
||||
|
||||
while ((c = getchar()) != EOF) {
|
||||
*p++ = c;
|
||||
if (c == '\n') {
|
||||
p = buf;
|
||||
sscanf(p, "Card %i", &card_id);
|
||||
|
||||
int num_cards = 1 + foresight[0];
|
||||
sum_scratchcards += num_cards;
|
||||
|
||||
for (int i = 0; i < MAX_FORESIGHT-1; i++) {
|
||||
foresight[i] = foresight[i+1];
|
||||
}
|
||||
|
||||
// Advance till ':'
|
||||
while (*p++ != ':');
|
||||
|
||||
winning_numbers_num = read_numbers(p, '|', winning_numbers);
|
||||
|
||||
while (*p++ != '|');
|
||||
|
||||
scratched_numbers_num = read_numbers(p, '\n', scratched_numbers);
|
||||
|
||||
int points = 0;
|
||||
int scratchcards_won = 0;
|
||||
for (int i = 0; i < scratched_numbers_num; i++) {
|
||||
for (int j = 0; j < winning_numbers_num; j++) {
|
||||
if (scratched_numbers[i] == winning_numbers[j]) {
|
||||
points = points ? points * 2 : 1;
|
||||
scratchcards_won++;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
for (int i = 0; i < scratchcards_won; i++) {
|
||||
foresight[i] += num_cards;
|
||||
}
|
||||
part1 += points;
|
||||
|
||||
memset(buf, 0, LINE_MAX_LENGTH);
|
||||
p = buf;
|
||||
}
|
||||
}
|
||||
|
||||
free(buf);
|
||||
printf("%i\n", part1);
|
||||
printf("%i\n", sum_scratchcards);
|
||||
}
|
||||
190
day4/input.txt
Normal file
190
day4/input.txt
Normal file
@@ -0,0 +1,190 @@
|
||||
Card 1: 2 15 17 11 64 59 45 41 61 19 | 4 36 62 43 94 41 24 25 13 83 97 86 61 90 67 7 15 58 18 19 38 17 49 52 37
|
||||
Card 2: 41 62 67 93 88 12 78 51 95 49 | 55 63 89 78 45 11 62 50 81 9 32 82 15 36 74 54 4 58 5 56 44 83 90 49 34
|
||||
Card 3: 51 22 38 33 85 23 56 76 60 93 | 94 40 61 37 38 82 93 96 13 50 81 65 56 26 4 18 86 30 8 16 60 27 23 48 51
|
||||
Card 4: 51 6 90 10 97 65 19 17 24 3 | 93 82 10 13 17 3 90 74 14 7 77 38 70 97 72 60 6 79 65 94 24 19 51 45 28
|
||||
Card 5: 76 61 43 95 41 2 40 58 30 96 | 72 23 69 5 30 3 10 17 78 20 13 86 60 81 90 46 96 39 6 32 31 73 65 95 62
|
||||
Card 6: 32 70 49 99 27 26 75 96 91 4 | 15 74 28 2 17 82 55 96 88 11 95 77 12 38 91 3 56 44 7 32 19 94 85 27 97
|
||||
Card 7: 38 21 90 66 46 32 55 94 72 75 | 3 10 90 77 41 99 46 82 65 72 9 21 66 94 80 22 97 56 93 61 18 81 34 76 64
|
||||
Card 8: 32 36 87 79 4 17 1 77 16 63 | 9 63 23 25 91 82 35 74 28 72 6 52 56 12 39 99 57 46 15 76 85 2 75 77 96
|
||||
Card 9: 42 5 58 80 96 88 37 30 49 69 | 26 6 17 71 46 51 45 10 62 33 38 23 42 74 50 61 95 11 93 57 14 22 72 85 86
|
||||
Card 10: 10 74 58 71 57 35 34 96 77 18 | 14 27 22 18 70 42 56 94 76 74 85 73 61 34 88 45 39 64 35 87 90 58 91 75 54
|
||||
Card 11: 24 26 43 62 66 93 38 51 95 86 | 31 75 23 91 12 3 90 9 36 87 76 58 40 35 56 65 17 74 61 93 20 71 82 92 73
|
||||
Card 12: 2 25 63 37 64 81 20 15 28 88 | 67 26 12 6 58 37 69 93 83 52 81 25 19 30 80 54 73 21 86 20 8 57 47 32 60
|
||||
Card 13: 48 37 14 80 51 17 85 26 40 33 | 80 7 79 38 8 74 10 78 89 16 81 84 19 49 86 83 63 82 40 58 25 47 53 34 4
|
||||
Card 14: 93 27 7 80 63 89 50 96 3 15 | 6 19 40 46 51 29 9 86 39 77 4 54 38 41 67 69 1 56 5 35 30 17 71 2 43
|
||||
Card 15: 33 72 28 75 56 22 16 38 44 51 | 81 67 79 73 52 40 69 43 12 77 31 41 23 14 64 58 5 88 95 13 99 6 42 83 38
|
||||
Card 16: 36 82 59 39 57 26 61 45 60 65 | 66 51 24 1 4 78 17 16 74 95 34 47 75 6 67 44 48 14 10 89 46 2 31 18 68
|
||||
Card 17: 40 50 36 8 54 17 29 13 89 98 | 6 59 60 57 18 30 80 32 46 77 86 35 48 84 91 4 38 99 17 33 3 15 82 83 62
|
||||
Card 18: 81 11 66 67 19 65 39 64 20 9 | 25 14 60 2 50 97 43 18 36 24 89 74 94 71 51 45 5 34 52 31 90 6 48 40 55
|
||||
Card 19: 41 81 99 97 18 92 79 82 83 62 | 97 34 41 76 87 60 21 63 93 55 77 92 42 56 80 94 81 36 11 1 83 70 52 5 29
|
||||
Card 20: 50 94 73 61 56 88 35 48 54 21 | 89 35 83 42 45 12 61 18 68 52 13 25 88 54 6 74 21 57 50 56 34 73 48 94 46
|
||||
Card 21: 95 69 16 96 19 86 94 74 33 1 | 19 95 86 16 94 76 17 39 5 1 97 27 44 69 74 96 29 48 14 92 33 7 12 91 42
|
||||
Card 22: 17 78 32 62 96 43 68 23 97 52 | 97 28 87 26 23 14 78 39 92 56 31 3 32 52 13 43 80 62 17 69 68 5 96 25 75
|
||||
Card 23: 57 93 4 6 2 34 18 80 99 9 | 9 53 58 19 35 6 46 87 86 36 59 17 26 54 39 52 99 20 69 18 25 30 34 41 42
|
||||
Card 24: 72 43 5 36 81 31 77 76 58 48 | 75 48 31 88 33 38 37 69 40 25 4 93 35 23 76 36 64 44 6 65 59 15 43 17 28
|
||||
Card 25: 14 52 98 94 85 95 27 54 67 34 | 54 14 19 3 24 36 6 52 16 95 76 61 23 8 98 34 28 99 67 85 27 55 70 59 94
|
||||
Card 26: 33 15 53 51 14 47 12 83 6 48 | 25 15 51 33 12 53 60 49 98 47 30 89 78 83 88 85 6 7 38 92 48 93 74 14 9
|
||||
Card 27: 72 33 73 12 18 13 15 88 82 39 | 23 33 72 13 18 1 12 15 64 8 59 73 48 31 40 57 76 39 52 88 89 36 82 41 67
|
||||
Card 28: 42 32 84 56 53 69 5 15 8 63 | 88 32 91 44 62 37 69 72 98 29 8 82 21 5 56 15 6 42 58 61 89 35 96 84 59
|
||||
Card 29: 51 41 27 43 38 63 67 26 8 50 | 52 8 1 32 26 59 4 67 27 98 75 11 54 14 50 16 70 66 2 86 62 37 65 38 55
|
||||
Card 30: 79 88 87 54 17 18 16 58 57 1 | 54 17 68 89 10 29 97 16 72 57 2 38 12 65 98 11 1 33 64 40 79 63 70 88 18
|
||||
Card 31: 61 75 59 95 28 91 57 54 55 82 | 19 57 30 95 54 81 64 28 94 92 3 80 10 63 6 83 88 69 59 15 27 93 96 40 38
|
||||
Card 32: 67 44 87 82 49 2 85 79 35 77 | 65 21 63 44 4 52 28 89 11 87 37 97 76 71 64 96 69 79 93 13 33 5 7 58 35
|
||||
Card 33: 34 69 25 16 38 4 48 28 39 80 | 90 71 48 27 46 54 19 16 69 12 6 59 25 17 10 81 47 30 28 13 66 38 58 4 80
|
||||
Card 34: 65 48 49 80 28 9 22 57 47 95 | 28 59 79 2 4 89 64 98 14 90 18 22 92 52 3 37 95 87 74 54 43 26 51 42 88
|
||||
Card 35: 60 8 75 58 47 63 90 71 93 50 | 60 9 24 63 98 66 39 91 46 34 86 67 16 95 53 73 48 87 75 96 44 90 68 26 93
|
||||
Card 36: 31 61 33 38 70 46 2 81 73 58 | 49 67 79 3 20 64 96 62 81 82 54 57 70 30 43 56 71 86 6 19 48 93 58 15 27
|
||||
Card 37: 86 62 46 70 33 84 90 66 89 96 | 56 39 63 53 45 80 49 61 52 64 12 69 74 26 44 86 96 62 27 31 78 2 28 21 16
|
||||
Card 38: 95 40 44 15 99 76 85 20 38 11 | 57 22 23 29 69 90 48 51 66 24 11 32 33 25 92 94 70 88 78 39 28 60 77 55 31
|
||||
Card 39: 67 40 10 87 93 47 23 98 96 91 | 14 30 78 72 70 99 52 65 84 12 18 75 59 85 83 89 55 11 82 34 63 10 97 54 69
|
||||
Card 40: 95 51 94 2 36 99 98 46 87 82 | 1 40 18 73 50 82 66 14 65 85 83 45 89 58 79 55 84 80 90 72 22 5 38 44 69
|
||||
Card 41: 68 75 93 29 66 95 27 46 23 82 | 8 60 39 33 41 36 25 73 94 89 50 71 85 19 51 30 53 45 9 31 83 99 5 32 52
|
||||
Card 42: 73 48 37 23 32 19 72 52 58 91 | 35 19 55 9 23 79 62 87 72 58 95 68 20 38 5 48 60 37 73 46 91 12 74 52 32
|
||||
Card 43: 42 39 19 59 11 50 88 31 10 9 | 77 11 39 56 42 67 22 12 88 57 75 79 80 6 92 86 99 33 59 90 89 93 68 70 61
|
||||
Card 44: 86 12 3 41 71 82 6 48 97 93 | 49 75 31 45 41 83 10 86 8 91 9 70 97 69 52 77 51 36 34 14 81 28 2 40 64
|
||||
Card 45: 51 9 72 44 18 14 40 97 2 25 | 83 80 62 22 7 34 88 33 17 23 38 81 70 89 26 35 57 78 46 76 4 61 56 98 55
|
||||
Card 46: 22 59 61 94 67 87 21 18 12 69 | 50 22 60 21 67 26 59 94 28 33 30 12 16 69 4 27 95 18 61 53 56 47 85 88 87
|
||||
Card 47: 91 58 84 29 4 60 77 41 83 97 | 70 35 40 17 62 41 9 59 26 76 78 16 25 92 91 95 71 77 63 21 6 67 54 46 49
|
||||
Card 48: 90 56 13 75 73 2 8 62 21 88 | 38 88 76 75 8 2 82 77 56 73 28 18 59 21 65 90 23 94 5 13 15 79 26 1 36
|
||||
Card 49: 84 14 99 51 58 28 63 36 48 91 | 94 46 6 61 2 9 40 38 64 63 91 16 49 81 70 48 80 36 51 58 84 98 96 34 60
|
||||
Card 50: 79 98 99 11 7 34 38 52 74 27 | 21 57 11 19 89 94 72 52 81 62 92 79 32 77 28 74 84 86 80 69 83 38 98 3 34
|
||||
Card 51: 58 60 15 93 24 72 94 29 59 12 | 71 72 7 86 23 39 65 87 76 22 6 74 69 94 46 52 91 60 96 24 93 47 4 15 59
|
||||
Card 52: 6 92 21 7 9 55 17 33 23 16 | 28 69 86 94 34 21 95 51 22 41 99 87 46 1 49 36 90 76 35 30 64 5 44 93 58
|
||||
Card 53: 57 10 81 4 93 79 51 87 28 50 | 38 34 97 15 49 89 59 37 25 48 70 41 98 33 78 87 95 85 35 71 32 30 96 67 36
|
||||
Card 54: 25 41 26 14 99 98 71 83 31 54 | 68 17 28 80 79 10 31 99 54 83 27 14 25 32 26 85 42 76 33 49 8 24 67 71 41
|
||||
Card 55: 38 26 25 70 78 37 13 76 31 73 | 82 10 2 51 13 8 98 12 19 77 84 89 93 22 54 35 23 31 69 42 43 25 39 57 94
|
||||
Card 56: 31 25 88 98 23 3 2 58 99 67 | 46 27 75 97 84 53 9 47 64 49 23 92 15 74 44 78 58 56 83 30 31 7 5 2 94
|
||||
Card 57: 50 61 25 29 59 1 47 72 65 84 | 72 74 97 28 30 75 56 61 44 40 62 95 4 8 64 22 34 25 14 16 50 92 65 39 13
|
||||
Card 58: 73 65 94 47 90 35 95 12 81 78 | 86 87 24 11 1 81 96 33 12 18 74 41 9 22 5 44 48 82 68 67 88 94 20 59 90
|
||||
Card 59: 41 27 3 55 16 83 49 75 51 88 | 33 66 74 58 60 72 75 67 78 55 68 95 81 3 39 86 69 94 92 4 5 44 57 26 56
|
||||
Card 60: 33 93 56 90 16 46 65 78 13 6 | 55 41 70 6 63 69 90 82 22 17 66 2 53 79 49 25 10 34 47 54 43 58 59 81 68
|
||||
Card 61: 72 45 87 76 64 80 96 22 67 98 | 69 25 90 48 67 88 30 34 38 98 19 73 86 8 99 35 44 95 91 36 63 37 2 13 66
|
||||
Card 62: 96 68 19 52 97 83 60 67 20 35 | 21 96 30 58 10 7 40 25 92 33 15 69 61 34 6 81 87 75 41 16 51 27 8 4 86
|
||||
Card 63: 17 1 45 26 82 78 85 15 89 8 | 49 38 16 22 71 50 81 74 87 61 14 19 64 93 96 23 59 56 76 86 53 6 7 80 41
|
||||
Card 64: 3 17 22 94 37 39 67 73 27 4 | 8 27 22 5 28 53 47 52 94 25 29 54 1 59 98 16 78 9 65 91 61 74 73 60 37
|
||||
Card 65: 80 48 70 23 99 11 20 31 54 94 | 73 69 21 10 66 90 80 29 55 67 92 20 96 94 79 93 31 30 17 14 27 75 13 95 71
|
||||
Card 66: 14 79 31 27 89 95 69 63 12 67 | 36 85 67 24 87 72 89 26 17 31 27 55 10 32 14 63 71 79 13 12 81 69 28 95 30
|
||||
Card 67: 87 44 51 53 37 69 39 96 90 16 | 22 63 83 31 32 76 66 68 29 30 53 48 4 72 82 46 95 80 17 21 56 51 89 12 77
|
||||
Card 68: 39 27 17 15 50 65 38 94 84 42 | 42 84 17 50 52 47 67 93 13 35 7 26 23 95 39 81 94 15 78 27 43 21 38 55 86
|
||||
Card 69: 13 22 8 54 61 77 75 31 1 67 | 68 54 15 23 40 58 67 3 71 78 90 33 44 22 57 19 8 30 74 38 48 41 9 25 65
|
||||
Card 70: 10 43 33 21 31 6 94 46 82 83 | 48 62 6 19 67 72 46 81 75 5 54 8 56 92 37 76 96 71 32 36 26 14 30 79 9
|
||||
Card 71: 91 9 15 33 37 22 61 74 14 70 | 79 31 18 42 43 40 26 56 95 45 86 76 65 23 3 94 24 35 4 2 68 51 25 12 80
|
||||
Card 72: 30 79 24 55 42 8 13 90 68 73 | 37 61 34 94 51 30 3 10 26 19 50 42 40 31 80 86 66 27 83 90 73 79 99 14 76
|
||||
Card 73: 25 88 63 85 56 49 30 46 10 99 | 46 68 67 60 11 78 6 85 12 97 91 21 27 81 39 48 69 44 25 63 22 10 3 61 79
|
||||
Card 74: 21 3 32 71 98 69 44 78 34 11 | 83 56 29 18 34 9 63 92 53 22 61 45 41 38 82 27 49 5 32 99 69 17 55 66 96
|
||||
Card 75: 68 92 32 65 49 38 3 56 17 44 | 47 68 6 1 10 24 66 84 60 2 48 56 57 61 51 35 28 17 82 52 98 81 23 75 38
|
||||
Card 76: 30 57 5 8 10 95 45 85 54 3 | 53 2 54 34 23 12 48 16 37 92 85 27 83 8 21 44 81 26 49 67 36 25 52 47 68
|
||||
Card 77: 31 84 72 26 83 55 20 42 65 61 | 53 96 17 18 59 21 23 77 78 15 43 58 66 3 60 55 38 45 6 72 44 94 11 79 19
|
||||
Card 78: 62 77 52 72 13 24 31 60 29 26 | 74 51 46 67 97 14 71 70 55 94 6 16 65 85 66 80 60 27 32 39 73 61 34 91 69
|
||||
Card 79: 69 74 82 58 44 37 86 51 75 20 | 93 70 2 35 30 79 45 56 65 59 22 64 89 36 66 5 34 13 49 43 97 74 7 26 83
|
||||
Card 80: 84 16 89 49 81 1 79 44 93 25 | 2 35 29 8 87 21 22 57 9 73 67 82 54 45 71 72 59 5 4 97 70 60 91 7 92
|
||||
Card 81: 25 44 10 12 23 79 60 45 96 90 | 62 23 25 40 12 90 42 10 79 45 69 46 9 27 73 59 34 44 29 94 95 86 66 1 58
|
||||
Card 82: 42 43 37 18 40 64 75 76 99 3 | 67 42 11 18 91 99 14 90 3 23 73 82 76 40 37 44 28 64 96 16 74 75 55 61 15
|
||||
Card 83: 38 89 77 47 66 22 87 59 7 43 | 59 46 7 73 79 23 96 22 28 87 66 32 77 89 98 19 38 18 43 56 15 47 74 95 99
|
||||
Card 84: 86 13 97 81 46 12 88 34 92 52 | 88 69 8 2 76 63 95 27 46 31 81 48 75 92 60 33 36 22 34 13 57 30 21 42 98
|
||||
Card 85: 57 71 21 43 41 23 18 15 59 93 | 40 8 21 25 19 57 52 71 75 45 16 18 89 99 43 20 27 4 53 98 80 22 7 29 41
|
||||
Card 86: 84 43 50 94 92 31 48 8 6 91 | 92 53 6 94 25 41 74 54 62 43 95 79 16 31 8 89 84 30 50 91 58 47 17 96 46
|
||||
Card 87: 45 96 17 51 25 40 39 13 78 82 | 66 61 23 13 59 10 1 86 30 62 74 41 34 45 8 65 36 16 78 93 20 92 35 82 90
|
||||
Card 88: 29 89 14 85 93 19 56 36 99 15 | 91 14 94 89 96 19 85 71 23 46 21 75 92 7 6 33 60 8 72 81 99 36 29 56 22
|
||||
Card 89: 77 79 82 96 75 63 72 59 37 11 | 43 97 11 61 80 68 22 19 71 63 16 18 56 49 9 79 45 36 37 89 1 8 48 4 40
|
||||
Card 90: 2 81 33 10 60 57 38 99 95 65 | 3 98 33 80 32 65 45 96 99 61 25 73 74 37 91 6 2 79 38 34 97 89 36 11 5
|
||||
Card 91: 31 62 73 12 53 51 64 55 9 20 | 45 76 95 42 81 56 32 62 11 48 93 9 69 79 84 28 46 82 88 96 31 91 13 98 92
|
||||
Card 92: 64 5 81 2 59 24 40 74 84 58 | 93 43 67 70 53 20 91 18 49 4 14 52 74 19 79 85 61 86 82 57 38 44 34 9 83
|
||||
Card 93: 6 94 85 43 15 67 68 79 81 65 | 15 35 14 78 21 68 86 9 97 99 75 87 23 46 70 30 41 27 18 84 3 50 53 63 79
|
||||
Card 94: 61 34 62 94 50 23 69 98 78 60 | 43 9 90 28 49 36 19 97 56 75 62 15 79 70 40 78 24 94 48 88 45 91 66 4 34
|
||||
Card 95: 73 26 99 83 45 46 9 50 38 14 | 98 81 63 27 55 28 32 82 92 41 87 60 49 50 99 95 11 89 4 78 17 47 20 15 96
|
||||
Card 96: 52 80 3 67 69 57 16 34 40 77 | 70 35 97 2 71 25 1 15 54 26 19 5 83 20 4 99 56 38 51 87 53 47 30 13 96
|
||||
Card 97: 54 41 65 23 52 82 81 22 28 47 | 27 90 3 24 15 85 36 88 97 37 4 18 42 50 99 35 83 78 79 46 40 63 92 34 67
|
||||
Card 98: 47 56 85 60 12 1 35 88 30 86 | 75 83 15 97 66 74 55 62 9 58 19 82 51 54 61 68 47 7 17 10 39 44 20 96 34
|
||||
Card 99: 52 25 39 18 92 17 93 29 6 9 | 22 83 86 51 5 43 20 73 13 66 6 82 24 8 2 11 87 79 57 50 19 35 45 62 49
|
||||
Card 100: 27 91 93 24 17 47 80 13 51 8 | 59 78 63 74 81 26 98 64 97 79 6 77 54 83 9 86 69 31 12 10 5 56 34 33 60
|
||||
Card 101: 8 45 53 15 57 36 69 47 13 1 | 15 13 79 47 69 36 99 57 25 91 1 8 39 73 90 24 84 93 60 40 53 55 3 45 87
|
||||
Card 102: 45 76 11 54 1 15 24 60 20 29 | 25 32 88 5 66 40 16 58 24 70 79 36 29 53 54 86 60 15 78 57 27 92 99 33 30
|
||||
Card 103: 46 15 97 62 94 19 99 76 42 93 | 65 19 5 58 3 10 12 24 50 64 54 22 85 31 44 93 30 47 14 21 97 78 2 15 81
|
||||
Card 104: 61 83 16 66 81 55 52 36 76 95 | 28 51 36 20 11 6 27 33 92 57 94 96 45 9 15 2 63 72 58 44 5 81 43 1 66
|
||||
Card 105: 44 12 34 11 26 72 57 55 38 69 | 41 57 62 26 14 72 89 99 34 69 28 10 68 70 2 50 98 37 12 38 44 71 11 80 55
|
||||
Card 106: 43 33 65 67 24 17 58 16 94 9 | 51 54 71 14 95 18 42 45 73 97 24 25 92 49 29 83 38 10 30 61 22 79 43 60 65
|
||||
Card 107: 74 9 87 65 8 71 6 51 47 79 | 74 5 6 71 65 82 57 88 66 76 70 8 51 87 54 81 96 79 7 9 47 12 24 52 50
|
||||
Card 108: 32 87 49 10 41 34 68 79 33 23 | 16 67 63 69 60 37 8 2 47 78 5 9 34 61 10 42 36 95 68 24 75 77 85 56 18
|
||||
Card 109: 98 95 89 44 76 63 83 99 71 79 | 49 64 88 18 67 48 23 37 32 99 65 14 1 63 80 84 60 5 87 94 70 8 96 16 35
|
||||
Card 110: 73 30 38 99 23 57 68 39 20 45 | 74 9 1 8 35 42 23 24 83 66 76 90 30 56 82 15 6 49 88 45 96 62 43 27 16
|
||||
Card 111: 48 62 64 91 57 12 68 30 25 18 | 78 3 21 29 20 77 91 74 72 1 18 28 19 25 44 52 34 12 64 17 6 7 57 5 14
|
||||
Card 112: 62 10 63 18 34 55 72 86 12 45 | 82 7 27 95 76 64 11 31 42 38 75 15 69 29 79 20 17 8 16 39 60 24 87 81 9
|
||||
Card 113: 91 58 97 55 46 75 74 53 72 2 | 82 7 17 38 89 81 14 24 33 13 11 91 79 93 96 18 2 35 80 15 45 63 41 46 37
|
||||
Card 114: 76 22 44 83 99 59 21 67 12 17 | 78 68 63 53 16 29 31 90 70 18 69 9 40 38 32 8 27 85 67 26 62 56 97 35 94
|
||||
Card 115: 11 49 95 65 18 67 29 91 45 25 | 37 44 78 20 88 35 32 60 90 40 26 5 68 53 70 31 74 63 21 4 87 46 12 92 91
|
||||
Card 116: 50 25 19 90 91 8 80 44 9 38 | 40 47 45 53 99 1 74 65 49 67 16 29 81 70 78 89 42 80 97 76 66 21 24 95 83
|
||||
Card 117: 38 7 34 3 57 30 29 44 52 21 | 5 48 70 24 26 50 32 27 1 4 25 96 54 16 90 61 33 67 89 78 83 22 72 6 47
|
||||
Card 118: 35 25 23 73 66 57 86 21 27 8 | 9 98 50 78 75 99 83 10 70 97 49 85 14 73 46 29 16 5 60 82 15 45 62 37 3
|
||||
Card 119: 51 84 3 55 90 61 93 18 38 35 | 63 50 60 78 87 74 95 58 26 27 34 11 81 30 28 99 94 89 64 1 96 65 72 56 76
|
||||
Card 120: 17 74 98 56 54 31 10 26 60 45 | 20 90 98 46 31 15 89 10 94 26 35 69 79 60 58 11 74 77 50 30 64 56 9 45 12
|
||||
Card 121: 27 43 12 84 96 70 61 19 92 46 | 59 18 91 25 23 97 32 72 4 21 95 93 85 60 81 9 58 30 53 94 90 69 48 89 2
|
||||
Card 122: 88 85 3 82 19 98 72 38 87 93 | 60 3 31 93 51 81 82 23 69 14 72 21 95 45 76 59 86 53 85 73 19 56 61 39 35
|
||||
Card 123: 22 6 50 96 91 15 33 7 29 57 | 72 67 62 78 91 96 23 7 17 69 26 29 75 2 57 20 43 74 82 68 56 92 54 66 48
|
||||
Card 124: 73 15 66 38 69 4 83 45 70 95 | 19 71 6 5 15 17 95 1 34 3 68 70 42 75 12 46 38 8 83 39 2 16 74 79 36
|
||||
Card 125: 32 86 2 71 72 53 73 67 12 85 | 60 31 70 99 33 45 95 22 79 41 25 3 46 5 20 75 37 55 35 18 36 59 8 63 80
|
||||
Card 126: 44 96 40 68 25 34 13 72 2 80 | 47 18 77 23 63 80 17 73 3 79 21 15 11 58 54 96 95 62 51 41 75 44 40 24 97
|
||||
Card 127: 4 34 21 87 85 1 44 72 71 24 | 72 46 83 10 50 77 87 49 91 85 1 42 66 38 54 89 35 86 59 65 71 15 34 4 99
|
||||
Card 128: 24 86 90 74 48 83 88 13 2 38 | 8 16 10 92 76 44 1 59 34 37 80 52 27 70 66 26 22 43 6 84 30 21 60 77 74
|
||||
Card 129: 28 71 81 50 31 13 6 63 58 51 | 5 35 62 15 72 47 76 44 32 34 2 14 50 45 77 18 24 81 78 59 48 40 9 7 26
|
||||
Card 130: 19 68 83 40 64 99 55 45 17 9 | 22 77 99 80 90 13 88 44 57 26 85 81 15 56 30 54 18 95 6 83 51 55 94 93 73
|
||||
Card 131: 47 44 33 5 59 74 1 21 46 3 | 4 14 87 41 82 63 31 45 47 23 55 94 89 39 86 20 52 66 10 59 48 34 68 21 12
|
||||
Card 132: 78 15 99 9 40 5 34 75 3 79 | 70 30 80 23 95 66 85 7 43 27 12 83 22 44 21 10 31 14 26 45 68 57 49 94 53
|
||||
Card 133: 54 14 80 44 33 11 53 69 1 71 | 64 2 56 28 84 76 26 32 92 3 39 47 69 9 6 75 50 99 95 30 35 73 98 13 59
|
||||
Card 134: 58 85 26 9 2 94 59 23 57 52 | 21 39 80 34 50 27 45 76 16 75 54 92 8 66 53 32 17 74 83 13 1 93 99 88 46
|
||||
Card 135: 43 81 39 26 61 75 13 40 72 48 | 9 87 61 99 51 81 59 55 19 13 35 74 60 45 39 40 65 33 78 46 26 8 71 7 44
|
||||
Card 136: 76 86 15 32 6 81 29 16 22 92 | 88 73 92 50 75 79 82 61 86 41 30 69 18 76 45 15 67 16 29 81 93 65 32 14 6
|
||||
Card 137: 37 65 99 6 61 45 27 86 68 84 | 6 7 61 67 65 33 86 64 59 90 96 54 99 23 85 68 18 55 40 4 10 37 97 77 73
|
||||
Card 138: 39 80 50 4 53 73 48 54 12 60 | 63 50 72 33 17 11 24 18 54 58 68 7 30 75 22 85 87 40 19 44 69 90 97 43 36
|
||||
Card 139: 8 86 87 39 58 56 80 34 85 81 | 25 9 2 26 19 61 96 72 36 45 6 21 91 7 34 89 59 56 87 8 49 98 85 74 97
|
||||
Card 140: 19 21 14 84 81 4 62 24 71 77 | 96 14 77 71 38 24 45 51 40 81 5 19 99 57 48 65 72 4 60 62 41 79 87 49 2
|
||||
Card 141: 87 32 58 9 88 63 22 71 83 18 | 37 26 51 34 44 22 84 48 58 65 3 62 45 90 60 70 74 81 57 68 18 47 85 73 40
|
||||
Card 142: 17 56 69 87 23 26 25 32 49 47 | 65 83 15 63 73 30 93 85 45 27 84 14 58 76 38 33 8 94 61 74 37 36 52 41 78
|
||||
Card 143: 52 86 94 23 28 58 81 71 30 21 | 23 96 75 87 55 50 21 76 9 80 97 69 35 33 27 71 86 94 30 42 84 10 3 14 62
|
||||
Card 144: 80 8 67 32 42 49 76 93 41 90 | 21 59 34 80 71 37 28 33 9 68 95 31 26 47 73 94 41 13 48 27 96 7 85 17 62
|
||||
Card 145: 22 13 74 92 75 17 19 48 58 55 | 36 31 20 92 11 76 23 51 71 84 59 88 89 38 1 90 97 46 30 41 77 6 17 64 2
|
||||
Card 146: 51 81 54 87 95 28 30 44 88 85 | 96 1 35 64 45 97 54 84 4 86 40 49 15 28 19 75 10 2 68 60 66 59 12 18 63
|
||||
Card 147: 44 45 70 23 71 37 17 59 97 53 | 88 9 26 22 62 68 6 96 77 31 95 50 54 42 14 5 30 24 48 3 67 75 56 49 7
|
||||
Card 148: 38 54 1 75 6 24 70 82 74 94 | 23 34 92 5 14 83 45 88 81 21 43 78 87 56 63 36 48 4 51 60 42 25 18 2 35
|
||||
Card 149: 11 87 55 57 8 27 48 67 12 45 | 3 37 54 81 2 15 92 30 5 10 38 98 64 93 99 68 36 50 88 97 35 29 79 46 58
|
||||
Card 150: 65 89 66 91 37 3 49 19 29 17 | 24 34 69 99 15 58 56 28 90 7 73 75 72 66 77 49 8 17 21 74 84 67 19 29 54
|
||||
Card 151: 86 4 93 67 52 14 43 99 9 38 | 34 60 72 47 24 76 38 67 48 85 14 43 93 92 49 45 18 25 86 9 31 99 63 41 4
|
||||
Card 152: 79 39 53 12 11 17 27 51 92 5 | 12 79 51 75 92 2 56 39 81 67 17 5 53 55 72 48 60 11 18 27 98 77 6 66 86
|
||||
Card 153: 22 95 26 5 32 14 7 66 8 35 | 60 32 96 25 8 57 73 95 74 27 66 26 7 1 14 5 12 34 21 35 22 87 77 24 85
|
||||
Card 154: 79 4 94 63 9 96 21 86 59 46 | 52 76 55 94 57 74 46 15 38 83 32 4 9 73 62 43 36 98 89 18 96 45 79 25 35
|
||||
Card 155: 53 58 97 98 67 5 8 46 31 54 | 76 5 46 80 30 54 31 33 51 97 47 67 8 83 10 58 60 73 98 71 62 82 48 95 77
|
||||
Card 156: 3 1 23 18 71 21 8 79 84 2 | 59 8 18 87 29 14 46 99 61 90 66 21 68 62 2 86 31 88 23 74 38 10 73 7 84
|
||||
Card 157: 24 3 22 90 56 15 78 61 1 81 | 33 70 73 5 71 93 30 67 53 18 62 7 19 85 47 65 43 82 69 75 57 46 44 99 50
|
||||
Card 158: 2 8 21 71 24 82 47 53 11 25 | 27 25 35 20 3 53 73 96 38 7 65 89 16 78 97 85 74 18 56 49 32 88 59 42 33
|
||||
Card 159: 69 81 74 51 35 90 33 58 97 22 | 89 45 91 1 77 10 72 35 31 42 28 71 97 80 87 22 64 33 95 3 68 56 69 82 67
|
||||
Card 160: 99 34 53 3 6 48 93 1 42 13 | 50 35 79 89 26 5 91 10 57 63 30 72 64 17 37 40 90 88 78 18 25 95 67 58 14
|
||||
Card 161: 41 39 34 75 50 52 94 71 82 13 | 26 8 87 95 20 91 49 96 65 36 51 24 46 69 83 52 47 41 79 11 50 73 89 70 44
|
||||
Card 162: 48 87 68 57 81 52 49 60 28 15 | 92 11 94 54 45 39 7 84 93 67 42 64 26 90 6 79 4 3 23 96 41 37 97 24 50
|
||||
Card 163: 67 41 11 38 81 56 45 4 76 70 | 32 87 62 51 58 27 91 37 29 90 22 43 77 97 35 46 93 88 23 31 99 21 79 18 47
|
||||
Card 164: 2 79 35 21 96 29 22 10 69 99 | 47 91 17 60 20 31 37 81 53 84 16 77 4 46 75 26 78 93 32 76 52 8 27 59 10
|
||||
Card 165: 32 37 54 95 66 64 59 19 28 44 | 96 49 3 75 94 63 98 65 4 7 2 73 50 24 78 31 21 42 82 25 70 79 35 38 1
|
||||
Card 166: 24 61 72 44 27 38 81 59 69 89 | 85 29 98 3 73 63 25 1 16 96 57 8 78 92 82 20 79 94 71 62 2 49 97 93 99
|
||||
Card 167: 55 22 60 95 80 25 28 56 69 18 | 22 38 29 46 90 41 59 93 94 57 74 43 97 49 27 34 19 64 55 81 33 37 13 15 89
|
||||
Card 168: 90 51 39 37 67 12 65 14 6 4 | 64 70 6 37 25 26 4 48 43 91 28 90 27 41 87 74 14 39 56 51 9 67 12 65 34
|
||||
Card 169: 57 11 25 88 28 82 60 95 27 26 | 42 82 35 47 87 14 11 88 63 96 65 43 95 25 99 5 26 20 28 57 60 40 76 27 7
|
||||
Card 170: 31 34 19 29 1 55 20 61 10 94 | 48 77 3 87 91 37 38 57 75 53 12 60 76 45 4 68 13 73 35 7 30 20 6 14 69
|
||||
Card 171: 67 10 59 89 52 53 40 17 64 29 | 88 27 59 1 75 10 95 67 34 40 83 4 82 64 2 52 89 29 53 33 8 71 91 85 17
|
||||
Card 172: 87 63 66 32 37 96 3 29 88 90 | 96 18 87 17 14 69 58 65 52 31 1 44 37 60 5 32 41 90 7 49 29 66 35 77 82
|
||||
Card 173: 70 84 52 81 63 32 61 94 38 97 | 24 34 63 52 81 99 8 57 66 50 94 84 70 38 61 86 15 32 47 78 45 77 95 76 97
|
||||
Card 174: 4 74 29 30 24 87 91 92 5 2 | 55 86 5 70 12 94 96 89 58 29 14 62 4 99 48 81 91 45 27 54 31 22 68 43 76
|
||||
Card 175: 91 78 3 20 86 98 89 82 13 57 | 24 76 59 66 73 1 5 82 45 6 92 3 33 43 17 83 12 14 91 71 19 46 54 96 25
|
||||
Card 176: 12 55 93 3 43 81 28 59 72 76 | 4 90 55 84 69 74 46 45 65 17 26 71 70 21 29 23 61 99 92 44 40 41 51 8 57
|
||||
Card 177: 56 5 89 93 62 17 2 6 50 40 | 35 60 5 47 76 92 15 2 34 28 69 29 19 9 27 49 1 88 57 48 84 8 26 59 91
|
||||
Card 178: 1 93 34 57 67 58 84 37 42 91 | 42 69 41 34 91 28 75 70 1 93 4 49 66 6 37 38 32 89 46 44 62 81 9 22 73
|
||||
Card 179: 90 95 7 29 42 51 22 39 84 75 | 75 25 80 96 55 41 73 43 26 42 46 7 86 22 84 1 39 50 90 12 3 29 51 95 81
|
||||
Card 180: 72 76 4 68 9 41 16 44 61 13 | 63 92 39 68 5 13 11 65 50 25 76 55 71 29 82 31 53 59 2 99 74 16 1 90 41
|
||||
Card 181: 29 63 61 82 33 94 51 32 50 84 | 80 85 7 8 54 30 87 56 90 75 69 60 25 43 53 47 72 81 1 59 97 28 52 46 10
|
||||
Card 182: 98 45 44 32 19 6 51 49 64 84 | 64 20 90 6 4 54 19 80 51 72 69 99 29 44 45 46 84 65 43 53 74 23 42 66 49
|
||||
Card 183: 23 35 4 50 88 87 38 7 19 2 | 76 79 80 5 66 30 74 29 37 94 11 50 1 67 13 27 90 40 70 91 71 12 81 9 33
|
||||
Card 184: 55 74 2 73 75 22 32 71 67 27 | 92 19 9 24 74 73 8 67 30 18 14 71 77 45 85 72 15 69 13 27 94 63 98 40 93
|
||||
Card 185: 14 73 72 38 16 40 83 28 37 96 | 19 74 49 96 90 48 26 1 95 54 3 82 50 41 43 64 69 80 77 97 52 16 23 25 31
|
||||
Card 186: 24 91 35 21 16 71 94 95 25 53 | 60 5 17 58 82 35 45 80 28 16 13 53 68 97 86 8 52 61 65 1 27 67 91 43 3
|
||||
Card 187: 96 39 77 52 97 33 80 99 18 15 | 48 8 85 79 81 33 43 90 62 14 36 65 2 32 82 15 91 23 34 68 56 87 11 57 73
|
||||
Card 188: 8 35 86 95 94 65 26 11 96 31 | 2 98 50 33 59 93 28 49 87 29 79 8 23 6 54 16 82 96 83 61 27 60 53 62 30
|
||||
Card 189: 60 27 78 55 84 1 36 28 20 77 | 45 85 75 8 54 74 58 73 17 68 13 53 47 79 7 65 35 40 51 87 18 37 71 72 21
|
||||
Card 190: 41 31 39 33 54 42 71 47 59 24 | 21 96 85 12 81 83 64 87 93 77 92 38 25 52 20 88 65 10 29 16 95 98 22 37 15
|
||||
1
day4/rust/.gitignore
vendored
Normal file
1
day4/rust/.gitignore
vendored
Normal file
@@ -0,0 +1 @@
|
||||
target
|
||||
7
day4/rust/Cargo.lock
generated
Normal file
7
day4/rust/Cargo.lock
generated
Normal file
@@ -0,0 +1,7 @@
|
||||
# This file is automatically @generated by Cargo.
|
||||
# It is not intended for manual editing.
|
||||
version = 3
|
||||
|
||||
[[package]]
|
||||
name = "rust"
|
||||
version = "0.1.0"
|
||||
8
day4/rust/Cargo.toml
Normal file
8
day4/rust/Cargo.toml
Normal file
@@ -0,0 +1,8 @@
|
||||
[package]
|
||||
name = "rust"
|
||||
version = "0.1.0"
|
||||
edition = "2021"
|
||||
|
||||
# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html
|
||||
|
||||
[dependencies]
|
||||
84
day4/rust/src/main.rs
Normal file
84
day4/rust/src/main.rs
Normal file
@@ -0,0 +1,84 @@
|
||||
use std::collections::VecDeque;
|
||||
|
||||
struct Card {
|
||||
_id: usize,
|
||||
winning_numbers: Vec<usize>,
|
||||
scratched_numbers: Vec<usize>,
|
||||
}
|
||||
|
||||
fn main() {
|
||||
let stdin = std::io::stdin();
|
||||
|
||||
let mut cards = Vec::new();
|
||||
|
||||
for line in stdin.lines() {
|
||||
let line = line.unwrap();
|
||||
|
||||
let (card_id_str, numbers) = line.split_once(':').unwrap();
|
||||
|
||||
let card_id = card_id_str
|
||||
.split_once(' ')
|
||||
.unwrap()
|
||||
.1
|
||||
.trim()
|
||||
.parse()
|
||||
.unwrap();
|
||||
|
||||
let (winning_numbers_str, scratched_numbers_str) = numbers.split_once('|').unwrap();
|
||||
|
||||
let winning_numbers = winning_numbers_str
|
||||
.split(' ')
|
||||
.filter(|e| e.len() > 0)
|
||||
.map(|e| e.parse().unwrap())
|
||||
.collect();
|
||||
|
||||
let scratched_numbers = scratched_numbers_str
|
||||
.split(' ')
|
||||
.filter(|e| e.len() > 0)
|
||||
.map(|e| e.parse().unwrap())
|
||||
.collect();
|
||||
|
||||
cards.push(Card {
|
||||
_id: card_id,
|
||||
winning_numbers,
|
||||
scratched_numbers,
|
||||
});
|
||||
}
|
||||
|
||||
let mut part1 = 0;
|
||||
let mut part2 = 0;
|
||||
|
||||
let mut foresight = VecDeque::new();
|
||||
|
||||
for card in &cards {
|
||||
let mut score = 0;
|
||||
let mut win_num = 0;
|
||||
|
||||
let card_num = foresight.pop_front().unwrap_or(0) + 1;
|
||||
part2 += card_num;
|
||||
|
||||
for scratched_number in &card.scratched_numbers {
|
||||
if card.winning_numbers.contains(&scratched_number) {
|
||||
win_num += 1;
|
||||
if score == 0 {
|
||||
score = 1;
|
||||
} else {
|
||||
score *= 2;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
for i in 0..win_num {
|
||||
if let Some(n) = foresight.get(i) {
|
||||
foresight[i] = n + card_num;
|
||||
} else {
|
||||
foresight.push_back(card_num);
|
||||
}
|
||||
}
|
||||
|
||||
part1 += score;
|
||||
}
|
||||
|
||||
println!("{}", part1);
|
||||
println!("{}", part2);
|
||||
}
|
||||
6
day4/sample.txt
Normal file
6
day4/sample.txt
Normal file
@@ -0,0 +1,6 @@
|
||||
Card 1: 41 48 83 86 17 | 83 86 6 31 17 9 48 53
|
||||
Card 2: 13 32 20 16 61 | 61 30 68 82 17 32 24 19
|
||||
Card 3: 1 21 53 59 44 | 69 82 63 72 16 21 14 1
|
||||
Card 4: 41 92 73 84 69 | 59 84 76 51 58 5 54 83
|
||||
Card 5: 87 83 26 28 32 | 88 30 70 12 93 22 82 36
|
||||
Card 6: 31 18 13 56 72 | 74 77 10 23 35 67 36 11
|
||||
BIN
day5/c/day5
Executable file
BIN
day5/c/day5
Executable file
Binary file not shown.
196
day5/c/day5.c
Normal file
196
day5/c/day5.c
Normal file
@@ -0,0 +1,196 @@
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
#include <string.h>
|
||||
#include <limits.h>
|
||||
#include <omp.h>
|
||||
|
||||
#define LINE_MAX_LENGTH 512
|
||||
#define MAX_RANGE_PER_MAPPING 64
|
||||
#define MAX_MAPPINGS 64
|
||||
#define MAX_SEEDS 128
|
||||
#define NUM_0_CHARCODE 48
|
||||
#define NUM_9_CHARCODE NUM_0_CHARCODE + 9
|
||||
|
||||
const char* resources[] = {
|
||||
"seed",
|
||||
"soil",
|
||||
"fertilizer",
|
||||
"water",
|
||||
"light",
|
||||
"temperature",
|
||||
"humidity",
|
||||
"location"
|
||||
};
|
||||
|
||||
#define RESOURCES_LEN (sizeof(resources) / sizeof(resources[0]))
|
||||
|
||||
struct mapping {
|
||||
unsigned long source;
|
||||
unsigned long destination;
|
||||
unsigned long mappings[MAX_RANGE_PER_MAPPING][3];
|
||||
int mapping_num;
|
||||
};
|
||||
|
||||
struct mapping* create_mapping(unsigned long src, unsigned long dst);
|
||||
|
||||
int main() {
|
||||
char *p, *buf, c;
|
||||
int firstline = 1, seed_num = 0;
|
||||
unsigned long seeds[MAX_SEEDS];
|
||||
|
||||
struct mapping **mappings;
|
||||
int mappings_num = 0;
|
||||
|
||||
mappings = (struct mapping**)malloc(MAX_MAPPINGS * sizeof(struct mapping*));
|
||||
|
||||
buf = (char *)malloc(LINE_MAX_LENGTH);
|
||||
memset(buf, 0, LINE_MAX_LENGTH);
|
||||
p = buf;
|
||||
|
||||
int src = 0, dst = 0;
|
||||
struct mapping *curr;
|
||||
|
||||
while ((c = getchar()) != EOF) {
|
||||
*p++ = c;
|
||||
if (c == '\n') {
|
||||
if (firstline) {
|
||||
if (buf[0] == '\n') {
|
||||
firstline = 0;
|
||||
memset(buf, 0, LINE_MAX_LENGTH);
|
||||
p = buf;
|
||||
continue;
|
||||
}
|
||||
|
||||
p = buf;
|
||||
while (*p < NUM_0_CHARCODE || *p > NUM_9_CHARCODE) p++;
|
||||
while (*p != '\0') {
|
||||
sscanf(p, "%lu", &seeds[seed_num]);
|
||||
seed_num++;
|
||||
|
||||
while (*p != ' ' && *p != '\n') p++;
|
||||
p++;
|
||||
}
|
||||
memset(buf, 0, LINE_MAX_LENGTH);
|
||||
p = buf;
|
||||
continue;
|
||||
}
|
||||
|
||||
if (src == dst) {
|
||||
char tmp1[64], tmp2[64];
|
||||
memset(tmp1, 0 , 64);
|
||||
memset(tmp2, 0 , 64);
|
||||
sscanf(buf, "%[^-]-to-%s map", tmp1, tmp2);
|
||||
|
||||
for (unsigned long i = 0; i < RESOURCES_LEN; i++) {
|
||||
if (strcmp(tmp1, resources[i]) == 0) {
|
||||
src = i;
|
||||
}
|
||||
if (strcmp(tmp2, resources[i]) == 0) {
|
||||
dst = i;
|
||||
}
|
||||
}
|
||||
curr = create_mapping(src, dst);
|
||||
} else if (buf[0] == '\n') {
|
||||
mappings[mappings_num] = curr;
|
||||
mappings_num++;
|
||||
src = dst = 0;
|
||||
} else {
|
||||
unsigned long src_start, dst_start, range;
|
||||
sscanf(buf, "%lu %lu %lu", &dst_start, &src_start, &range);
|
||||
curr->mappings[curr->mapping_num][0] = dst_start;
|
||||
curr->mappings[curr->mapping_num][1] = src_start;
|
||||
curr->mappings[curr->mapping_num][2] = range;
|
||||
curr->mapping_num++;
|
||||
}
|
||||
|
||||
memset(buf, 0, LINE_MAX_LENGTH);
|
||||
p = buf;
|
||||
}
|
||||
}
|
||||
mappings[mappings_num] = curr;
|
||||
mappings_num++;
|
||||
|
||||
// Part 1
|
||||
|
||||
unsigned long part1 = ULONG_MAX;
|
||||
int location_idx = 7;
|
||||
|
||||
for (int i = 0; i < seed_num; i++) {
|
||||
int cur_resource = 0;
|
||||
unsigned long cur_value = seeds[i];
|
||||
while (cur_resource != location_idx) {
|
||||
for (int j = 0; j < mappings_num; j++) {
|
||||
if (cur_resource != mappings[j]->source) {
|
||||
continue;
|
||||
}
|
||||
|
||||
for (int k = 0; k < mappings[j]->mapping_num; k++) {
|
||||
if (cur_value >= mappings[j]->mappings[k][1] && cur_value < mappings[j]->mappings[k][1] + mappings[j]->mappings[k][2]) {
|
||||
cur_value = mappings[j]->mappings[k][0] + (cur_value - mappings[j]->mappings[k][1]);
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
cur_resource = mappings[j]->destination;
|
||||
}
|
||||
}
|
||||
|
||||
if (part1 > cur_value) {
|
||||
part1 = cur_value;
|
||||
}
|
||||
}
|
||||
|
||||
printf("%lu\n", part1);
|
||||
|
||||
// Part 2
|
||||
|
||||
unsigned long part2 = ULONG_MAX;
|
||||
|
||||
// I know it could be done more efficiently than checking every single number but it only runs
|
||||
// for about an hour an a single core so if I use all 12 threads in my machine it only takes 5 mins
|
||||
for (int i = 0; i < seed_num; i+=2) {
|
||||
#pragma omp parallel for
|
||||
for (unsigned long s = seeds[i]; s < seeds[i] + seeds[i+1]; s++) {
|
||||
int cur_resource = 0;
|
||||
unsigned long cur_value = s;
|
||||
while (cur_resource != location_idx) {
|
||||
for (int j = 0; j < mappings_num; j++) {
|
||||
if (cur_resource != mappings[j]->source) {
|
||||
continue;
|
||||
}
|
||||
|
||||
for (int k = 0; k < mappings[j]->mapping_num; k++) {
|
||||
if (cur_value >= mappings[j]->mappings[k][1] && cur_value < mappings[j]->mappings[k][1] + mappings[j]->mappings[k][2]) {
|
||||
cur_value = mappings[j]->mappings[k][0] + (cur_value - mappings[j]->mappings[k][1]);
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
cur_resource = mappings[j]->destination;
|
||||
}
|
||||
}
|
||||
|
||||
#pragma omp critical
|
||||
if (part2 > cur_value) {
|
||||
part2 = cur_value;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
printf("%lu\n", part2);
|
||||
|
||||
free(buf);
|
||||
for (int i = 0; i < mappings_num; i++) {
|
||||
free(mappings[i]);
|
||||
}
|
||||
free(mappings);
|
||||
}
|
||||
|
||||
struct mapping* create_mapping(unsigned long src, unsigned long dst) {
|
||||
struct mapping *mapping;
|
||||
mapping = (struct mapping*)malloc(sizeof(struct mapping));
|
||||
memset(mapping, 0, sizeof(struct mapping));
|
||||
mapping->source = src;
|
||||
mapping->destination = dst;
|
||||
return mapping;
|
||||
}
|
||||
197
day5/input.txt
Normal file
197
day5/input.txt
Normal file
@@ -0,0 +1,197 @@
|
||||
seeds: 3127166940 109160474 3265086325 86449584 1581539098 205205726 3646327835 184743451 2671979893 17148151 305618297 40401857 2462071712 203075200 358806266 131147346 1802185716 538526744 635790399 705979250
|
||||
|
||||
seed-to-soil map:
|
||||
931304316 1786548802 232453384
|
||||
3500539319 2322065235 6421609
|
||||
496396007 147739714 266329192
|
||||
3169724489 768672891 39526579
|
||||
3689153715 1361862036 346985
|
||||
1936948751 3328259881 542896984
|
||||
3209251068 3154345676 173914205
|
||||
1163757700 2814318523 24125066
|
||||
2484210664 1362209021 231487475
|
||||
3991904247 2133571422 188493813
|
||||
1187882766 4045525873 83717994
|
||||
861951350 3084992710 69352966
|
||||
2715698139 2838443589 43714032
|
||||
3830303258 4025104215 20421658
|
||||
768672891 1268583577 93278459
|
||||
4180398060 2019002186 114569236
|
||||
3689500700 1593696496 10659519
|
||||
1271600760 808199470 460384107
|
||||
166497091 526585653 102729094
|
||||
3700160219 3894961176 130143039
|
||||
2966889400 2882157621 202835089
|
||||
147739714 414068906 18757377
|
||||
3850724916 4133608796 141179331
|
||||
2759412171 2328486844 183672918
|
||||
2479845735 4129243867 4364929
|
||||
3480360150 4274788127 20179169
|
||||
402636637 432826283 93759370
|
||||
3383165273 2717123646 97194877
|
||||
3506960928 1604356015 182192787
|
||||
269226185 629314747 133410452
|
||||
2943085089 3871156865 23804311
|
||||
1731984867 2512159762 204963884
|
||||
|
||||
soil-to-fertilizer map:
|
||||
3368312743 826425240 243745914
|
||||
1045038113 3682756471 174490549
|
||||
3931158487 1530223690 363808809
|
||||
1219528662 2460222182 131099318
|
||||
3020480207 1894032499 63879875
|
||||
121779694 248970341 36319877
|
||||
1993634034 2662348686 86667553
|
||||
3612058657 1323325837 196530127
|
||||
1531175223 2604354699 57993987
|
||||
158099571 121779694 127190647
|
||||
1867147432 3317666386 126486602
|
||||
2080301587 2768963716 548702670
|
||||
1402482267 1070171154 21180243
|
||||
2959841028 4051272297 60639179
|
||||
834756529 1966243663 128160296
|
||||
3911211010 2749016239 19947477
|
||||
962916825 3857247020 82121288
|
||||
2629004257 3444152988 238603483
|
||||
826425240 1957912374 8331289
|
||||
1350627980 3939368308 51854287
|
||||
1589169210 4214533702 80433594
|
||||
2867607740 2094403959 92233288
|
||||
1669602804 1125781209 197544628
|
||||
3084360082 1519855964 10367726
|
||||
1483712212 1091351397 34429812
|
||||
3094727808 2186637247 273584935
|
||||
1423662510 3991222595 60049702
|
||||
3808588784 4111911476 102622226
|
||||
1518142024 2591321500 13033199
|
||||
|
||||
fertilizer-to-water map:
|
||||
206818393 1973789958 18543481
|
||||
2641351404 1992333439 41420268
|
||||
58400970 2574944960 107826712
|
||||
3710426911 4065366707 42793360
|
||||
4217161704 4274048011 20919285
|
||||
1926695368 705931711 328031436
|
||||
1449580741 1210970895 50549447
|
||||
907984567 1421828853 15115545
|
||||
769748018 1108192216 102778679
|
||||
451427938 35457870 38201654
|
||||
2254726804 2033892789 137829519
|
||||
923239194 1513967644 270588891
|
||||
3753220271 4108160067 165887944
|
||||
499804857 310274559 109862756
|
||||
3061525238 3535532059 426476055
|
||||
1193828085 73659524 196024324
|
||||
872526697 0 35457870
|
||||
1766386857 1261520342 160308511
|
||||
4057593930 3283950856 159567774
|
||||
1389852409 646203379 59728332
|
||||
3919108215 3962008114 103358593
|
||||
1577153434 1784556535 189233423
|
||||
4022466808 3443518630 35127122
|
||||
489629592 1098016951 10175265
|
||||
923100112 2033753707 139082
|
||||
2392556323 2390203683 158894869
|
||||
1500130188 1436944398 77023246
|
||||
2577297600 1033963147 64053804
|
||||
609667613 2171722308 160080405
|
||||
3488001293 3061525238 222425618
|
||||
2551451192 2549098552 25846408
|
||||
4238080989 3478645752 56886307
|
||||
166227682 269683848 40590711
|
||||
0 2331802713 58400970
|
||||
225361874 420137315 226066064
|
||||
|
||||
water-to-light map:
|
||||
1833244152 0 764535859
|
||||
212138399 2132863085 224047237
|
||||
445686952 1600446740 163005122
|
||||
3322180377 2914685303 488586806
|
||||
2739726430 3712513349 582453947
|
||||
3946546331 3589340640 8839399
|
||||
1441711040 799272484 245821386
|
||||
1038755613 1763451862 6623730
|
||||
608692074 1587251997 13194743
|
||||
701103180 2356910322 39153476
|
||||
1687532426 1045093870 145711726
|
||||
2597780011 764535859 34736625
|
||||
740256656 1490869662 54307168
|
||||
0 1920724686 212138399
|
||||
2632516636 1545176830 9229765
|
||||
668257778 1554406595 32845402
|
||||
3955385730 2739726430 39179725
|
||||
4180633986 3598180039 114333310
|
||||
3810767183 2778906155 135779148
|
||||
1291061946 1770075592 150649094
|
||||
436185636 1481368346 9501316
|
||||
1045379343 2396063798 245682603
|
||||
794563824 1237176557 244191789
|
||||
621886817 1190805596 46370961
|
||||
3994565455 3403272109 186068531
|
||||
|
||||
light-to-temperature map:
|
||||
432141642 1268486741 19474646
|
||||
3617581823 3276436954 357008111
|
||||
3505110084 3786131308 49942802
|
||||
0 1287961387 432141642
|
||||
3096011130 1808659179 409098954
|
||||
1347993824 2675880000 161612192
|
||||
3019335150 3199760974 76675980
|
||||
3555052886 3137232037 62528937
|
||||
2778092757 1720103029 88556150
|
||||
451616288 2217758133 458121867
|
||||
1509606016 0 1268486741
|
||||
909738155 3836074110 138515824
|
||||
1048253979 2837492192 299739845
|
||||
2866648907 3633445065 152686243
|
||||
|
||||
temperature-to-humidity map:
|
||||
646729740 1519504972 559297346
|
||||
1894539176 2990410634 44298872
|
||||
232257988 972432123 414471752
|
||||
2277879451 278205785 108711195
|
||||
1775790220 132298732 118748956
|
||||
3371687162 2663455233 326955401
|
||||
1612056920 272509895 5695890
|
||||
1208383109 3703499740 147415518
|
||||
4070380190 4053129082 69974785
|
||||
4155541210 3305585510 139426086
|
||||
81956384 386916980 150301604
|
||||
3987543096 896459472 75972651
|
||||
2148980475 1386903875 128898976
|
||||
1617752810 3445011596 154599732
|
||||
4063515747 2078802318 6864443
|
||||
2392568787 3599611328 101532389
|
||||
2386590646 4123103867 5978141
|
||||
2494101176 2122546980 187027686
|
||||
2681128862 2085666761 36880219
|
||||
4140354975 2648268998 15186235
|
||||
1772352542 3051742077 3437678
|
||||
1355798627 3850915258 202213824
|
||||
3720104770 3055179755 250405755
|
||||
3032992830 2309574666 338694332
|
||||
1206027086 3701143717 2356023
|
||||
1938838048 537218584 44257139
|
||||
1558012451 81956384 50342348
|
||||
3970510525 3034709506 17032571
|
||||
1608354799 1515802851 3702121
|
||||
1983095187 4129082008 165885288
|
||||
3698642563 251047688 21462207
|
||||
2718009081 581475723 314983749
|
||||
|
||||
humidity-to-location map:
|
||||
971626884 4275486551 19480745
|
||||
1218249913 2090555906 502249162
|
||||
2914848039 2902831882 224865747
|
||||
3341591733 2819947352 82884530
|
||||
991107629 2592805068 227142284
|
||||
3424476263 606585628 95279547
|
||||
4279176998 2064757318 10971709
|
||||
3139713786 4068790015 201877947
|
||||
606585628 701865175 365041256
|
||||
3534582689 3291885426 744594309
|
||||
1916997152 1066906431 997850887
|
||||
1752809355 3127697629 164187797
|
||||
1720499075 4036479735 32310280
|
||||
4290148707 4270667962 4818589
|
||||
3519755810 2075729027 14826879
|
||||
1
day5/rust/.gitignore
vendored
Normal file
1
day5/rust/.gitignore
vendored
Normal file
@@ -0,0 +1 @@
|
||||
target
|
||||
7
day5/rust/Cargo.lock
generated
Normal file
7
day5/rust/Cargo.lock
generated
Normal file
@@ -0,0 +1,7 @@
|
||||
# This file is automatically @generated by Cargo.
|
||||
# It is not intended for manual editing.
|
||||
version = 3
|
||||
|
||||
[[package]]
|
||||
name = "rust"
|
||||
version = "0.1.0"
|
||||
8
day5/rust/Cargo.toml
Normal file
8
day5/rust/Cargo.toml
Normal file
@@ -0,0 +1,8 @@
|
||||
[package]
|
||||
name = "rust"
|
||||
version = "0.1.0"
|
||||
edition = "2021"
|
||||
|
||||
# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html
|
||||
|
||||
[dependencies]
|
||||
Some files were not shown because too many files have changed in this diff Show More
Reference in New Issue
Block a user