From 53505c93aed2f42eef45a3523320e5097b3dcb9c Mon Sep 17 00:00:00 2001 From: Marvin Borner Date: Mon, 14 Dec 2020 22:29:46 +0100 Subject: Found the problem at least --- 2020/14/solve.c | 12 +++++------- 1 file changed, 5 insertions(+), 7 deletions(-) (limited to '2020/14/solve.c') diff --git a/2020/14/solve.c b/2020/14/solve.c index e2233dc..2f89ca2 100644 --- a/2020/14/solve.c +++ b/2020/14/solve.c @@ -13,6 +13,7 @@ struct mem_map { struct mem_entry *tail; }; +// THIS FUNCTION IS THE SPEED PROBLEM! struct mem_entry *get_entry(struct mem_map *mem_map, int address) { if (!mem_map || !mem_map->head || !mem_map->tail) @@ -29,7 +30,6 @@ struct mem_entry *get_entry(struct mem_map *mem_map, int address) void new_entry(struct mem_map *mem_map, long address, long value) { - /* printf("%lu: %lu\n", address, value); */ if (!mem_map) return; @@ -111,7 +111,7 @@ long part_two(FILE *fp) int floating = 0; for (int i = 0; i < 36; i++) { if (mask[i] == '1') { - address |= 1L << (36 - i - 1); + address |= 1ul << (36 - i - 1); } else if (mask[i] == 'X') { floating_bits[floating] = i; floating++; @@ -121,11 +121,9 @@ long part_two(FILE *fp) long masked_addr = address; for (long perm = 0; perm < (1 << floating); ++perm) { long address = masked_addr; - for (int j = 0; j < floating; ++j) { - if (perm & (1L << j)) { - address ^= (1L << (36 - floating_bits[j] - 1)); - } - } + for (int j = 0; j < floating; j++) + if (perm & (1ul << j)) + address ^= (1ul << (36 - floating_bits[j] - 1)); new_entry(&mem_map, address, value); } } -- cgit v1.2.3