summary refs log tree commit diff homepage
diff options
context:
space:
mode:
authorJune McEnroe <june@causal.agency>2020-12-15 02:02:00 -0500
committerJune McEnroe <june@causal.agency>2020-12-15 02:02:00 -0500
commit519aa25c89bc5f372b9ca6727e8026fbba319e4f (patch)
tree643e212d5ac90b7ad18426ce13efa749651e0780
parentSolve day 15 part 2 (diff)
downloadaoc-519aa25c89bc5f372b9ca6727e8026fbba319e4f.tar.gz
aoc-519aa25c89bc5f372b9ca6727e8026fbba319e4f.zip
Update day 14 part 2 with the clever way
-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);
&follow=1'>Use "secure" libtls ciphersJune McEnroe 2021-07-08Use seprintf to build final 005June McEnroe 2021-06-19Fix LDADD.crypt on DarwinJune McEnroe 2021-06-18Add -m mode option to set user modesJune McEnroe 2021-06-18Document channel keys in join optionJune McEnroe 2021-06-18Use | to separate flags from config optionsJune McEnroe 2021-06-18Stop referring to server-time as IRCv3.2June McEnroe 2021-06-17Add mailing list archive to READMEJune McEnroe 2021-06-10Stop accumulating ISUPPORT tokens once MOTD startsJune McEnroe 2021-06-09Use seprintf for snip, removing strlcpynJune McEnroe 2021-06-09Use seprintf for reserializeJune McEnroe 2021-06-09Use seprintf for capListJune McEnroe 2021-06-09Add seprintfJune McEnroe 2021-05-27Add pounce-notify to README 2.4June McEnroe 2021-05-27Fix ENVIRONMENT formatting in pounce-notify(1)June McEnroe 2021-05-27Add note about Libera.Chat SASL-only rangesJune McEnroe 2021-05-25Add QUIRKS fileJune McEnroe 2021-05-19Replace freenode with tilde.chatJune McEnroe 2021-05-04notify: Reword pounce-notify manualJune McEnroe 2021-05-02Clean up Makefiles, configure scriptsJune McEnroe 2021-04-30palaver: Exit on getopt failureJune McEnroe 2021-04-30notify: Implement pounce-notifyJune McEnroe