From d4267d6f5138770a01d0f3eaabfcf41a8d566bb0 Mon Sep 17 00:00:00 2001 From: fredrikr79 Date: Tue, 23 Sep 2025 23:55:53 +0200 Subject: [PATCH] solve 2016/1 part 1 in uiua --- 2016/1/main.ua | 24 ++++++++++++++++++++++++ 1 file changed, 24 insertions(+) create mode 100644 2016/1/main.ua diff --git a/2016/1/main.ua b/2016/1/main.ua new file mode 100644 index 0000000..4919dd5 --- /dev/null +++ b/2016/1/main.ua @@ -0,0 +1,24 @@ +# aoc 2016/1 +&fras $ input.txt +°/$"_, _" ⍜⇌↘₁ +∧◇(⍥\+⋕ ⍣( + ⍩⊙⍜⊢(×i) °(⊂@L) + | ⍩⊙⍜⊢(ׯi) °(⊂@R)) +)⊙i_0 +⌵+°ℂ⊣ +$Part₁ +# the idea is to represent our position +# as a complex number (2d vector). rotate by +# 90 or -90 degrees when you encounter L or R +# by multiplying by i or -i on the direction +# vector. +# this can be done by folding with the initial +# values i (direction) and 0 (position), pattern- +# matching the next token on L or R and recognizing +# them by ⍩. +# once the direction vector has been rotated +# accordingly, ⍥\+⋕ to add the direction unit vector +# to the position vector n times for token Ln or Rn. +# +# we can see many awesome pieces of functional and +# array oriented code!