From 87c50bc725d1be40678e679579ee3bb2ec738ae2 Mon Sep 17 00:00:00 2001 From: Fredrik Robertsen <51152395+fredrikr79@users.noreply.github.com> Date: Tue, 3 Dec 2024 17:32:11 +0100 Subject: [PATCH] solve 2024 day 3 part 1 --- 2024/day_3/uiua/README.md | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) create mode 100644 2024/day_3/uiua/README.md diff --git a/2024/day_3/uiua/README.md b/2024/day_3/uiua/README.md new file mode 100644 index 0000000..7bce721 --- /dev/null +++ b/2024/day_3/uiua/README.md @@ -0,0 +1,16 @@ +# part 1 + +[solution](https://uiua.org/pad?src=0_14_0-dev_5__JmZyYXMgImlucHV0IgoKIyB0aGUgcmVnZXggZXhwcmVzc2lvbiBzdHJpbmcKIyB0byBtYXRjaCB0aGUgbXVsIGluc3RydWN0aW9ucwojIGFuZCBjYXB0dXJlIHRoZSBvcGVyYW5kcwpNdWwg4oaQICQgbXVsXCgoXGQrKSwoXGQrKVwpCgojIG1hdGNoIHRoZSBtdWwgZXhwcmVzc2lvbiwKIyBkcm9wIHRoZSBmdWxsICJtdWwoLi4uKSIgc3RyaW5nLCAKIyBwYXJzZSBlYWNoIG9wZXJhbmQgdG8gaW50ClBhcnNlIOKGkCDiiLXii5Ug4omh4oaYMSByZWdleCBNdWwKCiMgbXVsdGlwbHkgdGhlIG51bWJlcnMgaW4gZWFjaCByb3csCiMgc3VtIHRoZSBwcm9kdWN0cwpTb2wg4oaQIC8rIOKJoS_DlwoKU29sIFBhcnNlCg==) + +i first solved it this morning using vim, since i had no idea how to use regex in uiua. this is how i did it in vim (with some regex help from (kagi assistant)[https://help.kagi.com/kagi/ai/assistant.html]): + +``` +:e "input" +100J # there are few lines, join them all +:%s/\(mul(\d\+,\d\+)\)\|\(.\)/\1/g # find all mul expressions +:%s/mul(\(\d+\),\(\d+\))/\1*\2+/g # replace all mul expressions with the operands multiplied together with a + appended +$x # remove last + +:'<,'>s/.*/\=eval(submatch(0)) # evaluate the expression +``` + +my uiua solution is very similar