summary refs log tree commit diff homepage
diff options
context:
space:
mode:
Diffstat (limited to '')
-rw-r--r--2020/day14.c14
1 files changed, 3 insertions, 11 deletions
diff --git a/2020/day14.c b/2020/day14.c
index 07bab22..78f1885 100644
--- a/2020/day14.c
+++ b/2020/day14.c
@@ -38,18 +38,10 @@ int main(void) {
 			writes[len++] = (struct Write) { addr, (val & mask) | bits };
 			addr |= bits;
 			addr &= ~mask;
-			ul count = 1UL << __builtin_popcountl(mask);
-			for (ul i = 0; i < count; ++i) {
-				ul a = addr;
-				ul w = i;
-				for (int j = 0; j < 36; ++j) {
-					if (mask & (1UL << j)) {
-						a |= (w & 1) << j;
-						w >>= 1;
-					}
-				}
-				writes2[len2++] = (struct Write) { a, val };
+			for (ul m = mask; m; m = (m - 1) & mask) {
+				writes2[len2++] = (struct Write) { addr | m, val };
 			}
+			writes2[len2++] = (struct Write) { addr, val };
 		}
 	}
 	mergesort(writes, len, sizeof(writes[0]), compar);