diff options
author | Marvin Borner | 2020-12-14 22:29:46 +0100 |
---|---|---|
committer | Marvin Borner | 2020-12-14 22:29:46 +0100 |
commit | 53505c93aed2f42eef45a3523320e5097b3dcb9c (patch) | |
tree | c01f5c50244c1393d120326a4fb35a6762b6f8f7 | |
parent | 7cb9658e17baba2d43d0e7bc766512951ab4d05a (diff) |
Found the problem at least
-rw-r--r-- | 2020/14/solve.c | 12 |
1 files changed, 5 insertions, 7 deletions
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); } } |