day 18 part 2 (before cleaning)
This commit is contained in:
@@ -162,8 +162,6 @@ The magnitude of this final sum is 4140.
|
|||||||
Add up all of the snailfish numbers from the homework assignment in the order they appear. What is the magnitude of the final sum?
|
Add up all of the snailfish numbers from the homework assignment in the order they appear. What is the magnitude of the final sum?
|
||||||
|
|
||||||
Your puzzle answer was 3987.
|
Your puzzle answer was 3987.
|
||||||
|
|
||||||
The first half of this puzzle is complete! It provides one gold star: *
|
|
||||||
--- Part Two ---
|
--- Part Two ---
|
||||||
|
|
||||||
You notice a second question on the back of the homework assignment:
|
You notice a second question on the back of the homework assignment:
|
||||||
@@ -188,3 +186,9 @@ Again considering the last example homework assignment above:
|
|||||||
The largest magnitude of the sum of any two snailfish numbers in this list is 3993. This is the magnitude of [[2,[[7,7],7]],[[5,8],[[9,3],[0,2]]]] + [[[0,[5,8]],[[1,7],[9,6]]],[[4,[1,2]],[[1,4],2]]], which reduces to [[[[7,8],[6,6]],[[6,0],[7,7]]],[[[7,8],[8,8]],[[7,9],[0,6]]]].
|
The largest magnitude of the sum of any two snailfish numbers in this list is 3993. This is the magnitude of [[2,[[7,7],7]],[[5,8],[[9,3],[0,2]]]] + [[[0,[5,8]],[[1,7],[9,6]]],[[4,[1,2]],[[1,4],2]]], which reduces to [[[[7,8],[6,6]],[[6,0],[7,7]]],[[[7,8],[8,8]],[[7,9],[0,6]]]].
|
||||||
|
|
||||||
What is the largest magnitude of any sum of two different snailfish numbers from the homework assignment?
|
What is the largest magnitude of any sum of two different snailfish numbers from the homework assignment?
|
||||||
|
|
||||||
|
Your puzzle answer was 4500.
|
||||||
|
|
||||||
|
Both parts of this puzzle are complete! They provide two gold stars: **
|
||||||
|
|
||||||
|
At this point, you should return to your Advent calendar and try another puzzle.
|
||||||
|
@@ -155,7 +155,6 @@ static int node_explode(node_t *node)
|
|||||||
}
|
}
|
||||||
if (depth == 4) {
|
if (depth == 4) {
|
||||||
node_t *left = node->tree[LEFT], *right = node->tree[RIGHT];
|
node_t *left = node->tree[LEFT], *right = node->tree[RIGHT];
|
||||||
node_t *tmp;
|
|
||||||
//struct list_head *tmp;
|
//struct list_head *tmp;
|
||||||
|
|
||||||
/* skip leaves */
|
/* skip leaves */
|
||||||
@@ -287,8 +286,10 @@ static node_t *node_read(char **p, int depth)//, node_t *parent)
|
|||||||
|
|
||||||
node->depth = depth;
|
node->depth = depth;
|
||||||
|
|
||||||
if (!depth) /* root node */
|
if (!depth) { /* root node */
|
||||||
root = node;
|
root = node;
|
||||||
|
//log_f(1, "%s\n", *p);
|
||||||
|
}
|
||||||
|
|
||||||
//log_f(2, "str=%s depth=%d\n", *p, depth);
|
//log_f(2, "str=%s depth=%d\n", *p, depth);
|
||||||
switch (**p) {
|
switch (**p) {
|
||||||
@@ -308,6 +309,9 @@ static node_t *node_read(char **p, int depth)//, node_t *parent)
|
|||||||
list_add_tail(&node->leaf_list, &root->leaf_list);
|
list_add_tail(&node->leaf_list, &root->leaf_list);
|
||||||
}
|
}
|
||||||
(*p)++;
|
(*p)++;
|
||||||
|
//if (!depth) { /* root node */
|
||||||
|
// log_f(1, "%s\n", *p);
|
||||||
|
//}
|
||||||
return node;
|
return node;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -363,7 +367,6 @@ static s64 node_magnitude(node_t *node)
|
|||||||
static s64 part1()
|
static s64 part1()
|
||||||
{
|
{
|
||||||
node_t *head = NULL, *next = NULL;
|
node_t *head = NULL, *next = NULL;
|
||||||
s64 res = 1;
|
|
||||||
|
|
||||||
head = node_read(lines + 0, 0);
|
head = node_read(lines + 0, 0);
|
||||||
for (int i = 1; i < nlines; ++i) {
|
for (int i = 1; i < nlines; ++i) {
|
||||||
@@ -376,8 +379,26 @@ static s64 part1()
|
|||||||
|
|
||||||
static s64 part2()
|
static s64 part2()
|
||||||
{
|
{
|
||||||
s64 res = 2;
|
node_t *l1 = NULL, *l2 = NULL;
|
||||||
return res;
|
s64 max = 0, cur;
|
||||||
|
char *tmp;
|
||||||
|
|
||||||
|
for (int i = 0; i < nlines; ++i) {
|
||||||
|
for (int j = 0; j < nlines; ++j) {
|
||||||
|
if (j == i)
|
||||||
|
continue;
|
||||||
|
tmp = lines[i];
|
||||||
|
l1 = node_read(&tmp, 0);
|
||||||
|
tmp = lines[j];
|
||||||
|
l2 = node_read(&tmp, 0);
|
||||||
|
cur = node_magnitude(node_reduce(node_add(l1, l2)));
|
||||||
|
if (cur > max) {
|
||||||
|
log(2, "NEW BEST: %s + %s\n", lines[i], lines[j]);
|
||||||
|
max = cur;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return max;
|
||||||
}
|
}
|
||||||
|
|
||||||
static int usage(char *prg)
|
static int usage(char *prg)
|
||||||
|
Reference in New Issue
Block a user