improve 2016/1/1(uiua)

This commit is contained in:
2025-09-24 09:40:58 +02:00
parent 3b5c6ae52d
commit 9d8676a109

View File

@@ -1,17 +1,16 @@
# aoc 2016/1
&fras $ input.txt
°/$"_, _" ⍜⇌↘₁
∧◇(⍥\+⋕ ⍣(
⍩⊙⍜⊢(×i) °(⊂@L)
| ⍩⊙⍜⊢(ׯi) °(⊂@R))
)⊙i_0
⌵+°ℂ⊣
≡◇⊃[⍥¯⊙i ⨂"LR"⊢|⋕↘1] # pre-process
\(⊂⊢⊙⊣⊸⍜∩⊢×) # directions at each token
⬚0/(+⊙/×) # move in direction
+∩⌵°ℂ
$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.
# 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
@@ -19,7 +18,7 @@ $Part₁
# 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!
@@ -35,4 +34,4 @@ $Part₂
# each intermediate step (all our positions).
# this by modifying the ⍥-loop to keep a log.
# then we can find the first reoccurring position
# using the new ⧆.
# using the new ⧆.